WARNING in l2cap_chan_le_send_credits

Status: upstream: reported on 2026/11/13 23:38
Subsystems: bluetooth
Labels: prio:high
[Documentation on labels]
Reported-by: syzbot+9dc8780713b11155dd74@syzkaller.appspotmail.com
First crash: 1d00h, last: 1d00h
✨ AI-generated root cause summary:

In net/bluetooth/l2cap_core.c, l2cap_chan_le_send_credits() allocates an L2CAP transaction identifier via l2cap_get_ident() and unconditionally calls ida_free(&conn->tx_ida, ident) after transmission under the assumption that L2CAP_LE_CREDITS never expects a response. However, if the remote peer rejects the packet with L2CAP_COMMAND_REJ or sends a signaling response bearing that identifier, the asynchronous RX signaling handler l2cap_put_ident() sees the ID as currently allocated and frees it first. When l2cap_chan_le_send_credits() then executes ida_free() on the already-released identifier, ida_free() detects that the ID is not allocated and triggers the warning in lib/idr.c.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 18f2d01bfce9:

Root Cause Analysis

1. Functions, Structs, and Files Involved

  • net/bluetooth/l2cap_core.c:
    • l2cap_chan_le_send_credits(): Allocates and immediately releases the transaction identifier for outgoing credit packets.
    • l2cap_get_ident(): Allocates an ID from conn->tx_ida using ida_alloc_range().
    • l2cap_put_ident(): Frees an ID from conn->tx_ida when receiving responses or rejection packets.
    • struct l2cap_conn: Holds the connection state and struct ida tx_ida.
  • lib/idr.c:
    • ida_free(): Frees an allocated ID in an IDA instance and issues WARN(1, "ida_free called for id=%d which is not allocated.\n", id) if the ID's bit is not set.

2. Detailed Technical Mechanism

  1. Transaction Identifier Management: Commit 6c3ea155e5ee replaced the cyclic counter for L2CAP signaling transaction identifiers with an IDA structure (conn->tx_ida) to track in-flight requests and reuse IDs once freed by responses in l2cap_put_ident(). Commit 6e1930ece855 observed that L2CAP_LE_CREDITS is an unacknowledged indication/credit packet without an explicit response. To prevent exhausting the 1–255 ID range, l2cap_chan_le_send_credits() was changed to allocate an identifier and then immediately free it:

    ident = l2cap_get_ident(conn);
    l2cap_send_cmd(conn, ident, L2CAP_LE_CREDITS, sizeof(pkt), &pkt);
    if (ident > 0)
        ida_free(&conn->tx_ida, ident);
    
  2. The Race Condition / Lifecycle Violation:

    • l2cap_chan_le_send_credits() is invoked along the socket read path (e.g., l2cap_sock_recvmsg() -> l2cap_publish_rx_avail() -> l2cap_chan_rx_avail()) holding only lock_sock(sk). Neither chan->lock nor conn->lock is held.
    • When l2cap_chan_le_send_credits() allocates ident (here, ident = 2) via l2cap_get_ident(conn), bit 2 is set in conn->tx_ida.
    • l2cap_send_cmd(conn, ident, L2CAP_LE_CREDITS, ...) builds and transmits the frame.
    • Per the Bluetooth Core Specification, a remote peer or virtual HCI controller (such as syzkaller's vhci) may respond to any unrecognized, malformed, or rejected signaling command with L2CAP_COMMAND_REJ, quoting the rejected command's identifier (cmd->ident = 2).
    • When the RX signaling handler (l2cap_le_sig_cmd() or l2cap_bredr_sig_cmd()) processes the incoming frame, it invokes:
      l2cap_put_ident(conn, cmd->code, cmd->ident);
      
      Inside l2cap_put_ident():
      case L2CAP_COMMAND_REJ:
      ...
          if (ida_find_first_range(&conn->tx_ida, id, id) >= 0)
              ida_free(&conn->tx_ida, id);
      
    • Because ident = 2 is still marked allocated in conn->tx_ida during the transmission window, ida_find_first_range(&conn->tx_ida, 2, 2) succeeds and l2cap_put_ident() executes ida_free(&conn->tx_ida, 2).
    • Once execution resumes in l2cap_chan_le_send_credits(), it executes its own unconditional ida_free(&conn->tx_ida, 2).
    • ida_free() inspects conn->tx_ida, finds bit 2 already unset (0), and triggers the warning:
      ida_free called for id=2 which is not allocated.
      WARNING: lib/idr.c:594 at ida_free+0x24c/0x2d4 lib/idr.c:594
      
▶ ▼ ✨ AI Jobs (1)
ID Workflow Result Correct Bug Created Started Finished Revision
fb8805d9 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ✅ RemoteTrigger: ✅ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ WARNING in l2cap_chan_le_send_credits 2026/11/12 23:37 2026/11/12 23:37 2026/11/13 00:12 c0087d7f
▶ ▼ Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [bluetooth?] WARNING in l2cap_chan_le_send_credits 0 (1) 2026/11/13 23:38

Sample crash report:
------------[ cut here ]------------
ida_free called for id=2 which is not allocated.
WARNING: lib/idr.c:594 at ida_free+0x24c/0x2d4 lib/idr.c:594, CPU#0: syz.4.2428/12785
Modules linked in:
CPU: 0 UID: 0 PID: 12785 Comm: syz.4.2428 Tainted: G             L      syzkaller #0 PREEMPT 
Tainted: [L]=SOFTLOCKUP
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : ida_free+0x24c/0x2d4 lib/idr.c:594
lr : ida_free+0x24c/0x2d4 lib/idr.c:594
sp : ffff800094d27880
x29: ffff800094d27910 x28: 00000000000000cc x27: 1fffe0001fc18211
x26: 0000000000000002 x25: dfff800000000000 x24: ffff800094d27880
x23: ffff7000129a4f10 x22: 00000000000000ca x21: 0000000000000000
x20: 0000000000000002 x19: 0000000000000000 x18: 00000000ffffffff
x17: 0000000000000000 x16: 0000000000000000 x15: ffff80008b586000
x14: 0000000000001f42 x13: 0000000000000001 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000080000 x9 : 8f9eb4c3589ac800
x8 : 8f9eb4c3589ac800 x7 : 756372735f656c6f x6 : 5f656c6f736e6f63
x5 : ffff0000e4be4ffc x4 : 0000000000000000 x3 : ffff80008030d4c8
x2 : 0000000100000000 x1 : ffff0000dc3b0000 x0 : 0000000000000001
Call trace:
 ida_free+0x24c/0x2d4 lib/idr.c:594 (P)
 l2cap_chan_le_send_credits+0x17c/0x29c net/bluetooth/l2cap_core.c:7113
 l2cap_chan_rx_avail+0xb4/0x134 net/bluetooth/l2cap_core.c:7126
 l2cap_publish_rx_avail+0x110/0x168 net/bluetooth/l2cap_sock.c:-1
 l2cap_sock_recvmsg+0x280/0x7b8 net/bluetooth/l2cap_sock.c:1317
 sock_recvmsg_nosec net/socket.c:1154 [inline]
 sock_recvmsg+0xd4/0x170 net/socket.c:1176
 __sys_recvfrom+0x1ec/0x31c net/socket.c:2333
 __do_sys_recvfrom net/socket.c:2348 [inline]
 __se_sys_recvfrom net/socket.c:2344 [inline]
 __arm64_sys_recvfrom+0xec/0x10c net/socket.c:2344
 __invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
 invoke_syscall+0x98/0x244 arch/arm64/kernel/syscall.c:49
 el0_svc_common+0xec/0x23c arch/arm64/kernel/syscall.c:121
 do_el0_svc+0x4c/0x5c arch/arm64/kernel/syscall.c:140
 el0_svc+0x60/0x1d8 arch/arm64/kernel/entry-common.c:797
 el0t_64_sync_handler+0x44/0x104 arch/arm64/kernel/entry-common.c:816
 el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:606
irq event stamp: 584
hardirqs last  enabled at (583): [<ffff8000804a47b4>] vprintk_store+0x924/0xb94 kernel/printk/printk.c:2385
hardirqs last disabled at (584): [<ffff800086954058>] el1_brk64+0x20/0x54 arch/arm64/kernel/entry-common.c:484
softirqs last  enabled at (552): [<ffff8000800204f4>] __do_softirq+0x14/0x20 kernel/softirq.c:703
softirqs last disabled at (547): [<ffff8000800204f4>] __do_softirq+0x14/0x20 kernel/softirq.c:703
---[ end trace 0000000000000000 ]---

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/12 23:37 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci 18f2d01bfce9 d6166547 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-gce-arm64 WARNING in l2cap_chan_le_send_credits
* Struck through repros no longer work on HEAD.