All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: af_bluetooth: hold a reference on parent in accept_q
@ 2026-09-16 15:38 Nguyen Ngoc Thang
  2026-09-16 17:11 ` Pauli Virtanen
  2026-09-16 19:21 ` bluez.test.bot
  0 siblings, 2 replies; 3+ messages in thread
From: Nguyen Ngoc Thang @ 2026-09-16 15:38 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz, linux-bluetooth
  Cc: Nguyen Ngoc Thang, linux-kernel, syzbot+534002670dd34a114fdc,
	syzkaller-bugs

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.

Take a reference on parent in bt_accept_enqueue() and drop it in
bt_accept_unlink() to keep it alive for as long as a child points to
it.

Reported-by: syzbot+534002670dd34a114fdc@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=534002670dd34a114fdc
Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
---
 net/bluetooth/af_bluetooth.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 411d66f24393..f9aae18c6733 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);
@@ -265,6 +269,7 @@ void bt_accept_unlink(struct sock *sk)
 	sk_acceptq_removed(parent);
 	spin_unlock_bh(&bt_sk(parent)->accept_q_lock);
 	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: [PATCH] Bluetooth: af_bluetooth: hold a reference on parent in accept_q
  2026-09-16 15:38 [PATCH] Bluetooth: af_bluetooth: hold a reference on parent in accept_q Nguyen Ngoc Thang
@ 2026-09-16 17:11 ` Pauli Virtanen
  2026-09-16 19:21 ` bluez.test.bot
  1 sibling, 0 replies; 3+ messages in thread
From: Pauli Virtanen @ 2026-09-16 17:11 UTC (permalink / raw)
  To: Nguyen Ngoc Thang, Marcel Holtmann, Luiz Augusto von Dentz,
	linux-bluetooth
  Cc: linux-kernel, syzbot+534002670dd34a114fdc, syzkaller-bugs

Hi,

ke, 2026-09-16 kello 22:38 +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.
>
> Take a reference on parent in bt_accept_enqueue() and drop it in
> bt_accept_unlink() to keep it alive for as long as a child points to
> it.

AFAIK the UAF described above cannot occur in current kernel:

https://lore.kernel.org/linux-bluetooth/3674f5d34d731403bfa0e680c9e5718237612315.camel@iki.fi/

> Reported-by: syzbot+534002670dd34a114fdc@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=534002670dd34a114fdc
> Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
> ---
>  net/bluetooth/af_bluetooth.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
> index 411d66f24393..f9aae18c6733 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);
> @@ -265,6 +269,7 @@ void bt_accept_unlink(struct sock *sk)
>  	sk_acceptq_removed(parent);
>  	spin_unlock_bh(&bt_sk(parent)->accept_q_lock);
>  	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

* RE: Bluetooth: af_bluetooth: hold a reference on parent in accept_q
  2026-09-16 15:38 [PATCH] Bluetooth: af_bluetooth: hold a reference on parent in accept_q Nguyen Ngoc Thang
  2026-09-16 17:11 ` Pauli Virtanen
@ 2026-09-16 19:21 ` bluez.test.bot
  1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2026-09-16 19:21 UTC (permalink / raw)
  To: linux-bluetooth, ngocthang2710.1999

[-- Attachment #1: Type: text/plain, Size: 2953 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/1166624/

---Test result---

Test Summary:
CheckPatch                    FAIL      0.59 seconds
VerifyFixes                   PASS      0.08 seconds
VerifySignedoff               PASS      0.08 seconds
GitLint                       PASS      0.25 seconds
SubjectPrefix                 PASS      0.07 seconds
BuildKernel                   PASS      27.59 seconds
CheckAllWarning               PASS      31.90 seconds
CheckSparse                   PASS      34.81 seconds
BuildKernel32                 PASS      27.84 seconds
CheckKernelLLVM               PASS      32.91 seconds
TestRunnerSetup               PASS      791.67 seconds
TestRunner_l2cap-tester       PASS      16.44 seconds
TestRunner_iso-tester         PASS      26.73 seconds
TestRunner_bnep-tester        PASS      3.10 seconds
TestRunner_mgmt-tester        FAIL      60.50 seconds
TestRunner_rfcomm-tester      PASS      10.18 seconds
TestRunner_sco-tester         PASS      7.60 seconds
TestRunner_ioctl-tester       PASS      4.89 seconds
TestRunner_mesh-tester        FAIL      7.80 seconds
TestRunner_smp-tester         PASS      4.39 seconds
TestRunner_userchan-tester    PASS      3.26 seconds
TestRunner_6lowpan-tester     PASS      4.46 seconds
IncrementalBuild              PASS      28.78 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
Bluetooth: af_bluetooth: hold a reference on parent in accept_q
WARNING: The commit message has 'syzkaller', perhaps it also needs a 'Fixes:' tag?

total: 0 errors, 1 warnings, 0 checks, 17 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

/home/runner/work/bluetooth-next/bluetooth-next/src/patch/14822720.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.


##############################
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.019 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.448 seconds
Mesh - Send cancel - 2                               Timed out    1.999 seconds


https://github.com/bluez/bluetooth-next/pull/783

---
Regards,
Linux Bluetooth


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

end of thread, other threads:[~2026-09-16 19:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-16 15:38 [PATCH] Bluetooth: af_bluetooth: hold a reference on parent in accept_q Nguyen Ngoc Thang
2026-09-16 17:11 ` Pauli Virtanen
2026-09-16 19:21 ` bluez.test.bot

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.