From patchwork Wed Dec 8 00:54:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 522304 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B6E3C433EF for ; Wed, 8 Dec 2021 00:54:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238640AbhLHA6Z (ORCPT ); Tue, 7 Dec 2021 19:58:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234847AbhLHA6Y (ORCPT ); Tue, 7 Dec 2021 19:58:24 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0969C061574 for ; Tue, 7 Dec 2021 16:54:53 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id fv9-20020a17090b0e8900b001a6a5ab1392so828734pjb.1 for ; Tue, 07 Dec 2021 16:54:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ua4DPC4fWRMXlVMRPHDaZjGghpOdbFEAmDad48c2TvI=; b=iArJb+VGOaPOsHHNEiF4WOiZQCncnRUOGEyeWv+c2+JLj4YZqjBR6uM/z5hd65w1gn MQ4pwFLvQ/o0ZeSWLm/SiaPCqJvdVa7ynCQndlmNxsTq0WKkMzfJd5X/y+V9qqC++tPB GpLz62HyFDNkiIXv9vmLFF13qGiRvFzHpzx3bMIrLlh/Ey3yP8mmCX63lcC/F4ALaVzS 1j3AQ8uOO1+nmSFJU75hzBiM8qQ70ewFGmdnGFGtGjLatu5g00JEDVABvWzsalqLWtDA eyTXccgDzC8B2FWJSe3vFv6hPy1FqBmUGxMlqhs32bAtDZFb5NiFkIcoQyW7DJ8BVnIM emMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ua4DPC4fWRMXlVMRPHDaZjGghpOdbFEAmDad48c2TvI=; b=Gqz0GTBdXpmIk/bHdnTPU/CiiOyu9QnfvtDMj3v59V8BpjP7jxbbS6lievIGu/2Do8 tTmSG2dPw5Jo931SMdcW48t5cyklKmKWN49OwsCNmwuH3mVbt5WOPzfjOBq7HK7cx+vg UAAe2kRWooHijWrs5f+ne3yg6BsiCeiQoQUBkqDl94yYqHzOgKM29yV+kWeNyoFLFoT4 h0euhVI2TXJgBU5QfoFw757abLg08Tn4SG3mbSNPR+9lPB51Za9mKwh511wsNZ9+oTbm UkeIS8nopdiwLzL3M5xaQMo0CuWIpstUc69B+ZVetBlUKk5bQUaHdMfQZcwphNQRPA/s ixwA== X-Gm-Message-State: AOAM530rMxVcaHsbYZAnMOHCboL05vPTg54rkV1HC/EQtVU0Z2PiJLB1 OG9fxOxI8xk9gGgfN8mr8O8xaUoCrKg= X-Google-Smtp-Source: ABdhPJw7ba6DTne7Vz61N9g5O5FiF23q5By1L9RvpKvHcCO9ZO1CF6P7nPEBMvBl6xsRbm4sa7JkJw== X-Received: by 2002:a17:902:e8d8:b0:142:5622:f9e5 with SMTP id v24-20020a170902e8d800b001425622f9e5mr56083509plg.42.1638924892907; Tue, 07 Dec 2021 16:54:52 -0800 (PST) Received: from localhost.localdomain ([2601:1c0:6a01:d830:52cb:f76a:51b5:e541]) by smtp.gmail.com with ESMTPSA id d195sm604191pga.41.2021.12.07.16.54.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 16:54:52 -0800 (PST) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 1/5] emulator: Replace random number generation function Date: Tue, 7 Dec 2021 16:54:42 -0800 Message-Id: <20211208005446.196637-2-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211208005446.196637-1-hj.tedd.an@gmail.com> References: <20211208005446.196637-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch replaces the rand() function to the l_getrandom() from ELL, which uses the getrandom() system call. It was reported by the Coverity scan rand() should not be used for security-related applications, because linear congruential algorithms are too easy to break --- Makefile.tools | 3 ++- emulator/le.c | 4 ++-- emulator/phy.c | 6 ++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Makefile.tools b/Makefile.tools index c7bdff83f..8312d4d27 100644 --- a/Makefile.tools +++ b/Makefile.tools @@ -93,7 +93,8 @@ emulator_btvirt_SOURCES = emulator/main.c monitor/bt.h \ emulator/phy.h emulator/phy.c \ emulator/amp.h emulator/amp.c \ emulator/le.h emulator/le.c -emulator_btvirt_LDADD = lib/libbluetooth-internal.la src/libshared-mainloop.la +emulator_btvirt_LDADD = lib/libbluetooth-internal.la src/libshared-mainloop.la \ + src/libshared-ell.la $(ell_ldadd) emulator_b1ee_SOURCES = emulator/b1ee.c emulator_b1ee_LDADD = src/libshared-mainloop.la diff --git a/emulator/le.c b/emulator/le.c index 07a44c5f1..fed3a7815 100644 --- a/emulator/le.c +++ b/emulator/le.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "lib/bluetooth.h" #include "lib/hci.h" @@ -506,8 +507,7 @@ static unsigned int get_adv_delay(void) /* The advertising delay is a pseudo-random value with a range * of 0 ms to 10 ms generated for each advertising event. */ - srand(time(NULL)); - return (rand() % 11); + return (l_getrandom_uint32() % 11); } static void adv_timeout_callback(int id, void *user_data) diff --git a/emulator/phy.c b/emulator/phy.c index 2ae6ad3a2..570a9c975 100644 --- a/emulator/phy.c +++ b/emulator/phy.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "src/shared/util.h" #include "src/shared/mainloop.h" @@ -152,6 +153,7 @@ static int create_tx_socket(void) struct bt_phy *bt_phy_new(void) { struct bt_phy *phy; + uint64_t phy_id; phy = calloc(1, sizeof(*phy)); if (!phy) @@ -173,8 +175,8 @@ struct bt_phy *bt_phy_new(void) mainloop_add_fd(phy->rx_fd, EPOLLIN, phy_rx_callback, phy, NULL); if (!get_random_bytes(&phy->id, sizeof(phy->id))) { - srandom(time(NULL)); - phy->id = random(); + l_getrandom(&phy_id, sizeof(phy_id)); + phy->id = phy_id; } bt_phy_send(phy, BT_PHY_PKT_NULL, NULL, 0); From patchwork Wed Dec 8 00:54:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 525134 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAED3C4332F for ; Wed, 8 Dec 2021 00:54:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238668AbhLHA6Z (ORCPT ); Tue, 7 Dec 2021 19:58:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229918AbhLHA6Z (ORCPT ); Tue, 7 Dec 2021 19:58:25 -0500 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 622ACC061574 for ; Tue, 7 Dec 2021 16:54:54 -0800 (PST) Received: by mail-pg1-x52c.google.com with SMTP id l64so591465pgl.9 for ; Tue, 07 Dec 2021 16:54:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=BvGlbsHSaHYZ89GwHQfqmVwCe+aASVO9YDzeX3gwlbw=; b=WXkaz60IXYyYj5HQodAkU679DJR1a8ddPx3bL++psMWQQqohN+sCBSqoDf3QM/chKH O6fD9Hb3b0MuzdA/+sscPa2M3zmWnITiyauVK5kQz2/yh1cdz1eiAy54y/enI3LwZe3A bQPxkLD5CeS/qBGhi9QLzWjouk03NAK7OkII0pYwhTrUFiYL96vBl06OXjG6WWl1E99T WsTUDM9nURbsdSQbmyXWY4zn2JfA/5IJZjAeHWF678iY2ROvOq67SC/INiQyxzMWLVJI 5jzq+lsiw7vK0+Ff7RlVjWSRK7g84eRi1pf/D28aMVLmJjN4kMeTjXfpBNEpjV+ua/uh 8e5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BvGlbsHSaHYZ89GwHQfqmVwCe+aASVO9YDzeX3gwlbw=; b=dS+3BZsNQOecslW+r8ELryq6WIua1LPowIKJUpWT2GKrUAkhuNv3uVCR2WDJLYmX8Y d2Ncqejpk7UjBIwZ7NC0Pdux5ZLcwwKOVXt41kAazzvqjtKFcBrqV2FA1Bx/XI9at+X8 hD3nokes+ONFWqAf8njFY0L36wNswEMWsP4TzF6nWLKZogtAA8Tta0F2WFlTGeK3e4gO OHga1U+n8TQu9eLWzPOMzsQPrFMMNl6XFHL//mVmMOnusGy73zRfU86S/lrFHx1LCoWS nZDjvvzLRjOB/m22X5WtGV4ctZwjZkIRmFEUHqeFH7DwNi0HPaPUk6RaOt4qEFPppPsr Umlw== X-Gm-Message-State: AOAM532ZbR/NqKootXMR5nRonlQL2WeWlfFpkixYPKhaqttSRXfUqroA 78Ddc+7gRosD8ipLynFXf1CoHU+Hk50= X-Google-Smtp-Source: ABdhPJyGaEHxQi6aLtOod9A24hyf/SgZuVyV/LM92uxeZtmMgyCeiMm/XTuLycZCsxKPFCGLMCYwuw== X-Received: by 2002:a63:c042:: with SMTP id z2mr20958765pgi.491.1638924893653; Tue, 07 Dec 2021 16:54:53 -0800 (PST) Received: from localhost.localdomain ([2601:1c0:6a01:d830:52cb:f76a:51b5:e541]) by smtp.gmail.com with ESMTPSA id d195sm604191pga.41.2021.12.07.16.54.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 16:54:53 -0800 (PST) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 2/5] peripheral: Replace random number generation function Date: Tue, 7 Dec 2021 16:54:43 -0800 Message-Id: <20211208005446.196637-3-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211208005446.196637-1-hj.tedd.an@gmail.com> References: <20211208005446.196637-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch replaces the rand() function to the l_getrandom() from ELL, which uses the getrandom() system call. It was reported by the Coverity scan rand() should not be used for security-related applications, because linear congruential algorithms are too easy to break --- Makefile.tools | 3 ++- peripheral/main.c | 8 +++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Makefile.tools b/Makefile.tools index 8312d4d27..63b52c386 100644 --- a/Makefile.tools +++ b/Makefile.tools @@ -109,7 +109,8 @@ peripheral_btsensor_SOURCES = peripheral/main.c \ peripheral/gap.h peripheral/gap.c \ peripheral/gatt.h peripheral/gatt.c peripheral_btsensor_LDADD = src/libshared-mainloop.la \ - lib/libbluetooth-internal.la + lib/libbluetooth-internal.la \ + src/libshared-ell.la $(ell_ldadd) tools_3dsp_SOURCES = tools/3dsp.c monitor/bt.h tools_3dsp_LDADD = src/libshared-mainloop.la diff --git a/peripheral/main.c b/peripheral/main.c index 86b52236e..f7ac043a0 100644 --- a/peripheral/main.c +++ b/peripheral/main.c @@ -25,6 +25,7 @@ #include #include #include +#include #ifndef WAIT_ANY #define WAIT_ANY (-1) @@ -191,11 +192,8 @@ int main(int argc, char *argv[]) addr, 6) < 0) { printf("Generating new persistent static address\n"); - addr[0] = rand(); - addr[1] = rand(); - addr[2] = rand(); - addr[3] = 0x34; - addr[4] = 0x12; + l_getrandom(addr, 6); + /* Update the MSB to make it a static address */ addr[5] = 0xc0; efivars_write("BluetoothStaticAddress", From patchwork Wed Dec 8 00:54:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 522303 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90229C433F5 for ; Wed, 8 Dec 2021 00:54:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238851AbhLHA60 (ORCPT ); Tue, 7 Dec 2021 19:58:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238712AbhLHA6Z (ORCPT ); Tue, 7 Dec 2021 19:58:25 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C5FFC061574 for ; Tue, 7 Dec 2021 16:54:55 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id gf14-20020a17090ac7ce00b001a7a2a0b5c3so3155104pjb.5 for ; Tue, 07 Dec 2021 16:54:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=9A9e1koPlNVL+eyx9T1qletL0N7uiOfsPVaFRftMOF0=; b=eu9q5l/RfFFL/vmBHaUgz5w1NchDPgLoFR5V3EW2nvan69FY0d5Pls7ezos9OJajEB aztdiK380CjgKuYqZHkzA5Zk/n7U8R3lojrkbc4dfsALwjQaOecdf7O3icYJHbrSwyDx qdsqktTPp/KbrhGpzUydhUHlZS8sNLJa0isz4oiBkfZzfVO9mDkYtieuVADk41ZPs2oL M8qYG+0r/8fGYX+obkxF/Gz7w9zBnc0m695vX4h/5Uooy1k5QArnSvH3O2Uu8Jlf+JO2 ElYw97QwxLyc0N0LENaPwj1mWZzY7U54dTAwULCrzcUXtfUX361Sv0iYqm2cox3JggL5 tCiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9A9e1koPlNVL+eyx9T1qletL0N7uiOfsPVaFRftMOF0=; b=3L7EQXC4Q2vZjgqAPVPq1vPbqKxuaj9ENy6TpHHRFSK5mWhj+ly6y+SWmHvXkHyyDY DB+Wq1XEvODtFebDAcQ7nNUl/DYzaGSiJoCX7Ddb2mPZW8PwP7gqPSXCcEnbp184PRcn UZOdSTIWaZlM5d80BJwXR8Pp7z4EwGwtxVNppLGf8s5IlEx7IGCtFbSLaeCazGGmiAPC bzABCpJjscKopCk5Qfsk//r4EBytH5TqTPM87xUh3JfhlZUqBzoJIWgu5LKC2BbXy4To AixVhifg4TtGiYEyw6Wq0vWzArNwpWnQKXBOShYQf25Inoa3EqzDQRunIzMo2qhu8iTL +DuQ== X-Gm-Message-State: AOAM532hhemMI6ZlElWasKPQhrMvcBXpeBI1cSS6NeEtWU/NUqeB8MEJ jl1f3WxBWkjCofYk8hX4slenqDT8onQ= X-Google-Smtp-Source: ABdhPJx92Nr8xBfrr0xp6ts40CzkTMjtA9t3RCNfMfpo2G+cggsl/ViKJt5RyE5uujWsg0Z7+17/DA== X-Received: by 2002:a17:90a:4b47:: with SMTP id o7mr3289946pjl.92.1638924894335; Tue, 07 Dec 2021 16:54:54 -0800 (PST) Received: from localhost.localdomain ([2601:1c0:6a01:d830:52cb:f76a:51b5:e541]) by smtp.gmail.com with ESMTPSA id d195sm604191pga.41.2021.12.07.16.54.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 16:54:53 -0800 (PST) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 3/5] tools/btgatt-server: Replace random number generation function Date: Tue, 7 Dec 2021 16:54:44 -0800 Message-Id: <20211208005446.196637-4-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211208005446.196637-1-hj.tedd.an@gmail.com> References: <20211208005446.196637-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch replaces the rand() function to the l_getrandom() from ELL, which uses the getrandom() system call. It was reported by the Coverity scan rand() should not be used for security-related applications, because linear congruential algorithms are too easy to break --- Makefile.tools | 4 ++-- tools/btgatt-server.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile.tools b/Makefile.tools index 63b52c386..45470b767 100644 --- a/Makefile.tools +++ b/Makefile.tools @@ -287,8 +287,8 @@ tools_btgatt_client_LDADD = src/libshared-mainloop.la \ tools_btgatt_server_SOURCES = tools/btgatt-server.c src/uuid-helper.c tools_btgatt_server_LDADD = src/libshared-mainloop.la \ - lib/libbluetooth-internal.la - + lib/libbluetooth-internal.la \ + src/libshared-ell.la $(ell_ldadd) tools_rctest_LDADD = lib/libbluetooth-internal.la tools_l2test_LDADD = lib/libbluetooth-internal.la diff --git a/tools/btgatt-server.c b/tools/btgatt-server.c index 000145a3d..d2a877275 100644 --- a/tools/btgatt-server.c +++ b/tools/btgatt-server.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "lib/bluetooth.h" #include "lib/hci.h" @@ -286,7 +287,7 @@ static bool hr_msrmt_cb(void *user_data) uint32_t cur_ee; pdu[0] = 0x06; - pdu[1] = 90 + (rand() % 40); + pdu[1] = 90 + (l_getrandom_uint32() % 40); if (expended_present) { pdu[0] |= 0x08; From patchwork Wed Dec 8 00:54:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 525133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2462EC433FE for ; Wed, 8 Dec 2021 00:54:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229918AbhLHA61 (ORCPT ); Tue, 7 Dec 2021 19:58:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238835AbhLHA60 (ORCPT ); Tue, 7 Dec 2021 19:58:26 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9C4AC061574 for ; Tue, 7 Dec 2021 16:54:55 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id z6so436998plk.6 for ; Tue, 07 Dec 2021 16:54:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ced3sO1DZKwcuGIFJwU6z7OT390K7VCxMmJJd5tHGXY=; b=DS0lbyYUHICCeG2kDqAzY6UWSwu+OY2d+afCS07ewj2E1Ud49uMTLi7jJ8ui1aOuq3 DRY/6IYbRAbSL8+YdeAsx5JWYe+XhM2BODgfWBjjMYmoXi5XSmkTROfQZ9lLMakQkhxs lVCqHWUExvrG2vC9D8gq1qP6xih7UJveJx4MAKQ3luLVZ6SHNKOOk7WpK0NjfbU81fpa n2wj4KLk+V0MTL3bcfKUOECjD3PmtzfgIVs+b2LdsGuVMPHJ4bI0JKCbpIvt3r1TzBlX 5e/VSXXBNoT3926dnUqoT26xpYo2EG0vMW594otRmIeXGaPHHG0qY6fSMCaUXBT0MC1U 14cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ced3sO1DZKwcuGIFJwU6z7OT390K7VCxMmJJd5tHGXY=; b=IA+dYRNRGpowQXdYyz2qq9k1a5PHtvNrQexXd8LuFRbRju4NbUiXh2gcxSQdP6nnYh iVp83LiwUiSgmqP/UVc0XcmdPruZqQ51GGA06rlPFPwosdMrjEIZlGaFS19XYA63lkrK CJgdhxWUHuNIFT7OJYckMbuDCJHC+xaIhHL8ld/sIA76i3QNNEkA8MXj/JDIGiyn82UL PKocIr6GADQHfnD+neE7sUAyJ/7sQGPV6buPLgJWLIsA9kKrayLNOVO2g3PVtVtjKrzd raGPGBBJeEgsc+Yo9XqlzuGkCgIG6MV39dbgpT1tGtoSa1P4mOzQh+RCagFZJvD0GcQh eneg== X-Gm-Message-State: AOAM533Rl8IgI78RCmyyfiptF6CbJbKH7MFWDJrk94YKxFzHpedE9v8u 374w7FXh7mNfGQroiyKFJTHa1WpP1D4= X-Google-Smtp-Source: ABdhPJzJpDtvJH+WdR+jvukPS9C87qIZXB9DQGUA0J0mxE5nUWeo2IoQ2B5mG6o8IF5KRqi8HcuJCg== X-Received: by 2002:a17:902:aa43:b0:142:6919:73da with SMTP id c3-20020a170902aa4300b00142691973damr55197717plr.39.1638924895056; Tue, 07 Dec 2021 16:54:55 -0800 (PST) Received: from localhost.localdomain ([2601:1c0:6a01:d830:52cb:f76a:51b5:e541]) by smtp.gmail.com with ESMTPSA id d195sm604191pga.41.2021.12.07.16.54.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 16:54:54 -0800 (PST) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 4/5] plugins: Replace random number generation function Date: Tue, 7 Dec 2021 16:54:45 -0800 Message-Id: <20211208005446.196637-5-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211208005446.196637-1-hj.tedd.an@gmail.com> References: <20211208005446.196637-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch replaces the rand() function to the l_getrandom() from ELL, which uses the getrandom() system call. It was reported by the Coverity scan rand() should not be used for security-related applications, because linear congruential algorithms are too easy to break --- Makefile.plugins | 1 + plugins/autopair.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile.plugins b/Makefile.plugins index 7693c767f..c771b2dfb 100644 --- a/Makefile.plugins +++ b/Makefile.plugins @@ -7,6 +7,7 @@ builtin_sources += plugins/wiimote.c builtin_modules += autopair builtin_sources += plugins/autopair.c +builtin_ldadd += src/libshared-ell.la $(ell_ldadd) builtin_modules += policy builtin_sources += plugins/policy.c diff --git a/plugins/autopair.c b/plugins/autopair.c index 665a4f4a6..474209fd2 100644 --- a/plugins/autopair.c +++ b/plugins/autopair.c @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -130,7 +131,7 @@ static ssize_t autopair_pincb(struct btd_adapter *adapter, return 0; snprintf(pinstr, sizeof(pinstr), "%06u", - rand() % 1000000); + l_getrandom_uint32() % 1000000); *display = true; memcpy(pinbuf, pinstr, 6); return 6; From patchwork Wed Dec 8 00:54:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 522302 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C823AC433EF for ; Wed, 8 Dec 2021 00:54:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238913AbhLHA62 (ORCPT ); Tue, 7 Dec 2021 19:58:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238856AbhLHA61 (ORCPT ); Tue, 7 Dec 2021 19:58:27 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87301C061574 for ; Tue, 7 Dec 2021 16:54:56 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id y14-20020a17090a2b4e00b001a5824f4918so3157200pjc.4 for ; Tue, 07 Dec 2021 16:54:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=RInqyw9zZIqeT0BZBcJLRmW4AvPHDt4uFyn3ne7vqec=; b=puUsFnAJQ2AEEgtiWlPMDkB3SwIRoCxJ2aRhHjoAr1hxD7Tx2nQKIPcGaErj1VLa5b 5YXXQYmipICj4nE45hagzH2TTrw1qsrzer41rvJ6v44kjPJ0gvGMZl7ernRD7CWyirxf dVvaIn5qi/qHbtXlmZjEBndRtjg4p8k9rwR+wUwdZFtfXnrdVoWnhAkVL3FiCeaLp9QL a9PAKLDZ6hkmq5ql5VFYlsHCFxO9/CpoEQs2KDyDjte+c/i9vuD7KrByXt6465SqH2b2 CWGt1Lu79s01zg/syeoQamP8LLI00y5K1JegDNMtcjleTZySm2DznpRS65RnYt7ZT8kQ SCaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RInqyw9zZIqeT0BZBcJLRmW4AvPHDt4uFyn3ne7vqec=; b=Ti9/Q2sKfWPxQxkxPur/epk2f03UReVZCWMzorZ4nqF0MDV5/nSMcOe36/0hcUOaYL HbMS9kfgykdJAkj4KRUEpMCd5Wf9gQgo2dtIKLeqtGhm6R4Uca/drgB6lgroe2QeVT3y wMebb545HwoHm5YtsS0MMWf4pM9NkfVr+3KsAmvaNohN4Yo4YJW/cTRRTGsaHxLGhuJ0 +bhYUBRorXbae3pJ7r9/1IDllryOE2xh8N82WZBt1N87SJmJKSSP89Trh+p6CHLt3Ff3 GHv+OQ9YN+1lfDZWfidpYxchzaWDr4Jdx9MyksvhkUpcOGAwG+zlzPLFaDHbfjRDVpDX BDPQ== X-Gm-Message-State: AOAM532wS9XHc+7754a3QK86E8JKgZ/N1mlpuJTUqXvoktortoAsT5Ar fkFh5JYw2E5sS+3HAoJXqvFykaWpJC8= X-Google-Smtp-Source: ABdhPJyoubMx4Nsa+/J1PuyI5ZWF4kSxFdDRrUg15Dpl1sNSMw1VIqvKYjUHBxF64P2eC4vwdCVJfQ== X-Received: by 2002:a17:902:e74a:b0:142:114c:1f1e with SMTP id p10-20020a170902e74a00b00142114c1f1emr55195331plf.78.1638924895818; Tue, 07 Dec 2021 16:54:55 -0800 (PST) Received: from localhost.localdomain ([2601:1c0:6a01:d830:52cb:f76a:51b5:e541]) by smtp.gmail.com with ESMTPSA id d195sm604191pga.41.2021.12.07.16.54.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 16:54:55 -0800 (PST) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 5/5] profiles/health: Replace random number generation function Date: Tue, 7 Dec 2021 16:54:46 -0800 Message-Id: <20211208005446.196637-6-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211208005446.196637-1-hj.tedd.an@gmail.com> References: <20211208005446.196637-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch replaces the rand() function to the l_getrandom() from ELL, which uses the getrandom() system call. It was reported by the Coverity scan rand() should not be used for security-related applications, because linear congruential algorithms are too easy to break --- Makefile.plugins | 1 + profiles/health/hdp.c | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile.plugins b/Makefile.plugins index c771b2dfb..7817035c6 100644 --- a/Makefile.plugins +++ b/Makefile.plugins @@ -87,6 +87,7 @@ builtin_sources += profiles/health/mcap.h profiles/health/mcap.c \ profiles/health/hdp_manager.c \ profiles/health/hdp.h profiles/health/hdp.c \ profiles/health/hdp_util.h profiles/health/hdp_util.c +builtin_ldadd += src/libshared-ell.la $(ell_ldadd) endif builtin_modules += gap diff --git a/profiles/health/hdp.c b/profiles/health/hdp.c index 6bc41946f..e77f963a4 100644 --- a/profiles/health/hdp.c +++ b/profiles/health/hdp.c @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -1484,13 +1485,12 @@ static void destroy_create_dc_data(gpointer data) static void *generate_echo_packet(void) { uint8_t *buf; - int i; buf = g_malloc(HDP_ECHO_LEN); - srand(time(NULL)); + if (buf == NULL) + return NULL; - for(i = 0; i < HDP_ECHO_LEN; i++) - buf[i] = rand() % UINT8_MAX; + l_getrandom(buf, HDP_ECHO_LEN); return buf; }