From 6d3ddef1d05cc2dcf7c35f16d15896a164d14290 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 8 Jun 2016 09:42:28 +0200 Subject: [PATCH] Bluetooth: Fix using uninitialized PRNG PRNG needs to be initialized right at the begining so that it is safe to use it from initialization sequence. This fix a race when ECC emulation code was using uninitiliazed PRNG for public key generation. Change-Id: Ia396f964b915368cee39ea6be998ef5774062591 Signed-off-by: Szymon Janc --- net/bluetooth/hci_core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 41b0bf9ade7..becb0bd1321 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2656,6 +2656,15 @@ static int common_init(void) hci_reset_complete(rsp); net_buf_unref(rsp); + /* + * initialize PRNG right after reset so that it is safe to use it later + * on in initialization process + */ + err = prng_init(&prng); + if (err) { + return err; + } + /* Read Local Supported Features */ err = bt_hci_cmd_send_sync(BT_HCI_OP_READ_LOCAL_FEATURES, NULL, &rsp); if (err) { @@ -2803,7 +2812,7 @@ static int le_init(void) } #endif /* CONFIG_BLUETOOTH_SMP */ - return prng_init(&prng); + return 0; } #if defined(CONFIG_BLUETOOTH_BREDR)