Skip to content

Commit 9d1a3c7

Browse files
arndbVudentz
authored andcommitted
Bluetooth: avoid memcmp() out of bounds warning
bacmp() is a wrapper around memcpy(), which contain compile-time checks for buffer overflow. Since the hci_conn_request_evt() also calls bt_dev_dbg() with an implicit NULL pointer check, the compiler is now aware of a case where 'hdev' is NULL and treats this as meaning that zero bytes are available: In file included from net/bluetooth/hci_event.c:32: In function 'bacmp', inlined from 'hci_conn_request_evt' at net/bluetooth/hci_event.c:3276:7: include/net/bluetooth/bluetooth.h:364:16: error: 'memcmp' specified bound 6 exceeds source size 0 [-Werror=stringop-overread] 364 | return memcmp(ba1, ba2, sizeof(bdaddr_t)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Add another NULL pointer check before the bacmp() to ensure the compiler understands the code flow enough to not warn about it. Since the patch that introduced the warning is marked for stable backports, this one should also go that way to avoid introducing build regressions. Fixes: 1ffc6f8 ("Bluetooth: Reject connection with the device which has same BD_ADDR") Cc: Kees Cook <[email protected]> Cc: "Lee, Chun-Yi" <[email protected]> Cc: Luiz Augusto von Dentz <[email protected]> Cc: Marcel Holtmann <[email protected]> Cc: [email protected] Signed-off-by: Arnd Bergmann <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 18f547f commit 9d1a3c7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

net/bluetooth/hci_event.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3273,7 +3273,7 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data,
32733273
/* Reject incoming connection from device with same BD ADDR against
32743274
* CVE-2020-26555
32753275
*/
3276-
if (!bacmp(&hdev->bdaddr, &ev->bdaddr)) {
3276+
if (hdev && !bacmp(&hdev->bdaddr, &ev->bdaddr)) {
32773277
bt_dev_dbg(hdev, "Reject connection with same BD_ADDR %pMR\n",
32783278
&ev->bdaddr);
32793279
hci_reject_conn(hdev, &ev->bdaddr);

0 commit comments

Comments
 (0)