diff mbox series

Bluetooth: MGTM: Fix slab-out-of-bounds in tlv_data_is_valid

Message ID 20210528001702.69323-1-luiz.dentz@gmail.com
State Superseded
Headers show
Series Bluetooth: MGTM: Fix slab-out-of-bounds in tlv_data_is_valid | expand

Commit Message

Luiz Augusto von Dentz May 28, 2021, 12:17 a.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Found with:

tools/mgmt-tester -s "Add Advertising - Success (ScRsp only)"

Add Advertising - Success (ScRsp only) - run
  Sending Add Advertising (0x003e)
  Test condition added, total 1
[   11.004577] ==================================================================
[   11.005292] BUG: KASAN: slab-out-of-bounds in tlv_data_is_valid+0x87/0xe0
[   11.005984] Read of size 1 at addr ffff888002c695b0 by task mgmt-tester/87
[   11.006711]
[   11.007176]
[   11.007429] Allocated by task 87:
[   11.008151]
[   11.008438] The buggy address belongs to the object at ffff888002c69580
[   11.008438]  which belongs to the cache kmalloc-64 of size 64
[   11.010526] The buggy address is located 48 bytes inside of
[   11.010526]  64-byte region [ffff888002c69580, ffff888002c695c0)
[   11.012423] The buggy address belongs to the page:
[   11.013291]
[   11.013544] Memory state around the buggy address:
[   11.014359]  ffff888002c69480: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
[   11.015453]  ffff888002c69500: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
[   11.016232] >ffff888002c69580: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc
[   11.017010]                                      ^
[   11.017547]  ffff888002c69600: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc
[   11.018296]  ffff888002c69680: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
[   11.019116] ==================================================================

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
 net/bluetooth/mgmt.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Marcel Holtmann May 28, 2021, 5:36 a.m. UTC | #1
Hi Luiz,

> Found with:
> 
> tools/mgmt-tester -s "Add Advertising - Success (ScRsp only)"
> 
> Add Advertising - Success (ScRsp only) - run
>  Sending Add Advertising (0x003e)
>  Test condition added, total 1
> [   11.004577] ==================================================================
> [   11.005292] BUG: KASAN: slab-out-of-bounds in tlv_data_is_valid+0x87/0xe0
> [   11.005984] Read of size 1 at addr ffff888002c695b0 by task mgmt-tester/87
> [   11.006711]
> [   11.007176]
> [   11.007429] Allocated by task 87:
> [   11.008151]
> [   11.008438] The buggy address belongs to the object at ffff888002c69580
> [   11.008438]  which belongs to the cache kmalloc-64 of size 64
> [   11.010526] The buggy address is located 48 bytes inside of
> [   11.010526]  64-byte region [ffff888002c69580, ffff888002c695c0)
> [   11.012423] The buggy address belongs to the page:
> [   11.013291]
> [   11.013544] Memory state around the buggy address:
> [   11.014359]  ffff888002c69480: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
> [   11.015453]  ffff888002c69500: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
> [   11.016232] >ffff888002c69580: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc
> [   11.017010]                                      ^
> [   11.017547]  ffff888002c69600: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc
> [   11.018296]  ffff888002c69680: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
> [   11.019116] ==================================================================
> 
> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> ---
> net/bluetooth/mgmt.c | 3 +++
> 1 file changed, 3 insertions(+)

please git blame this and add a Fixes: tag.

Regards

Marcel
diff mbox series

Patch

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 91d36c3bf23e..b52e39fe0285 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -7590,6 +7590,9 @@  static bool tlv_data_is_valid(struct hci_dev *hdev, u32 adv_flags, u8 *data,
 	for (i = 0, cur_len = 0; i < len; i += (cur_len + 1)) {
 		cur_len = data[i];
 
+		if (!cur_len)
+			continue;
+
 		if (data[i + 1] == EIR_FLAGS &&
 		    (!is_adv_data || flags_managed(adv_flags)))
 			return false;