[PATCH 09/10] Switch from using os_random() to using os_get_random(...) in wpas_auth_failed(...)
Jouni Malinen
j at w1.fi
Fri Feb 19 07:45:48 PST 2016
On Sun, Feb 14, 2016 at 07:41:19PM +0000, Nick Lowe wrote:
> Switch from using os_random() to using
> os_get_random(...) in wpas_auth_failed(...) The intention is to facilitate
> the future removal of os_random(). os_random() uses a low quality PRNG which
> we should avoid using outright unless there is a compelling performance
> justification to do so.
> diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
> void wpas_auth_failed(struct wpa_supplicant *wpa_s, char *reason)
> - int dur;
> + int dur, r;
> - wpa_key_mgmt_wpa_ieee8021x(ssid->key_mgmt))
> - dur += os_random() % (ssid->auth_failures * 10);
> + wpa_key_mgmt_wpa_ieee8021x(ssid->key_mgmt) &&
> + os_get_random((u8 *) &r, sizeof(r)) >= 0)
> + dur += r % (ssid->auth_failures * 10);
This does not look safe. Shouldn't r be unsigned at minimum? The
proposed construction seems to have about 0.5 chance of being negative
and reducing the wait duration. Please note that os_random() returns
unsigned long. The dur variable could also be changed to be unsigned
(not that this construction would be able to go beyond the maximum int
value in practice).
--
Jouni Malinen PGP id EFC895FA
More information about the Hostap
mailing list