Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751505AbdFIBRF (ORCPT ); Thu, 8 Jun 2017 21:17:05 -0400 Received: from frisell.zx2c4.com ([192.95.5.64]:51229 "EHLO frisell.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751445AbdFIBRE (ORCPT ); Thu, 8 Jun 2017 21:17:04 -0400 From: "Jason A. Donenfeld" To: tytso@mit.edu, linux-kernel@vger.kernel.org Cc: "Jason A. Donenfeld" , Marcel Holtmann , Gustavo Padovan , Johan Hedberg Subject: [PATCH] bluetooth: ensure RNG is properly seeded before powerup Date: Fri, 9 Jun 2017 03:16:54 +0200 Message-Id: <20170609011654.14161-1-Jason@zx2c4.com> In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1908 Lines: 48 The SMP protocol uses lots of complex cryptography that relies on securely generated random numbers. Thus, it's important that the RNG is actually seeded before use. Ted and the bluetooth maintainers seem to think that it's sufficient to wait_for_random_bytes before powering up, and this will ensure that all subsequent get_random_bytes calls occur after this single wait_for_random_bytes. (I'm not completely convinced, but time will tell.) Therefore, we put this call to wait_for_random_bytes, which is running in a workqueue, so it can sleep while waiting. We also are required to pass the potential error code back through the failure setter, like the rest of the function does. Signed-off-by: Jason A. Donenfeld Cc: Marcel Holtmann Cc: Gustavo Padovan Cc: Johan Hedberg --- Ted -- this would be instead of my other bluetooth patch. I think my other one might be a bit more robust, but if you prefer this strategy instead, here's the code for it. net/bluetooth/hci_core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 05686776a5fb..d940e22f365d 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2017,6 +2017,18 @@ static void hci_power_on(struct work_struct *work) BT_DBG("%s", hdev->name); + /* Bluetooth is a big user of cryptography and thus needs to have a + * good random number generator, especially for the SMP protocol. + * Thus, we ensure we have good randomness before powering up. + */ + err = wait_for_random_bytes(); + if (err < 0) { + hci_dev_lock(hdev); + mgmt_set_powered_failed(hdev, err); + hci_dev_unlock(hdev); + return; + } + if (test_bit(HCI_UP, &hdev->flags) && hci_dev_test_flag(hdev, HCI_MGMT) && hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) { -- 2.13.1