[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <202310091342.C99D7BF@keescook>
Date: Mon, 9 Oct 2023 13:43:12 -0700
From: Kees Cook <keescook@...omium.org>
To: Arnd Bergmann <arnd@...nel.org>
Cc: Marcel Holtmann <marcel@...tmann.org>,
Johan Hedberg <johan.hedberg@...il.com>,
Luiz Augusto von Dentz <luiz.dentz@...il.com>,
"Lee, Chun-Yi" <jlee@...e.com>, Arnd Bergmann <arnd@...db.de>,
Luiz Augusto von Dentz <luiz.von.dentz@...el.com>,
stable@...r.kernel.org, Iulia Tanasescu <iulia.tanasescu@....com>,
Pauli Virtanen <pav@....fi>, Jakub Kicinski <kuba@...nel.org>,
Claudia Draghicescu <claudia.rosu@....com>,
linux-bluetooth@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] [v2] Bluetooth: avoid memcmp() out of bounds warning
On Mon, Oct 09, 2023 at 10:31:31PM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@...db.de>
>
> 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: d70e44fef8621 ("Bluetooth: Reject connection with the device which has same BD_ADDR")
> Cc: Kees Cook <keescook@...omium.org>
> Cc: "Lee, Chun-Yi" <jlee@...e.com>
> Cc: Luiz Augusto von Dentz <luiz.von.dentz@...el.com>
> Cc: Marcel Holtmann <marcel@...tmann.org>
> Cc: stable@...r.kernel.org
> Signed-off-by: Arnd Bergmann <arnd@...db.de>
A weird side-effect of the NULL check, but not unreasonable. :)
Reviewed-by: Kees Cook <keescook@...omium.org>
--
Kees Cook
Powered by blists - more mailing lists