Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH v1] Bluetooth: 6lowpan: Always consume the skb in chan_recv_cb
@ 2026-11-13 16:19 Luiz Augusto von Dentz
  2026-11-13 17:03 ` [v1] " bluez.test.bot
  0 siblings, 1 reply; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2026-11-13 16:19 UTC (permalink / raw)
  To: linux-bluetooth

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

The l2cap_chan_ops recv callback takes ownership of the skb on success and
leaves it to the caller on failure.  chan_recv_cb() violates this: when
recv_pkt() fails it returns -EAGAIN even though skb_share_check() may
already have dropped the caller's reference to a shared skb and replaced
it with a clone.  The L2CAP caller then calls kfree_skb() on the original
skb, over-releasing it, while the clone is leaked.

Make recv_pkt() free the skb on its drop path and have chan_recv_cb()
always consume the skb and return 0, including the lookup failures, so the
caller never frees it again.  A dropped packet is accounted in rx_dropped
and no longer reported as a receive error to L2CAP.

Fixes: 11e3ff707278 ("6lowpan: Use skb_cow in IPHC decompression.")
Assisted-by: OpenCode:claude-sonnet-5.5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
 net/bluetooth/6lowpan.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
index 8c51c20f6c4b..68ca2f49dadc 100644
--- a/net/bluetooth/6lowpan.c
+++ b/net/bluetooth/6lowpan.c
@@ -345,6 +345,7 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
 	return NET_RX_SUCCESS;
 
 drop:
+	kfree_skb(skb);
 	dev->stats.rx_dropped++;
 	return NET_RX_DROP;
 }
@@ -356,21 +357,26 @@ static int chan_recv_cb(struct l2cap_chan *chan, struct sk_buff *skb)
 	struct lowpan_peer *peer;
 	int err;
 
+	/* The skb is always consumed, so never return an error that would
+	 * make the caller free it again.
+	 */
 	peer = lookup_peer(chan->conn);
 	if (!peer)
-		return -ENOENT;
+		goto drop;
 
 	dev = lookup_dev(chan->conn);
 	if (!dev || !dev->netdev)
-		return -ENOENT;
+		goto drop;
 
 	err = recv_pkt(skb, dev->netdev, peer);
-	if (err) {
+	if (err)
 		BT_DBG("recv pkt %d", err);
-		err = -EAGAIN;
-	}
 
-	return err;
+	return 0;
+
+drop:
+	kfree_skb(skb);
+	return 0;
 }
 
 static int setup_header(struct sk_buff *skb, struct net_device *netdev,
-- 
2.56.0


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

end of thread, other threads:[~2026-11-13 17:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 16:19 [PATCH v1] Bluetooth: 6lowpan: Always consume the skb in chan_recv_cb Luiz Augusto von Dentz
2026-11-13 17:03 ` [v1] " bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox