LKML Archive on
help / color / mirror / Atom feed
From: Desmond Cheong Zhi Xi <>
Cc: Desmond Cheong Zhi Xi <>,,,,
Subject: [PATCH 1/2] Bluetooth: call sock_hold earlier in sco_conn_del
Date: Thu,  2 Sep 2021 23:13:05 -0400	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

In sco_conn_del, conn->sk is read while holding on to the
sco_conn.lock to avoid races with a socket that could be released

However, in between unlocking sco_conn.lock and calling sock_hold,
it's possible for the socket to be freed, which would cause a
use-after-free write when sock_hold is finally called.

To fix this, the reference count of the socket should be increased
while the sco_conn.lock is still held.

Signed-off-by: Desmond Cheong Zhi Xi <>
 net/bluetooth/sco.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index b62c91c627e2..4a057f99b60a 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -187,10 +187,11 @@ static void sco_conn_del(struct hci_conn *hcon, int err)
 	/* Kill socket */
 	sk = conn->sk;
+	if (sk)
+		sock_hold(sk);
 	if (sk) {
-		sock_hold(sk);
 		sco_chan_del(sk, err);

  reply	other threads:[~2021-09-03  3:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-03  3:13 [PATCH 0/2] Bluetooth: various SCO fixes Desmond Cheong Zhi Xi
2021-09-03  3:13 ` Desmond Cheong Zhi Xi [this message]
2021-09-10  7:36   ` [PATCH 1/2] Bluetooth: call sock_hold earlier in sco_conn_del Marcel Holtmann
2021-10-04 18:12     ` Desmond Cheong Zhi Xi
2021-09-03  3:13 ` [PATCH 2/2] Bluetooth: fix init and cleanup of sco_conn.timeout_work Desmond Cheong Zhi Xi
2021-09-03 23:37 ` [PATCH 0/2] Bluetooth: various SCO fixes Luiz Augusto von Dentz

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \ \ \
    --subject='Re: [PATCH 1/2] Bluetooth: call sock_hold earlier in sco_conn_del' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).