Skip to content

Commit

Permalink
fix(mme): Replace insecure rand() with getrandom() for TMSI generation (
Browse files Browse the repository at this point in the history
magma#15433)

Signed-off-by: shashidhar-patil <[email protected]>
Co-authored-by: panyogesh <[email protected]>
  • Loading branch information
shashidhar-patil and panyogesh authored Jun 19, 2024
1 parent e8d204d commit 8792d18
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lte/gateway/c/core/oai/tasks/nas/api/mme/mme_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <sys/random.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -408,6 +409,11 @@ status_code_e mme_api_unsubscribe(bstring apn) {
}

static tmsi_t generate_random_TMSI() {
// note srand with seed is initialized at main
return (tmsi_t)rand();
tmsi_t tmsi = (tmsi_t)0;
if (getrandom(reinterpret_cast<void*>(&tmsi), sizeof(tmsi_t), 0) !=
sizeof(tmsi_t)) {
tmsi = static_cast<tmsi_t>(
rand()); // Fallback in case of fundamental system error
}
return tmsi;
}

0 comments on commit 8792d18

Please sign in to comment.