[PATCH 4.4 037/149] Bluetooth: Prevent out-of-bounds read in hci_inquiry_result_with_rssi_evt()

From: Greg Kroah-Hartman
Date: Thu Aug 20 2020 - 06:35:50 EST


From: Peilin Ye <yepeilin.cs@xxxxxxxxx>

commit 629b49c848ee71244203934347bd7730b0ddee8d upstream.

Check `num_rsp` before using it as for-loop counter. Add `unlock` label.

Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Peilin Ye <yepeilin.cs@xxxxxxxxx>
Signed-off-by: Marcel Holtmann <marcel@xxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

---
net/bluetooth/hci_event.c | 7 +++++++
1 file changed, 7 insertions(+)

--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3609,6 +3609,9 @@ static void hci_inquiry_result_with_rssi
struct inquiry_info_with_rssi_and_pscan_mode *info;
info = (void *) (skb->data + 1);

+ if (skb->len < num_rsp * sizeof(*info) + 1)
+ goto unlock;
+
for (; num_rsp; num_rsp--, info++) {
u32 flags;

@@ -3630,6 +3633,9 @@ static void hci_inquiry_result_with_rssi
} else {
struct inquiry_info_with_rssi *info = (void *) (skb->data + 1);

+ if (skb->len < num_rsp * sizeof(*info) + 1)
+ goto unlock;
+
for (; num_rsp; num_rsp--, info++) {
u32 flags;

@@ -3650,6 +3656,7 @@ static void hci_inquiry_result_with_rssi
}
}

+unlock:
hci_dev_unlock(hdev);
}