From: Kees Cook <keescook@chromium.org>
To: Edward AD <twuufnxlz@gmail.com>
Cc: syzbot+c90849c50ed209d77689@syzkaller.appspotmail.com,
davem@davemloft.net, edumazet@google.com,
johan.hedberg@gmail.com, kuba@kernel.org,
linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org,
luiz.dentz@gmail.com, luiz.von.dentz@intel.com,
marcel@holtmann.org, netdev@vger.kernel.org, pabeni@redhat.com,
syzkaller-bugs@googlegroups.com
Subject: Re: [PATCH] Bluetooth: hci_sock: fix slab oob read in create_monitor_event
Date: Wed, 11 Oct 2023 09:20:39 -0700 [thread overview]
Message-ID: <202310110908.F2639D3276@keescook> (raw)
In-Reply-To: <20231010053656.2034368-2-twuufnxlz@gmail.com>
On Tue, Oct 10, 2023 at 01:36:57PM +0800, Edward AD wrote:
> When accessing hdev->name, the actual string length should prevail
>
> Reported-by: syzbot+c90849c50ed209d77689@syzkaller.appspotmail.com
> Fixes: dcda165706b9 ("Bluetooth: hci_core: Fix build warnings")
> Signed-off-by: Edward AD <twuufnxlz@gmail.com>
> ---
> net/bluetooth/hci_sock.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
> index 5e4f718073b7..72abe54c45dd 100644
> --- a/net/bluetooth/hci_sock.c
> +++ b/net/bluetooth/hci_sock.c
> @@ -488,7 +488,7 @@ static struct sk_buff *create_monitor_event(struct hci_dev *hdev, int event)
> ni->type = hdev->dev_type;
> ni->bus = hdev->bus;
> bacpy(&ni->bdaddr, &hdev->bdaddr);
> - memcpy(ni->name, hdev->name, 8);
> + memcpy(ni->name, hdev->name, strlen(hdev->name));
Uh, what's going on here?
hdev is:
struct hci_dev {
...
const char *name;
ni is:
struct hci_mon_new_index {
char name[8];
You can't use "strlen" here in the case that "hdev->name" is larger than
8 bytes.
Also, why memcpy() and not strscpy()? Is this supposed to be padded out
with %NUL bytes? It appears to be sent over the network, so "yes" seems
to be the safe answer.
Should ni->name be always %NUL terminated? That I can't tell for sure,
but I assume "no", because the solution was to explicitly copy all the
bytes _except_ the %NUL byte (using strlen).
struct hci_mon_new_index's "name" should be marked __nonstring, and
instead strtomem_pad() should be used instead of memcpy.
-Kees
>
> opcode = cpu_to_le16(HCI_MON_NEW_INDEX);
> break;
> --
> 2.25.1
>
--
Kees Cook
prev parent reply other threads:[~2023-10-11 16:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-09 10:29 [syzbot] [bluetooth?] KASAN: slab-out-of-bounds Read in create_monitor_event syzbot
2023-10-09 11:32 ` shaozhengchao
2023-10-10 5:36 ` [PATCH] Bluetooth: hci_sock: fix slab oob read " Edward AD
2023-10-10 18:40 ` patchwork-bot+bluetooth
2023-10-11 16:20 ` Kees Cook [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202310110908.F2639D3276@keescook \
--to=keescook@chromium.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=johan.hedberg@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=luiz.von.dentz@intel.com \
--cc=marcel@holtmann.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=syzbot+c90849c50ed209d77689@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=twuufnxlz@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).