Skip to contentSkip to conversation

Bluetooth: L2CAP: Fix printing wrong information if SDU length exceeds MTU

PATCH Applied Luiz Augusto von Dentz 3 participants 5 messages Mar 16 – Mar 17

Subsystems (2)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/2 Bluetooth: L2CAP: Fix printing wrong information if SDU length exceeds MTU

From: Luiz Augusto von Dentz <[email protected]>

The code was printing skb->len and sdu_len in the places where it should be sdu_len and chan->imtu respectively to match the if conditions.

Fixes fa768fce4aae ("Bluetooth: LE L2CAP: Disconnect if received packet's SDU exceeds IMTU")
---
 net/bluetooth/l2cap_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bluetooth/l2cap_core.c +1 -1
index 4c63c949d839..6394cbcc838b 100644
@@ -6705,7 +6705,7 @@ static int l2cap_ecred_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb)
 
 		if (sdu_len > chan->imtu) {
 			BT_ERR("Too big LE L2CAP SDU length: len %u > %u",
-			       skb->len, sdu_len);
+			       sdu_len, chan->imtu);
 			l2cap_send_disconn_req(chan, ECONNRESET);
 			err = -EMSGSIZE;
 			goto failed;
Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH 2/2 Bluetooth: MGMT: Fix dangling pointer on mgmt_add_adv_patterns_monitor_complete

From: Luiz Augusto von Dentz <[email protected]>

This fixes the condition checking so mgmt_pending_valid is executed whenever status != -ECANCELED otherwise Calling mgmt_pending_free(cmd) would kfree(cmd) without unlinking it from the list first, leaving a dangling pointer. Any subsequent list traversal (e.g., mgmt_pending_foreach during __mgmt_power_off, or another mgmt_pending_valid call) would dereference freed memory.

Fixes 302a1f674c00 ("Bluetooth: MGMT: Fix possible UAFs")
---
 net/bluetooth/mgmt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bluetooth/mgmt.c +1 -1
index d52238ce6a9a..e5f9287fb826 100644
@@ -5355,7 +5355,7 @@ static void mgmt_add_adv_patterns_monitor_complete(struct hci_dev *hdev,
 	 * hci_adv_monitors_clear is about to be called which will take care of
 	 * freeing the adv_monitor instances.
 	 */
-	if (status == -ECANCELED && !mgmt_pending_valid(hdev, cmd))
+	if (status == -ECANCELED || !mgmt_pending_valid(hdev, cmd))
 		return;
 
 	monitor = cmd->user_data;
Signature · 1 line
2.53.0
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH v1 2/2] Bluetooth: MGMT: Fix dangling pointer on mgmt_add_adv_patterns_monitor_complete

Dear Luiz,

Thank you for your patch.

Am 16.03.26 um 20:09 schrieb Luiz Augusto von Dentz:

Quoted 4 lines

From: Luiz Augusto von Dentz <[email protected]>

This fixes the condition checking so mgmt_pending_valid is executed whenever status != -ECANCELED otherwise Calling mgmt_pending_free(cmd)

s/Calling/calling/

Quoted 16 lines

would kfree(cmd) without unlinking it from the list first, leaving a dangling pointer. Any subsequent list traversal (e.g., mgmt_pending_foreach during __mgmt_power_off, or another mgmt_pending_valid call) would dereference freed memory.

Fixes 302a1f674c00 ("Bluetooth: MGMT: Fix possible UAFs")
---
  net/bluetooth/mgmt.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/bluetooth/mgmt.c +0 -0
index d52238ce6a9a..e5f9287fb826 100644

net/bluetooth/mgmt.c static void mgmt_add_adv_patterns_monitor_complete(struct hci_dev *hdev, · line 5361

Quoted 8 lines
net/bluetooth/mgmt.c +1 -1
@@ -5355,7 +5355,7 @@ static void mgmt_add_adv_patterns_monitor_complete(struct hci_dev *hdev,
  	 * hci_adv_monitors_clear is about to be called which will take care of
  	 * freeing the adv_monitor instances.
  	 */
-	if (status == -ECANCELED && !mgmt_pending_valid(hdev, cmd))
+	if (status == -ECANCELED || !mgmt_pending_valid(hdev, cmd))
  		return;
 
  	monitor = cmd->user_data;

Kind regards,

Paul

Reviewed-by on v1 1/2
#3 lore raw
In reply to Luiz Augusto von Dentz

Dear Luiz,

Thank you for your patch.

Am 16.03.26 um 20:09 schrieb Luiz Augusto von Dentz:

Quoted 4 lines

From: Luiz Augusto von Dentz <[email protected]>

The code was printing skb->len and sdu_len in the places where it should be sdu_len and chan->imtu respectively to match the if conditions.

Maybe add the URL of the message with the review comments?

Quoted 11 lines
Fixes fa768fce4aae ("Bluetooth: LE L2CAP: Disconnect if received packet's SDU exceeds IMTU")
---
  net/bluetooth/l2cap_core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/bluetooth/l2cap_core.c +0 -0
index 4c63c949d839..6394cbcc838b 100644

net/bluetooth/l2cap_core.c static int l2cap_ecred_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb) · line 6711

Quoted 8 lines
net/bluetooth/l2cap_core.c +1 -1
@@ -6705,7 +6705,7 @@ static int l2cap_ecred_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb)
 
  		if (sdu_len > chan->imtu) {
  			BT_ERR("Too big LE L2CAP SDU length: len %u > %u",
-			       skb->len, sdu_len);
+			       sdu_len, chan->imtu);
  			l2cap_send_disconn_req(chan, ECONNRESET);
  			err = -EMSGSIZE;
  			goto failed;

Kind regards,

Paul

#4 lore raw
In reply to Luiz Augusto von Dentz
This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 9 lines · On Mon, 16 Mar 2026 15:09:56 -0400 you wrote:

From: Luiz Augusto von Dentz <[email protected]>

The code was printing skb->len and sdu_len in the places where it should be sdu_len and chan->imtu respectively to match the if conditions.

Fixes fa768fce4aae ("Bluetooth: LE L2CAP: Disconnect if received packet's SDU exceeds IMTU")

[...]

Here is the summary with links:
- [v1,1/2] Bluetooth: L2CAP: Fix printing wrong information if SDU length exceeds MTU

    https://git.kernel.org/bluetooth/bluetooth-next/c/013598897448

- [v1,2/2] Bluetooth: MGMT: Fix dangling pointer on mgmt_add_adv_patterns_monitor_complete
https://git.kernel.org/bluetooth/bluetooth-next/c/3c2dbfa16ca6

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html