Skip to contentSkip to conversation

net/bluetooth: Fix slab-out-of-bounds read in hci_extended_inquiry_result_evt()

PATCH Superseded Peilin Ye 4 participants 7 messages Jul 9, 2020 – Jul 1, 2021

Subsystems (4)
lore
Share & tools
lore

Peilin Ye

author
#0 lore raw

PATCH 1/1 net/bluetooth: Fix slab-out-of-bounds read in hci_extended_inquiry_result_evt()

Check upon num_rsp is insufficient. A malformed event packet with a large num_rsp number makes hci_extended_inquiry_result_evt() go out of bounds. Fix it. Also, make num_rsp unsigned.

This patch fixes the following syzbot bug:

    https://syzkaller.appspot.com/bug?id=4bf11aa05c4ca51ce0df86e500fce486552dc8d2
---
 net/bluetooth/hci_event.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/bluetooth/hci_event.c +3 -3
index 03a0759f2fc2..29aff5e7dec2 100644
@@ -4369,13 +4369,13 @@ static void hci_extended_inquiry_result_evt(struct hci_dev *hdev,
 					    struct sk_buff *skb)
 {
 	struct inquiry_data data;
-	struct extended_inquiry_info *info = (void *) (skb->data + 1);
-	int num_rsp = *((__u8 *) skb->data);
+	struct extended_inquiry_info *info = (void *)(skb->data + 1);
+	__u8 num_rsp = *((__u8 *)skb->data);
 	size_t eir_len;
 
 	BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
 
-	if (!num_rsp)
+	if (!num_rsp || num_rsp * sizeof(*info) > skb->truesize)
 		return;
 
 	if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ))
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v2 1/1 net/bluetooth: Fix slab-out-of-bounds read in hci_extended_inquiry_result_evt()

Check upon num_rsp is insufficient. A malformed event packet with a large num_rsp number makes hci_extended_inquiry_result_evt() go out of bounds. Fix it.

This patch fixes the following syzbot bug:

    https://syzkaller.appspot.com/bug?id=4bf11aa05c4ca51ce0df86e500fce486552dc8d2

---
Changes in v2:
- Use skb->len instead of skb->truesize as the length limit.
- Leave num_rsp as of type int.

 net/bluetooth/hci_event.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bluetooth/hci_event.c +1 -1
index 03a0759f2fc2..91cb3707d20a 100644
@@ -4375,7 +4375,7 @@ static void hci_extended_inquiry_result_evt(struct hci_dev *hdev,
 
 	BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
 
-	if (!num_rsp)
+	if (!num_rsp || skb->len < num_rsp * sizeof(*info))
 		return;
 
 	if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ))
Signature · 1 line
2.25.1
Acked-by on v2 1/1
#2 lore raw
Quoted 10 lines · Peilin Ye

Check upon num_rsp is insufficient. A malformed event packet with a large num_rsp number makes hci_extended_inquiry_result_evt() go out of bounds. Fix it.

This patch fixes the following syzbot bug:

    https://syzkaller.appspot.com/bug?id=4bf11aa05c4ca51ce0df86e500fce486552dc8d2

Bluetooth maintainers, can you also add a cc: stable on this so it gets picked up properly there?

thanks,

greg k-h
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

author
#3 lore raw

PATCH v3 1/1 net/bluetooth: Fix slab-out-of-bounds read in hci_extended_inquiry_result_evt()

In reply to Peilin Ye

Check upon num_rsp is insufficient. A malformed event packet with a large num_rsp number makes hci_extended_inquiry_result_evt() go out of bounds. Fix it.

This patch fixes the following syzbot bug:

    https://syzkaller.appspot.com/bug?id=4bf11aa05c4ca51ce0df86e500fce486552dc8d2

---
Change in v3:
- Minimum skb->len requirement was 1 byte inaccurate since info starts from skb->data + 1. Fix it.

Changes in v2:
- Use skb->len instead of skb->truesize as the length limit.
- Leave num_rsp as of type int.

 net/bluetooth/hci_event.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bluetooth/hci_event.c +1 -1
index 03a0759f2fc2..13d8802b8137 100644
@@ -4375,7 +4375,7 @@ static void hci_extended_inquiry_result_evt(struct hci_dev *hdev,
 
 	BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
 
-	if (!num_rsp)
+	if (!num_rsp || skb->len < num_rsp * sizeof(*info) + 1)
 		return;
 
 	if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ))
Signature · 6 lines
2.25.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
maintainer
#4 lore raw

Hi Peilin,

Quoted 14 lines

Check upon num_rsp is insufficient. A malformed event packet with a large num_rsp number makes hci_extended_inquiry_result_evt() go out of bounds. Fix it.

This patch fixes the following syzbot bug:

   https://syzkaller.appspot.com/bug?id=4bf11aa05c4ca51ce0df86e500fce486552dc8d2

---
Change in v3:
- Minimum skb->len requirement was 1 byte inaccurate since info

Quoted 8 lines
     starts from `skb->data + 1`. Fix it.

Changes in v2:
- Use skb->len instead of skb->truesize as the length limit.
- Leave num_rsp as of type int.

net/bluetooth/hci_event.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel

#5 lore raw

Re: maybe similar bug exists for HCI_EV_INQUIRY_RESULT* like [Linux-kernel-mentees] [PATCH v2] net/bluetooth: slab-out-of-bounds read in hci_extended_inquiry_result_evt()

In reply to Peilin Ye

For the net/bluetooth/hci_event.c , maybe similar bug could be inside hci_inquiry_result_with_rssi_evt() that is HCI_EV_INQUIRY_RESULT_WITH_RSSI and inside hci_inquiry_result_evt() that is HCI_EV_INQUIRY_RESULT.

author
#6 lore raw

Re: maybe similar bug exists for HCI_EV_INQUIRY_RESULT* like [Linux-kernel-mentees] [PATCH v2] net/bluetooth: slab-out-of-bounds read in hci_extended_inquiry_result_evt()

Quoted 3 lines · Alexander Larkin

For the net/bluetooth/hci_event.c , maybe similar bug could be inside hci_inquiry_result_with_rssi_evt() that is HCI_EV_INQUIRY_RESULT_WITH_RSSI and inside hci_inquiry_result_evt() that is HCI_EV_INQUIRY_RESULT.

Hi Alexander,

Thanks for looking into this, I believe they were handled in commit 629b49c848ee ("Bluetooth: Prevent out-of-bounds read in hci_inquiry_result_with_rssi_evt()") and commit 75bbd2ea50ba ("Bluetooth:
Prevent out-of-bounds read in hci_inquiry_result_evt()").

Thanks,
Peilin Ye