From: Chengfeng Ye <nicoyip.dev@gmail.com>
To: Marcel Holtmann <marcel@holtmann.org>,
Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
Kees Cook <kees@kernel.org>, Chengfeng Ye <nicoyip.dev@gmail.com>,
Jakub Kicinski <kuba@kernel.org>,
Pengpeng Hou <pengpeng@iscas.ac.cn>,
Jiale Yao <yaojiale02@163.com>,
SeungJu Cheon <suunj1331@gmail.com>,
Ali Ahmet Memis <ali@iusegentoo.com>,
Tim Bird <tim.bird@sony.com>
Cc: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org,
Pauli Virtanen <pav@iki.fi>
Subject: [PATCH v2] Bluetooth: RFCOMM: serialize session teardown
Date: Sat, 22 Aug 2026 23:06:19 +0800 [thread overview]
Message-ID: <20260822150619.3684599-1-nicoyip.dev@gmail.com> (raw)
rfcomm_kill_listener() walks session_list and deletes every session
without holding rfcomm_mutex, unlike the normal session processing and
connect error paths.
Under normal operation, an open RFCOMM socket pins rfcomm.ko, so
rfcomm_kill_listener() does not run concurrently with rfcomm_dlc_open().
However, forced module unload via delete_module(O_TRUNC) can stop
krfcommd while a failed connect is still unwinding.
connect task forced unload / krfcommd
------------ ------------------------
rfcomm_lock()
rfcomm_session_add()
delete_module("rfcomm", O_TRUNC)
rfcomm_kill_listener()
fetch session from session_list
kernel_connect() fails
rfcomm_session_del()
remove and free session
rfcomm_session_del(session)
The final call then reads the freed session and may corrupt the list.
KASAN reported with mdelay() to enlarge critical window:
BUG: KASAN: slab-use-after-free in rfcomm_run+0x3802/0x3f00 [rfcomm]
Read of size 8 at addr ffff888111058d40 by task krfcommd/79
Tainted: [R]=FORCED_RMMOD
Allocated by task 86:
rfcomm_session_add+0xa1/0x300 [rfcomm]
rfcomm_dlc_open+0x8b2/0xf30 [rfcomm]
rfcomm_sock_connect+0x34c/0x530 [rfcomm]
Freed by task 86:
kfree+0x121/0x3c0
rfcomm_dlc_open+0xab7/0xf30 [rfcomm]
rfcomm_sock_connect+0x34c/0x530 [rfcomm]
Hold rfcomm_mutex across the teardown traversal so every reachable
session_list walk uses the same serialization.
Reviewed-by: Ali Ahmet Memis <ali@iusegentoo.com>
Tested-by: Ali Ahmet Memis <ali@iusegentoo.com>
Reviewed-by: Pauli Virtanen <pav@iki.fi>
Signed-off-by: Chengfeng Ye <nicoyip.dev@gmail.com>
---
Changes in v2:
- Rewrite the changelog to describe make clear trigger: forced module
unload with delete_module(O_TRUNC) and temporary delay widening.
- Drop the Fixes tag.
- Drop Cc: stable.
- Add Ali Ahmet Memis's Reviewed-by and Tested-by tags.
- Add Pauli Virtanen's Reviewed-by tag.
Link: https://lkml.iu.edu/2608.2/10891.html [v1]
net/bluetooth/rfcomm/core.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index 9cdfea666a2c..5fe2758e8c47 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -2178,8 +2178,10 @@ static void rfcomm_kill_listener(void)
BT_DBG("");
+ rfcomm_lock();
list_for_each_entry_safe(s, n, &session_list, list)
rfcomm_session_del(s);
+ rfcomm_unlock();
}
static int rfcomm_run(void *unused)
--
2.43.0
next reply other threads:[~2026-08-22 15:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-22 15:06 Chengfeng Ye [this message]
2026-08-24 16:50 ` [PATCH v2] Bluetooth: RFCOMM: serialize session teardown patchwork-bot+bluetooth
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=20260822150619.3684599-1-nicoyip.dev@gmail.com \
--to=nicoyip.dev@gmail.com \
--cc=ali@iusegentoo.com \
--cc=kees@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
--cc=pav@iki.fi \
--cc=pengpeng@iscas.ac.cn \
--cc=suunj1331@gmail.com \
--cc=tim.bird@sony.com \
--cc=yaojiale02@163.com \
/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