Bluetooth: L2CAP: Fix use-after-free caused by l2cap_chan_put
Subsystems (2)
Luiz Augusto von Dentz
maintainerPATCH v2 1/1 Bluetooth: L2CAP: Fix use-after-free caused by l2cap_chan_put
From: Luiz Augusto von Dentz <[email protected]>
This fixes the following trace which is caused by hci_rx_work starting up *after* the final channel reference has been put() during sock_close() but *before* the references to the channel have been destroyed, so instead the code now rely on kref_get_unless_zero/l2cap_chan_hold_unless_zero to prevent referencing a channel that is about to be destroyed.
refcount_t: increment on 0; use-after-free.
BUG: KASAN: use-after-free in refcount_dec_and_test+0x20/0xd0 Read of size 4 at addr ffffffc114f5bf18 by task kworker/u17:14/705 CPU: 4 PID: 705 Comm: kworker/u17:14 Tainted: G S W 4.14.234-00003-g1fb6d0bd49a4-dirty #28 Hardware name: Qualcomm Technologies, Inc. SM8150 V2 PM8150 Google Inc. MSM sm8150 Flame DVT (DT) Workqueue: hci0 hci_rx_work Call trace: dump_backtrace+0x0/0x378 show_stack+0x20/0x2c dump_stack+0x124/0x148 print_address_description+0x80/0x2e8 __kasan_report+0x168/0x188 kasan_report+0x10/0x18 __asan_load4+0x84/0x8c refcount_dec_and_test+0x20/0xd0 l2cap_chan_put+0x48/0x12c l2cap_recv_frame+0x4770/0x6550 l2cap_recv_acldata+0x44c/0x7a4 hci_acldata_packet+0x100/0x188 hci_rx_work+0x178/0x23c process_one_work+0x35c/0x95c worker_thread+0x4cc/0x960 kthread+0x1a8/0x1c4 ret_from_fork+0x10/0x18
--- include/net/bluetooth/l2cap.h | 1 + net/bluetooth/l2cap_core.c | 61 +++++++++++++++++++++++++++-------- 2 files changed, 49 insertions(+), 13 deletions(-)
include/net/bluetooth/l2cap.h +1 -0
@@ -847,6 +847,7 @@ enum { };void l2cap_chan_hold (struct l2cap_chan *c); +struct l2cap_chan *l2cap_chan_hold_unless_zero (struct l2cap_chan *c);void l2cap_chan_put (struct l2cap_chan *c);static inline void l2cap_chan_lock (struct l2cap_chan *chan)
net/bluetooth/l2cap_core.c +48 -13
180 lines not on this page · raw message
Signature · 1 line
2.36.1
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/project/bluetooth/list/?series=661930
---Test result---
Test Summary:
CheckPatch PASS 2.01 seconds GitLint PASS 0.96 seconds SubjectPrefix PASS 0.80 seconds BuildKernel PASS 34.13 seconds BuildKernel32 PASS 29.84 seconds Incremental Build with patchesPASS 48.38 seconds TestRunner: Setup PASS 532.15 seconds TestRunner: l2cap-tester PASS 17.50 seconds TestRunner: bnep-tester PASS 6.00 seconds TestRunner: mgmt-tester PASS 100.59 seconds TestRunner: rfcomm-tester PASS 9.52 seconds TestRunner: sco-tester PASS 9.29 seconds TestRunner: smp-tester PASS 9.28 seconds TestRunner: userchan-tester PASS 6.13 seconds
---
Regards,
Linux Bluetooth
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 9 lines · On Thu, 21 Jul 2022 09:10:50 -0700 you wrote:
From: Luiz Augusto von Dentz <[email protected]>
This fixes the following trace which is caused by
hci_rx_workstarting up *after* the final channel reference has beenput()duringsock_close()but *before* the references to the channel have been destroyed, so instead the code now rely on kref_get_unless_zero/l2cap_chan_hold_unless_zero to prevent referencing a channel that is about to be destroyed.[...]
Here is the summary with links:
- [v2] Bluetooth: L2CAP: Fix use-after-free caused by l2cap_chan_put
https://git.kernel.org/bluetooth/bluetooth-next/c/d0be8347c623
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html