* [PATCH] Bluetooth: RFCOMM: Fix slab-use-after-free in rfcomm_dev_add()
@ 2026-11-22 9:33 Leicheng Xie via B4 Relay
2026-11-22 17:24 ` bluez.test.bot
0 siblings, 1 reply; 2+ messages in thread
From: Leicheng Xie via B4 Relay @ 2026-11-22 9:33 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz, Gianluca Anzolin
Cc: linux-bluetooth, syzbot+11542ff1d167fdffa1fc, stable,
Leicheng Xie
From: Leicheng Xie <leicheng.dev@gmail.com>
__rfcomm_dev_add() inserts the newly allocated struct rfcomm_dev into
rfcomm_dev_list and releases rfcomm_dev_lock while holding only the
initial tty_port reference. Back in rfcomm_dev_add(), the device is
registered with tty_port_register_device() and further initialized
(dev->tty_dev assignment, reparenting, drvdata, sysfs attributes, and
reading dev->id).
When RFCOMM_RELEASE_ONHUP is set, a concurrent task can open and close
the RFCOMM TTY device as soon as it becomes visible on rfcomm_dev_list.
rfcomm_tty_install() takes over the initial reference by setting
RFCOMM_TTY_OWNED, and rfcomm_tty_cleanup() drops it to zero, freeing
dev via rfcomm_dev_destruct() while rfcomm_dev_add() is still running:
BUG: KASAN: slab-use-after-free in rfcomm_dev_add
Write of size 8 at addr ffff88800e85b3e0 by task rfcomm_uaf_poc/179
Hold an extra tty_port reference in __rfcomm_dev_add() before dropping
rfcomm_dev_lock, and release it at the end of rfcomm_dev_add() after
caching dev->id. On the tty_port_register_device() failure path, use
test_and_set_bit(RFCOMM_TTY_OWNED, &dev->status) before dropping the
initial reference to match __rfcomm_release_dev() and prevent a leak or
double-put if a concurrent open took ownership.
Fixes: 5b899241874d ("Bluetooth: Release RFCOMM port when the last user closes the TTY")
Reported-by: syzbot+11542ff1d167fdffa1fc@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=11542ff1d167fdffa1fc
Cc: stable@vger.kernel.org
Signed-off-by: Leicheng Xie <leicheng.dev@gmail.com>
---
net/bluetooth/rfcomm/tty.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index 198c7dd1a95b..3a61c45b5b51 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -303,6 +303,9 @@ static struct rfcomm_dev *__rfcomm_dev_add(struct rfcomm_dev_req *req,
holds reference to this module. */
__module_get(THIS_MODULE);
+ /* Hold an extra reference for rfcomm_dev_add() until setup completes */
+ tty_port_get(&dev->port);
+
mutex_unlock(&rfcomm_dev_lock);
return dev;
@@ -316,6 +319,7 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
{
struct rfcomm_dev *dev;
struct device *tty;
+ int id;
BT_DBG("id %d channel %d", req->dev_id, req->channel);
@@ -328,6 +332,8 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
tty = tty_port_register_device(&dev->port, rfcomm_tty_driver,
dev->id, NULL);
if (IS_ERR(tty)) {
+ if (!test_and_set_bit(RFCOMM_TTY_OWNED, &dev->status))
+ tty_port_put(&dev->port);
tty_port_put(&dev->port);
return PTR_ERR(tty);
}
@@ -342,7 +348,10 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
if (device_create_file(dev->tty_dev, &dev_attr_channel) < 0)
BT_ERR("Failed to create channel attribute");
- return dev->id;
+ id = dev->id;
+ tty_port_put(&dev->port);
+
+ return id;
}
/* ---- Send buffer ---- */
---
base-commit: 4843f6873f7c4835e62f2c73ba0fd538e57a2f22
change-id: 20261122-fix-rfcomm-dev-add-uaf-cfe483717195
Best regards,
--
Leicheng Xie <leicheng.dev@gmail.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-22 17:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 9:33 [PATCH] Bluetooth: RFCOMM: Fix slab-use-after-free in rfcomm_dev_add() Leicheng Xie via B4 Relay
2026-11-22 17:24 ` bluez.test.bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox