* [PATCH v3] Bluetooth: af_bluetooth: Fix double list_del and UAF in accept_q
@ 2026-09-18 10:47 Nguyen Ngoc Thang
2026-09-18 14:47 ` [v3] " bluez.test.bot
2026-09-18 15:34 ` [PATCH v3] " Pauli Virtanen
0 siblings, 2 replies; 3+ messages in thread
From: Nguyen Ngoc Thang @ 2026-09-18 10:47 UTC (permalink / raw)
To: linux-bluetooth
Cc: linux-kernel, marcel, luiz.dentz, syzbot+534002670dd34a114fdc,
syzkaller-bugs, Nguyen Ngoc Thang
bt_sk(sk)->parent is a raw pointer with no refcount backing it, so a
child sitting in the listening socket's accept_q can outlive it. When
the child's channel is torn down independently (e.g. hci_error_reset()
-> l2cap_conn_del() -> l2cap_sock_teardown_cb()), bt_accept_unlink()
dereferences the freed parent, corrupting its accept_q_lock and list.
Additionally, if multiple threads concurrently tear down the child
socket, bt_accept_unlink() can be called multiple times. Without
checking if the socket is still in the list, the second thread will
perform a double list_del_init(), causing list_del corruption (kernel BUG).
Fix this by:
1. Taking a reference on parent in bt_accept_enqueue() and dropping it
only when actually unlinked in bt_accept_unlink().
2. Checking !list_empty(&bt_sk(sk)->accept_q) inside the accept_q_lock
to prevent double unlinking.
3. Moving sock_put() outside of the spinlock to avoid sleeping in an
atomic context.
Reported-by: syzbot+534002670dd34a114fdc@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=534002670dd34a114fdc
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
---
net/bluetooth/af_bluetooth.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 411d66f24393..7797b1052808 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -224,6 +224,10 @@ void bt_accept_enqueue(struct sock *parent, struct sock *sk, bool bh)
else
lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
+ /* Hold a reference on parent so it cannot be freed while sk keeps
+ * a raw pointer to it via bt_sk(sk)->parent.
+ */
+ sock_hold(parent);
bt_sk(sk)->parent = parent;
spin_lock_bh(&par->accept_q_lock);
@@ -257,15 +261,24 @@ EXPORT_SYMBOL(bt_accept_enqueue);
void bt_accept_unlink(struct sock *sk)
{
struct sock *parent = bt_sk(sk)->parent;
+ bool unlinked = false;
- BT_DBG("sk %p state %d", sk, sk->sk_state);
+ if (!parent)
+ return;
spin_lock_bh(&bt_sk(parent)->accept_q_lock);
- list_del_init(&bt_sk(sk)->accept_q);
- sk_acceptq_removed(parent);
+ if (!list_empty(&bt_sk(sk)->accept_q)) {
+ list_del_init(&bt_sk(sk)->accept_q);
+ sk_acceptq_removed(parent);
+ unlinked = true;
+ }
spin_unlock_bh(&bt_sk(parent)->accept_q_lock);
- bt_sk(sk)->parent = NULL;
- sock_put(sk);
+
+ if (unlinked) {
+ bt_sk(sk)->parent = NULL;
+ sock_put(parent);
+ sock_put(sk);
+ }
}
EXPORT_SYMBOL(bt_accept_unlink);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [v3] Bluetooth: af_bluetooth: Fix double list_del and UAF in accept_q
2026-09-18 10:47 [PATCH v3] Bluetooth: af_bluetooth: Fix double list_del and UAF in accept_q Nguyen Ngoc Thang
@ 2026-09-18 14:47 ` bluez.test.bot
2026-09-18 15:34 ` [PATCH v3] " Pauli Virtanen
1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2026-09-18 14:47 UTC (permalink / raw)
To: linux-bluetooth, ngocthang2710.1999
[-- Attachment #1: Type: text/plain, Size: 2227 bytes --]
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1168560/
---Test result---
Test Summary:
CheckPatch PASS 0.60 seconds
VerifyFixes PASS 0.10 seconds
VerifySignedoff PASS 0.10 seconds
GitLint PASS 0.29 seconds
SubjectPrefix PASS 0.09 seconds
BuildKernel PASS 29.00 seconds
CheckAllWarning PASS 31.93 seconds
CheckSparse PASS 34.15 seconds
BuildKernel32 PASS 27.88 seconds
CheckKernelLLVM PASS 31.52 seconds
TestRunnerSetup PASS 704.03 seconds
TestRunner_l2cap-tester PASS 16.11 seconds
TestRunner_iso-tester PASS 36.46 seconds
TestRunner_bnep-tester PASS 3.76 seconds
TestRunner_mgmt-tester FAIL 60.00 seconds
TestRunner_rfcomm-tester PASS 4.17 seconds
TestRunner_sco-tester PASS 11.49 seconds
TestRunner_ioctl-tester PASS 5.29 seconds
TestRunner_mesh-tester FAIL 8.91 seconds
TestRunner_smp-tester PASS 4.07 seconds
TestRunner_userchan-tester PASS 2.94 seconds
TestRunner_6lowpan-tester PASS 4.13 seconds
IncrementalBuild PASS 30.91 seconds
Details
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 501, Passed: 496 (99.0%), Failed: 1, Not Run: 4
Failed Test Cases
Read Exp Feature - Success Failed 0.022 seconds
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner
Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0
Failed Test Cases
Mesh - Send cancel - 1 Timed out 2.523 seconds
Mesh - Send cancel - 2 Timed out 1.997 seconds
https://github.com/bluez/bluetooth-next/pull/790
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] Bluetooth: af_bluetooth: Fix double list_del and UAF in accept_q
2026-09-18 10:47 [PATCH v3] Bluetooth: af_bluetooth: Fix double list_del and UAF in accept_q Nguyen Ngoc Thang
2026-09-18 14:47 ` [v3] " bluez.test.bot
@ 2026-09-18 15:34 ` Pauli Virtanen
1 sibling, 0 replies; 3+ messages in thread
From: Pauli Virtanen @ 2026-09-18 15:34 UTC (permalink / raw)
To: Nguyen Ngoc Thang, linux-bluetooth
Cc: linux-kernel, marcel, luiz.dentz, syzbot+534002670dd34a114fdc,
syzkaller-bugs
Hi,
pe, 2026-09-18 kello 17:47 +0700, Nguyen Ngoc Thang kirjoitti:
> bt_sk(sk)->parent is a raw pointer with no refcount backing it, so a
> child sitting in the listening socket's accept_q can outlive it. When
> the child's channel is torn down independently (e.g. hci_error_reset()
> -> l2cap_conn_del() -> l2cap_sock_teardown_cb()), bt_accept_unlink()
> dereferences the freed parent, corrupting its accept_q_lock and list.
This was resent without replying to previous comments:
https://lore.kernel.org/linux-bluetooth/1baff112d1ebd255575c7e52936b13db10f218b7.camel@iki.fi/
AFAIK the issue is already fixed upstream in a different way.
> Additionally, if multiple threads concurrently tear down the child
> socket, bt_accept_unlink() can be called multiple times. Without
> checking if the socket is still in the list, the second thread will
> perform a double list_del_init(), causing list_del corruption (kernel BUG).
>
> Fix this by:
> 1. Taking a reference on parent in bt_accept_enqueue() and dropping it
> only when actually unlinked in bt_accept_unlink().
> 2. Checking !list_empty(&bt_sk(sk)->accept_q) inside the accept_q_lock
> to prevent double unlinking.
> 3. Moving sock_put() outside of the spinlock to avoid sleeping in an
> atomic context.
These don't look right: eg. sock_put() was not inside spinlock even
before.
> Reported-by: syzbot+534002670dd34a114fdc@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=534002670dd34a114fdc
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
>
> Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
> ---
> net/bluetooth/af_bluetooth.c | 23 ++++++++++++++++++-----
> 1 file changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
> index 411d66f24393..7797b1052808 100644
> --- a/net/bluetooth/af_bluetooth.c
> +++ b/net/bluetooth/af_bluetooth.c
> @@ -224,6 +224,10 @@ void bt_accept_enqueue(struct sock *parent, struct sock *sk, bool bh)
> else
> lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
>
> + /* Hold a reference on parent so it cannot be freed while sk keeps
> + * a raw pointer to it via bt_sk(sk)->parent.
> + */
> + sock_hold(parent);
> bt_sk(sk)->parent = parent;
>
> spin_lock_bh(&par->accept_q_lock);
> @@ -257,15 +261,24 @@ EXPORT_SYMBOL(bt_accept_enqueue);
> void bt_accept_unlink(struct sock *sk)
> {
> struct sock *parent = bt_sk(sk)->parent;
> + bool unlinked = false;
>
> - BT_DBG("sk %p state %d", sk, sk->sk_state);
> + if (!parent)
> + return;
>
> spin_lock_bh(&bt_sk(parent)->accept_q_lock);
> - list_del_init(&bt_sk(sk)->accept_q);
> - sk_acceptq_removed(parent);
> + if (!list_empty(&bt_sk(sk)->accept_q)) {
> + list_del_init(&bt_sk(sk)->accept_q);
> + sk_acceptq_removed(parent);
> + unlinked = true;
> + }
> spin_unlock_bh(&bt_sk(parent)->accept_q_lock);
> - bt_sk(sk)->parent = NULL;
> - sock_put(sk);
> +
> + if (unlinked) {
> + bt_sk(sk)->parent = NULL;
> + sock_put(parent);
> + sock_put(sk);
> + }
> }
> EXPORT_SYMBOL(bt_accept_unlink);
>
--
Pauli Virtanen
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-18 15:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-18 10:47 [PATCH v3] Bluetooth: af_bluetooth: Fix double list_del and UAF in accept_q Nguyen Ngoc Thang
2026-09-18 14:47 ` [v3] " bluez.test.bot
2026-09-18 15:34 ` [PATCH v3] " Pauli Virtanen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.