diff options
author | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2018-07-07 21:51:09 +0100 |
---|---|---|
committer | Holger Freyther <holger@freyther.de> | 2018-07-11 21:13:11 +0000 |
commit | 6d49b049ee304f1ea0e4801df61e69713b01f0f8 (patch) | |
tree | 3ffca58aced050916dc0f4d6c62c7a6354aa53b9 /src/host/layer23/src/mobile/settings.c | |
parent | c36dc296321af23b171903fd0ad3cf8d7e552ab2 (diff) |
Move from libc random() to osmo_get_rand_id
When starting multiple mobile in the same second, the libc random number
generator will be seeded to exactly the same value.
The random bits inside the RACH request(s) will be exactly the same
across multiple mobile and when the channel fails they all pick the same
randomized back-off timing.
Use stronger random numbers and replace all calls to random(2) with
osmo_get_rand_id. Add a fallback to try random().
Change-Id: Ie0cc64663cd4b90c027b79545dc5d3ac9d87b9dd
Diffstat (limited to 'src/host/layer23/src/mobile/settings.c')
-rw-r--r-- | src/host/layer23/src/mobile/settings.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/host/layer23/src/mobile/settings.c b/src/host/layer23/src/mobile/settings.c index 7370b0ab..80b0b482 100644 --- a/src/host/layer23/src/mobile/settings.c +++ b/src/host/layer23/src/mobile/settings.c @@ -23,6 +23,7 @@ #include <errno.h> #include <string.h> #include <osmocom/core/talloc.h> +#include <osmocom/gsm/gsm_utils.h> #include <osmocom/bb/mobile/app_mobile.h> #include <osmocom/bb/common/logging.h> @@ -178,14 +179,19 @@ int gsm_random_imei(struct gsm_settings *set) { int digits = set->imei_random; char rand[16]; + long rand_num; if (digits <= 0) return 0; if (digits > 15) digits = 15; - sprintf(rand, "%08ld", random() % 100000000); - sprintf(rand + 8, "%07ld", random() % 10000000); + if (osmo_get_rand_id((uint8_t *) &rand_num, sizeof(rand_num)) != 0) + rand_num = random(); + sprintf(rand, "%08ld", rand_num % 100000000); + if (osmo_get_rand_id((uint8_t *) &rand_num, sizeof(rand_num)) != 0) + rand_num = random(); + sprintf(rand + 8, "%07ld", rand_num % 10000000); strcpy(set->imei + 15 - digits, rand + 15 - digits); strncpy(set->imeisv, set->imei, 15); |