mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: XIAO WU <xiaowu.417@qq.com>
To: Alva Lan <alvalan9@foxmail.com>,
	gregkh@linuxfoundation.org, sashal@kernel.org,
	stable@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Pauli Virtanen <pav@iki.fi>,
	Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Subject: Re: [PATCH 6.6.y] Bluetooth: hci_conn: fix potential UAF in set_cig_params_sync
Date: Sun, 21 Jun 2026 09:57:51 +0800	[thread overview]
Message-ID: <tencent_D72AF901D90EB103AEB5111845A7AC8FF705@qq.com> (raw)
In-Reply-To: <tencent_42D87A0C871AE6AF019BF6AB46F003577205@qq.com>

Hi,

I came across a Sashiko AI code review [1] that flagged a related
use-after-free in `get_l2cap_conn()` — it has the same lock-dropping
pattern that your patch fixes in `set_cig_params_sync()`.

I was able to trigger it in QEMU with KASAN on a 6.6.y kernel. Writing
to the 6lowpan debugfs control file races against connection teardown.

On Sun, Jun 8, 2026 at 5:56:55PM +0300, Pauli Virtanen wrote:
 > This commit adds hci_dev_lock() around the hci_conn lookup and field
 > accesses in set_cig_params_sync(). This prevents a potential
 > use-after-free if the connection is concurrently freed.

The same pattern in `get_l2cap_conn()` still drops the lock before
accessing the returned hcon pointer:

```c
// net/bluetooth/6lowpan.c: get_l2cap_conn()
hci_dev_lock(hdev);
hcon = hci_conn_hash_lookup_le(hdev, addr, le_addr_type);
hci_dev_unlock(hdev);                  // lock dropped
hci_dev_put(hdev);

if (!hcon)
     return -ENOENT;

*conn = (struct l2cap_conn *)hcon->l2cap_data;  // UAF if freed
```

The connection is returned without a reference count.  If a concurrent
disconnect event frees it via `hci_conn_del()`, the subsequent
dereference of `hcon->l2cap_data` hits freed memory.

[KASAN report — kernel 6.6.142, CONFIG_KASAN=y]

   ==================================================================
   BUG: KASAN: slab-use-after-free in get_l2cap_conn.constprop.0+0x73f/0x750
   Read of size 8 at addr ffff888106514ab8 by task poc/9349

   CPU: 1 PID: 9349 Comm: poc Not tainted 6.6.142-g1ab6d2b45d08 #1

   Call Trace:
    <TASK>
    dump_stack_lvl+0xd9/0x1b0
    print_report+0xce/0x630
    kasan_report+0xd4/0x110
    get_l2cap_conn.constprop.0+0x73f/0x750
    lowpan_control_write+0x574/0x740
    full_proxy_write+0x12f/0x1a0
    vfs_write+0x2ba/0xe60
    ksys_write+0x134/0x260
    do_syscall_64+0x39/0xc0
    entry_SYSCALL_64_after_hwframe+0x79/0xe3

   Allocated by task 56:
    __hci_conn_add+0x136/0x1ac0
    hci_conn_add_unset+0x72/0x100
    le_conn_complete_evt+0x667/0x2180
    hci_le_conn_complete_evt+0x241/0x370

   Freed by task 56:
    __kmem_cache_free+0xb6/0x2e0
    hci_conn_del+0x.../...

[1] 
https://sashiko.dev/#/patchset/tencent_42D87A0C871AE6AF019BF6AB46F003577205%40qq.com
     (Sashiko AI code review — "Use-After-Free", Severity: High)

Thanks,
XIAO



  parent reply	other threads:[~2026-06-21  1:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-08  9:56 Alva Lan
2026-06-09  0:51 ` Sasha Levin
2026-06-21  1:57 ` XIAO WU [this message]
2026-06-21  5:38   ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_D72AF901D90EB103AEB5111845A7AC8FF705@qq.com \
    --to=xiaowu.417@qq.com \
    --cc=alvalan9@foxmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luiz.von.dentz@intel.com \
    --cc=pav@iki.fi \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome