Re: [PATCH] Bluetooth: hci_core: remove acl hdr handle error message

From: Luiz Augusto von Dentz
Date: Tue Oct 08 2024 - 10:32:45 EST


On Tue, Oct 8, 2024 at 10:12 AM Luiz Augusto von Dentz
<luiz.dentz@xxxxxxxxx> wrote:
>
> Hi Edward,
>
> On Tue, Oct 8, 2024 at 6:47 AM Edward Adam Davis <eadavis@xxxxxx> wrote:
> >
> > Syzbot reported a uninit-value in hci_rx_work.This is because l2cap didn't
> > execute the corresponding connection request to call l2cap_send_cmd() or
> > l2cap_do_send(), and ultimately called hci_add_acl_hdr() to set hdr->handle.
>
> What are you talking about here, what these functions have to do with
> a local handle variable?
>
> > Therefore, when calling the thread callback function hci_rx_work() to call
> > hci_acldata_packet, hdr->handle should not be used directly.
>
> It is not being used directly, the handle is a local variable which
> get assigned:
>
> handle = __le16_to_cpu(hdr->handle);
>
> If what you are saying is that there is no guarantee that skb->len >=
> HCI_ACL_HDR_SIZE then we probably want to replace skb_pull with
> skb_pull_data.
>
> > Reported-and-tested-by: syzbot+6ea290ba76d8c1eb1ac2@xxxxxxxxxxxxxxxxxxxxxxxxx
> > Closes: https://syzkaller.appspot.com/bug?extid=6ea290ba76d8c1eb1ac2
> > Signed-off-by: Edward Adam Davis <eadavis@xxxxxx>
> > ---
> > net/bluetooth/hci_core.c | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> > index d6976db02c06..20605a7f3f4e 100644
> > --- a/net/bluetooth/hci_core.c
> > +++ b/net/bluetooth/hci_core.c
> > @@ -3791,8 +3791,7 @@ static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb)
> > l2cap_recv_acldata(conn, skb, flags);
> > return;
> > } else {
> > - bt_dev_err(hdev, "ACL packet for unknown connection handle %d",
> > - handle);
> > + bt_dev_err(hdev, "ACL packet for unknown connection handle");
> > }
> >
> > kfree_skb(skb);
> > --
> > 2.43.0
> >
>
>
> --
> Luiz Augusto von Dentz

#syz test

--
Luiz Augusto von Dentz
From cda0135697d86de8a2d732df17e0fa497c2f02ff Mon Sep 17 00:00:00 2001
From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx>
Date: Tue, 8 Oct 2024 10:16:48 -0400
Subject: [PATCH v1] Bluetooth: hci_core: Fix not checking skb length on
hci_acldata_packet

This fixes not checking if skb really contains an ACL header otherwise
the code may attempt to access some uninitilized/invalid memory past the
actual skb->data.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx>
---
net/bluetooth/hci_core.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index b2f8f9c5b610..d5f917076e0e 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3765,18 +3765,22 @@ static void hci_tx_work(struct work_struct *work)
/* ACL data packet */
static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb)
{
- struct hci_acl_hdr *hdr = (void *) skb->data;
+ struct hci_acl_hdr *hdr;
struct hci_conn *conn;
__u16 handle, flags;

- skb_pull(skb, HCI_ACL_HDR_SIZE);
+ hdr = skb_pull_data(skb, sizeof(*hdr));
+ if (!hdr) {
+ bt_dev_err(hdev, "ACL packet too small");
+ goto drop;
+ }

handle = __le16_to_cpu(hdr->handle);
flags = hci_flags(handle);
handle = hci_handle(handle);

- BT_DBG("%s len %d handle 0x%4.4x flags 0x%4.4x", hdev->name, skb->len,
- handle, flags);
+ bt_dev_dbg(hdev, "len %d handle 0x%4.4x flags 0x%4.4x", skb->len,
+ handle, flags);

hdev->stat.acl_rx++;

@@ -3797,6 +3801,7 @@ static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb)
handle);
}

+drop:
kfree_skb(skb);
}

--
2.46.1