All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] Bluetooth: hci_core: Fix not checking skb length on hci_acldata_packet
@ 2024-10-09 17:41 Luiz Augusto von Dentz
  2024-10-09 17:41 ` [PATCH v2 2/2] Bluetooth: hci_core: Fix not checking skb length on hci_scodata_packet Luiz Augusto von Dentz
  2024-10-10 23:30 ` [PATCH v2 1/2] Bluetooth: hci_core: Fix not checking skb length on hci_acldata_packet patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2024-10-09 17:41 UTC (permalink / raw)
  To: linux-bluetooth

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 --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.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2 2/2] Bluetooth: hci_core: Fix not checking skb length on hci_scodata_packet
  2024-10-09 17:41 [PATCH v2 1/2] Bluetooth: hci_core: Fix not checking skb length on hci_acldata_packet Luiz Augusto von Dentz
@ 2024-10-09 17:41 ` Luiz Augusto von Dentz
  2024-10-10 23:30 ` [PATCH v2 1/2] Bluetooth: hci_core: Fix not checking skb length on hci_acldata_packet patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2024-10-09 17:41 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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

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 --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index d5f917076e0e..779c4aeaef22 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3808,18 +3808,22 @@ static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb)
 /* SCO data packet */
 static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb)
 {
-	struct hci_sco_hdr *hdr = (void *) skb->data;
+	struct hci_sco_hdr *hdr;
 	struct hci_conn *conn;
 	__u16 handle, flags;
 
-	skb_pull(skb, HCI_SCO_HDR_SIZE);
+	hdr = skb_pull_data(skb, sizeof(*hdr));
+	if (!hdr) {
+		bt_dev_err(hdev, "SCO 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.sco_rx++;
 
@@ -3837,6 +3841,7 @@ static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb)
 				       handle);
 	}
 
+drop:
 	kfree_skb(skb);
 }
 
-- 
2.46.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 1/2] Bluetooth: hci_core: Fix not checking skb length on hci_acldata_packet
  2024-10-09 17:41 [PATCH v2 1/2] Bluetooth: hci_core: Fix not checking skb length on hci_acldata_packet Luiz Augusto von Dentz
  2024-10-09 17:41 ` [PATCH v2 2/2] Bluetooth: hci_core: Fix not checking skb length on hci_scodata_packet Luiz Augusto von Dentz
@ 2024-10-10 23:30 ` patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2024-10-10 23:30 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hello:

This series was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Wed,  9 Oct 2024 13:41:58 -0400 you wrote:
> 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>
> 
> [...]

Here is the summary with links:
  - [v2,1/2] Bluetooth: hci_core: Fix not checking skb length on hci_acldata_packet
    https://git.kernel.org/bluetooth/bluetooth-next/c/32fed76a03eb
  - [v2,2/2] Bluetooth: hci_core: Fix not checking skb length on hci_scodata_packet
    https://git.kernel.org/bluetooth/bluetooth-next/c/7285f89d6a95

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-10-10 23:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-09 17:41 [PATCH v2 1/2] Bluetooth: hci_core: Fix not checking skb length on hci_acldata_packet Luiz Augusto von Dentz
2024-10-09 17:41 ` [PATCH v2 2/2] Bluetooth: hci_core: Fix not checking skb length on hci_scodata_packet Luiz Augusto von Dentz
2024-10-10 23:30 ` [PATCH v2 1/2] Bluetooth: hci_core: Fix not checking skb length on hci_acldata_packet patchwork-bot+bluetooth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.