summaryrefslogtreecommitdiff
path: root/tools/perf/scripts/python
diff options
context:
space:
mode:
authorPiyus Kedia <piyus@iiitd.ac.in>2026-11-12 23:08:12 +0530
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2026-11-16 13:13:42 -0500
commit76248359ac32e97cd7d1bd55a4c94a2ad4009871 (patch)
tree139148a2781309a17443a5bec8a0a642078aef2b /tools/perf/scripts/python
parent3b069de8a5d688c7e8381b99d6cdb7467fcae0de (diff)
Bluetooth: L2CAP: clear the SDU before the receive callback
l2cap_ecred_data_rcv() completes a reassembled SDU by calling l2cap_ecred_recv() with chan->sdu still set, and only clears the reassembly state after it returns: if (chan->sdu->len == chan->sdu_len) { err = l2cap_ecred_recv(chan, chan->sdu); if (!err) { chan->sdu = NULL; ... l2cap_ecred_recv() hands the SDU to the channel's receive callback, which takes ownership of it on success, and then updates the credits: err = chan->ops->recv(chan, skb); ... l2cap_chan_le_send_credits(chan); l2cap_chan_le_send_credits() calls l2cap_le_rx_credits(), which reads size_t sdu_len = chan->sdu ? chan->sdu->len : 0; so between the callback consuming the skb and the assignment above, chan->sdu is a dangling pointer that is dereferenced. For the 6LoWPAN channel the callback frees the skb outright - chan_recv_cb() -> recv_pkt() ends in consume_skb(skb) and returns NET_RX_SUCCESS - so the read is a straightforward use-after-free that KASAN reports: BUG: KASAN: slab-use-after-free in l2cap_le_rx_credits net/bluetooth/l2cap_core.c:576 [inline] BUG: KASAN: slab-use-after-free in l2cap_chan_le_send_credits+0xa8/0x3e0 net/bluetooth/l2cap_core.c:6811 Read of size 4 at addr ffff88800e134070 by task kworker/u21:2/11352 Workqueue: hci0 hci_rx_work l2cap_le_rx_credits net/bluetooth/l2cap_core.c:576 [inline] l2cap_chan_le_send_credits+0xa8/0x3e0 net/bluetooth/l2cap_core.c:6811 l2cap_ecred_recv+0x63/0x120 net/bluetooth/l2cap_core.c:6873 l2cap_ecred_data_rcv net/bluetooth/l2cap_core.c:6976 [inline] l2cap_data_channel net/bluetooth/l2cap_core.c:7028 [inline] l2cap_recv_frame+0x6c3c/0x9650 net/bluetooth/l2cap_core.c:7162 l2cap_recv_acldata+0x6fd/0xe60 net/bluetooth/l2cap_core.c:7902 hci_acldata_packet net/bluetooth/hci_core.c:3865 [inline] hci_rx_work+0x3c0/0xbe0 net/bluetooth/hci_core.c:4092 Freed by task 11352: recv_pkt net/bluetooth/6lowpan.c chan_recv_cb+0x88/0x150 net/bluetooth/6lowpan.c:367 l2cap_ecred_recv+0x61/0x160 net/bluetooth/l2cap_core.c:6864 The buggy address belongs to the object at ffff88800e134000 which belongs to the cache skbuff_head_cache of size 240 The buggy address is located 112 bytes inside of freed 240-byte region Offset 112 is sk_buff.len. Only a multi-frame SDU is affected: the single-frame path already calls l2cap_ecred_recv() with chan->sdu NULL, so l2cap_le_rx_credits() reads a zero sdu_len there. l2cap_reassemble_sdu() completes a segmented SDU the same way and has the same defect. On an ERTM or streaming channel l2cap_sock_recv_cb() calls l2cap_publish_rx_avail(), which reaches l2cap_chan_le_send_credits() through l2cap_chan_rx_avail(), and that function evaluates u16 return_credits = l2cap_le_rx_credits(chan); in its initializer - before the mode test that makes the rest of it a no-op for a non-LE channel. So chan->sdu is dereferenced on that path too, and the result is discarded. What makes it a use-after-free rather than a stale read is a consumer that frees the skb from another thread: BNEP's session kthread takes it off the socket with a lockless skb_dequeue() (net/bluetooth/bnep/core.c:530, freed at :533) and never takes the socket lock, so lock_sock() is no defence. Fix both sites. Clear the reassembly state before handing the SDU to the callback, which makes the fragmented path behave like the single-frame one, and free the SDU on the spot if the callback refused it - the error path's kfree_skb(chan->sdu) used to do that, and the callbacks leave the skb to the caller when they fail. Clearing it first is also the arithmetically correct input, not merely a safe one. l2cap_le_rx_credits() subtracts sdu_len from chan->rx_avail because a partially reassembled SDU will claim that much receive buffer once it completes: if (chan->rx_avail <= sdu_len) return 0; return DIV_ROUND_UP(chan->rx_avail - sdu_len, chan->mps); A completed SDU is no longer waiting for that space. If the callback queued it, l2cap_sock_recv_cb() has already called l2cap_publish_rx_avail(), which recomputes rx_avail from sk_rcvbuf - sk_rmem_alloc with that skb included in sk_rmem_alloc; if the callback consumed it, as the 6LoWPAN one does, it occupies nothing at all. Either way the reassembly buffer is empty, so zero is the right sdu_len, and a NULL chan->sdu is how l2cap_le_rx_credits() expresses that - the same value l2cap_le_flowctl_init() depends on when it seeds chan->rx_credits on an idle channel. Carrying the old length into the calculation instead would subtract the SDU a second time and under-grant credits on every delivery, and once rx_avail fell to the size of one SDU the channel would be granted none at all. Per Documentation/process/generated-content.rst: the use-after-free was found by an AI-driven fuzzing harness built on syzkaller, developed jointly by Kapil Vaswani and myself, which drove a virtual HCI controller and a 6LoWPAN channel under KASAN on x86_64. The root-cause analysis, this changelog and the patch were written with the assistance of a large language model over an extended session, and reviewed by hand; the before/after testing below the --- was run by us. Fixes: ce60b9231b66 ("Bluetooth: compute LE flow credits based on recvbuf space") Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai> Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Diffstat (limited to 'tools/perf/scripts/python')
0 files changed, 0 insertions, 0 deletions