diff mbox series

[v1,1/2] Bluetooth: hci_core: Fix not checking skb length on hci_acldata_packet

Message ID 20241008154005.595169-1-luiz.dentz@gmail.com (mailing list archive)
State Superseded
Headers show
Series [v1,1/2] Bluetooth: hci_core: Fix not checking skb length on hci_acldata_packet | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch warning WARNING: Reported-by: should be immediately followed by Closes: with a URL to the report #96: Reported-by: syzbot+6ea290ba76d8c1eb1ac2@syzkaller.appspotmail.com Tested-by: syzbot+6ea290ba76d8c1eb1ac2@syzkaller.appspotmail.com WARNING: The commit message has 'syzkaller', perhaps it also needs a 'Fixes:' tag? total: 0 errors, 2 warnings, 0 checks, 33 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /github/workspace/src/src/13826647.patch has style problems, please review. NOTE: Ignored message types: UNKNOWN_COMMIT_ID NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.
tedd_an/GitLint success Gitlint PASS
tedd_an/SubjectPrefix success Gitlint PASS
tedd_an/BuildKernel success BuildKernel PASS
tedd_an/CheckAllWarning warning CheckSparse WARNING net/bluetooth/hci_core.c: In function ‘hci_scodata_packet’:./include/net/bluetooth/bluetooth.h:280:9: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘unsigned int’ [-Wformat=] 280 | BT_DBG("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__) | ^~~~~~./include/net/bluetooth/bluetooth.h:266:33: note: in definition of macro ‘BT_DBG’ 266 | #define BT_DBG(fmt, ...) bt_dbg(fmt "\n", ##__VA_ARGS__) | ^~~net/bluetooth/hci_core.c:3825:2: note: in expansion of macro ‘bt_dev_dbg’ 3825 | bt_dev_dbg(hdev, "%s len %d handle 0x%4.4x flags 0x%4.4x", skb->len, | ^~~~~~~~~~net/bluetooth/hci_core.c:3825:21: note: format string is defined here 3825 | bt_dev_dbg(hdev, "%s len %d handle 0x%4.4x flags 0x%4.4x", skb->len, | ~^ | | | char * | %dnet/bluetooth/hci_core.c:3825:2: note: in expansion of macro ‘bt_dev_dbg’ 3825 | bt_dev_dbg(hdev, "%s len %d handle 0x%4.4x flags 0x%4.4x", skb->len, | ^~~~~~~~~~net/bluetooth/hci_core.c:3825:57: note: format string is defined here 3825 | bt_dev_dbg(hdev, "%s len %d handle 0x%4.4x flags 0x%4.4x", skb->len, | ~~~~^ | | | unsigned intnet/bluetooth/hci_core.c: In function ‘hci_scodata_packet’:./include/net/bluetooth/bluetooth.h:280:9: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘unsigned int’ [-Wformat=] 280 | BT_DBG("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__) | ^~~~~~./include/net/bluetooth/bluetooth.h:266:33: note: in definition of macro ‘BT_DBG’ 266 | #define BT_DBG(fmt, ...) bt_dbg(fmt "\n", ##__VA_ARGS__) | ^~~net/bluetooth/hci_core.c:3825:2: note: in expansion of macro ‘bt_dev_dbg’ 3825 | bt_dev_dbg(hdev, "%s len %d handle 0x%4.4x flags 0x%4.4x", skb->len, | ^~~~~~~~~~net/bluetooth/hci_core.c:3825:21: note: format string is defined here 3825 | bt_dev_dbg(hdev, "%s len %d handle 0x%4.4x flags 0x%4.4x", skb->len, | ~^ | | | char * | %dnet/bluetooth/hci_core.c:3825:2: note: in expansion of macro ‘bt_dev_dbg’ 3825 | bt_dev_dbg(hdev, "%s len %d handle 0x%4.4x flags 0x%4.4x", skb->len, | ^~~~~~~~~~net/bluetooth/hci_core.c:3825:57: note: format string is defined here 3825 | bt_dev_dbg(hdev, "%s len %d handle 0x%4.4x flags 0x%4.4x", skb->len, | ~~~~^ | | | unsigned int
tedd_an/CheckSparse warning CheckSparse WARNING net/bluetooth/hci_core.c: In function ‘hci_scodata_packet’:net/bluetooth/hci_core.c:3825:2: note: in expansion of macro ‘bt_dev_dbg’net/bluetooth/hci_core.c:3825:21: note: format string is defined herenet/bluetooth/hci_core.c:3825:2: note: in expansion of macro ‘bt_dev_dbg’net/bluetooth/hci_core.c:3825:57: note: format string is defined herenet/bluetooth/hci_core.c: In function ‘hci_scodata_packet’:net/bluetooth/hci_core.c:3825:2: note: in expansion of macro ‘bt_dev_dbg’net/bluetooth/hci_core.c:3825:21: note: format string is defined herenet/bluetooth/hci_core.c:3825:2: note: in expansion of macro ‘bt_dev_dbg’net/bluetooth/hci_core.c:3825:57: note: format string is defined here

Commit Message

Luiz Augusto von Dentz Oct. 8, 2024, 3:40 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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

Reported-by: syzbot+6ea290ba76d8c1eb1ac2@syzkaller.appspotmail.com
Tested-by: syzbot+6ea290ba76d8c1eb1ac2@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=6ea290ba76d8c1eb1ac2
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
 net/bluetooth/hci_core.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
diff mbox series

Patch

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);
 }