From: Hyunwoo Kim <imv4bel@gmail.com>
To: marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com
Cc: linux-bluetooth@vger.kernel.org, imv4bel@gmail.com
Subject: [PATCH] Bluetooth: SCO: Fix use-after-free in sco_conn_ready() due to missing sock_hold
Date: Fri, 20 Mar 2026 00:12:45 +0900 [thread overview]
Message-ID: <abwSbezp8_z0K_eY@v4bel> (raw)
sco_get_sock_listen() returns a pointer to a listening socket without
incrementing its reference count. If the listening socket is concurrently
closed and freed before sco_conn_ready() calls lock_sock(parent), a
use-after-free occurs. The listening socket has no sco_conn association
(sco_pi(sk)->conn == NULL), so sco_conn_lock does not prevent it.
Fix by adding sock_hold()/sock_put() in sco_get_sock_listen() following
the iso_get_sock() pattern.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
---
net/bluetooth/sco.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index e7db50165879..7ad6d9208de5 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -449,14 +449,23 @@ static struct sock *sco_get_sock_listen(bdaddr_t *src)
continue;
/* Exact match. */
- if (!bacmp(&sco_pi(sk)->src, src))
+ if (!bacmp(&sco_pi(sk)->src, src)) {
+ sock_hold(sk);
break;
+ }
/* Closest match */
- if (!bacmp(&sco_pi(sk)->src, BDADDR_ANY))
+ if (!bacmp(&sco_pi(sk)->src, BDADDR_ANY)) {
+ if (sk1)
+ sock_put(sk1);
sk1 = sk;
+ sock_hold(sk1);
+ }
}
+ if (sk && sk1)
+ sock_put(sk1);
+
read_unlock(&sco_sk_list.lock);
return sk ? sk : sk1;
@@ -1376,6 +1385,7 @@ static void sco_conn_ready(struct sco_conn *conn)
if (!sk) {
release_sock(parent);
sco_conn_unlock(conn);
+ sock_put(parent);
return;
}
@@ -1399,6 +1409,7 @@ static void sco_conn_ready(struct sco_conn *conn)
release_sock(parent);
sco_conn_unlock(conn);
+ sock_put(parent);
}
}
--
2.43.0
next reply other threads:[~2026-03-19 15:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-19 15:12 Hyunwoo Kim [this message]
2026-03-19 16:37 ` Bluetooth: SCO: Fix use-after-free in sco_conn_ready() due to missing sock_hold bluez.test.bot
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=abwSbezp8_z0K_eY@v4bel \
--to=imv4bel@gmail.com \
--cc=johan.hedberg@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
/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