From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796012362; b=MlNdxRTgsRN6BYpvNLY4mWobbGjoLTulND584InXxAYI1lVn1UlT1LSlPbh1qXURV53A HlBlDUM/1gPLyLVz9wRU6/Qb0fKlgA9AsjRdN5lK/m7QyW9turCsFXGmhWv9pw/8vgJPZ DTnPsnzxZx0cPHDh1n442Jg3d1zoVvWx1tPWvLsrFYFPBxE/Vym6KIeJT/Rq92YELbG+1 EEsHgvmCNjTPZHF5djvyDDvMsHqCqA9Ik7gzCfzodvxBwe6EV90Bdz3fliLle1ggB2duP ebndXRFkF+HydN7r/NEKRYclDGaHZZEJWLs67GfhKYEyXewjRT/fSlqC6wzMp0ylZtQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796012362; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=sYXttp5IHiAYnW11ypM02EEaWDWeTG7LOMGX4FtIjME=; b=R9t/UF6TKQ58faVrhqJZBe6BNuyxtKqwRcs769v994h2wV0fV+Qi5vuw9Fz/rhNqUtOP qa2GTF+tmIW7vQriTpMmDuy5RA5asBm8RCARQXOZMq2OmVN+E5qtZMBNtzpL38oOiR4cg jknowPg2S0gURIYdYK4vXxd/4NsLS8Po86KvD2R67S/3kq9VArCE/7wEAnFD9ebdLqmzo iZa1CL8SJFVEC6f1wKjffogCEVEdiLh6hrli2KmBm2m/Dr1qECYzVjT1Bl7lbARn1+zOP d5etsSkEiqb/CeJED1S3HoUPsEIkoXdORfm414rl9CNSeLI2lcGiXvpsrVH17Y4OY3w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Q2cTSS56; arc=none smtp.remote-ip=209.85.215.177 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CC78606A31C for ; Mon, 30 Nov 2026 04:19:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6CC78606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Q2cTSS56 Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-cdeaea71717so222016a12.1 for ; Sun, 29 Nov 2026 20:19:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796012362; x=1796617162; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=sYXttp5IHiAYnW11ypM02EEaWDWeTG7LOMGX4FtIjME=; b=Q2cTSS56q6Iy1EP0CMHGNVtGyWxAZTV1xxt3t44sFQp5iye33m9bEFx9lOZx0I5mHE fNNGzDzQHVHG5rye/Ebgmu1e7/PfZg8GgUI+3cB0dXgeoFQpyEKus+MYT49ZTOnJeSB4 RMHkM6xaiRCG+ZytAeC11/j8fJgsySZaAmmtp1OVDKULhisEYtDZf/3xlgi/5pCMFrF1 hYyZDiy0Upd4Vju6kteo38Udry0eBhPjArFMuomBSSj4za7ZumUJbuEr7WHrpcJD/YiZ h1Wu+j54GHlMVI2UJ7UsHUAwfWxuK18tBYiRhhqYcfinEyJSI0s9VYfdk1fWp7CIGLcl QXqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796012362; x=1796617162; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=sYXttp5IHiAYnW11ypM02EEaWDWeTG7LOMGX4FtIjME=; b=J3s2Kf5gp/3v5hJCgPy3XgL554lnUtvL01eg3e/j5THccb4Ja2G0MMFtoX6Gu/IPFv wBZ7fV5R91qNNrndbh2TN5K+JU3wl48XNBF/wZa/4al40MiKvqaliiYdLsONg5f5K9A7 9V/DHTBtVErBP5s2pZxzMHWbTSNdM1bwcJ58sdtMDHmIRFs6xPXeUAIo9omr9eK7OyG7 KDW9rRPianfIWBFowWw8bIgv45b7lQalB/yu+5kALdLii9UWObEn8qbyWJqhgTNpK3+o OxxgSEeOiqcjmr1f7tcCdoq7uORAk9fTyP2Fdx675dZDHWzHHFDB94E9UiJs+Bs61Jho 7TlQ== X-Gm-Message-State: APuU4Z/A029f3YHRfPeSTMfb73TGB3YO6cEpQ/Jnm8mkbSRH2aeR66yH b7Gli69f1lD2FsAYYn3tr9QNKFOTCVrhzSfH7Ni9HcSPBvwE21OatZ9YJtn2ffCQtp2x6A== X-Gm-Gg: AZFdTZdGQ6WPx5GrxoEIqdkTscb0j//m2OJsOpFk9OUm/trwyekeoaqQN8Y9Kc5brXc BZ3G3NQDlV2gLdcQKzXYBXf10Y54yXUdMgY9SZe39HGDNDEr3UQIaeqPPR49CMfKPyrlSSMznR2 EhcHPVl4qdbPT2k0HI7lz3tWaAh0x/qU6XDzxaJ+hmkFVpQ+UREYFD3sskZJ8v2oCaSTab7lS0c 0QuDBRih07J/l30bhGXIe1VOAFeDBIcwZ/A7gHUyrVYG7qjRWbykE+N3M0WDTwx+oLX+QMTQq9G wPhMIPq5CUB4jwr8pnF96hZflrAmrjirUW7EuVZaKOOkTvVoQ0oy//eKVNuuVnQMuxAGkYehu87 W+pjXq0P+jnQR/e3nIahhTt1vod/G4yQUnyFIygsv05j2zUcc9IaqvJEyOyn4P3h0g/61j3jQvl T1zoBE40Hdu3L4oOyhFXto6HducvVwfwokDG9akdVwiwnUpNRffHy+GnjWfCsawGHnVTHhcUH3A Y7GFB64FrLxYBui1KXcbaEKeiGNI+KZxwGw5bLUF1BD9GDcBfGKMaxfhljuX/eRFLyBaWvqOnVG ZquYeSzFDyqvlMAgXGCx98N5DE1o+22lMKYpXOy8RJqm4OoABq4= X-Received: by 2002:a17:903:298c:b0:2ed:4b23:c41b with SMTP id d9443c01a7336-2f03f151d00mr511560125ad.3.1796012361709; Sun, 29 Nov 2026 20:19:21 -0800 (PST) Received: from security.datascience.hku.hk ([175.159.181.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f03f105b76sm159432355ad.50.2026.11.29.20.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 20:19:21 -0800 (PST) From: Yu Junzhe To: stable@vger.kernel.org Cc: Yu Junzhe , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , linux-bluetooth@vger.kernel.org, Greg Kroah-Hartman , Sasha Levin , syzbot+d32d77220b92eddd89ad@syzkaller.appspotmail.com, Pauli Virtanen , Luiz Augusto von Dentz Subject: [PATCH 6.12.y v2] Bluetooth: hci_core: lookup hci_conn on RX path on protocol side Date: Mon, 30 Nov 2026 04:19:14 +0000 Message-ID: <20261130041916.132-1-junzheyu1@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <2026112622-galley-skipping-e8a2@gregkh> References: <20261118123533.25-1-junzheyu1@gmail.com> <20261119035758.45-1-junzheyu1@gmail.com> <2026-11-19-1-daily-reply-0012@kernel.org> <20261126075554.106-1-junzheyu1@gmail.com> <2026112622-galley-skipping-e8a2@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Pauli Virtanen commit 79a2d4678ba90bdba577dc3af88cc900d6dcd5ee upstream. The hdev lock/lookup/unlock/use pattern in the packet RX path doesn't ensure hci_conn* is not concurrently modified/deleted. This locking appears to be leftover from before conn_hash started using RCU commit bf4c63252490b ("Bluetooth: convert conn hash to RCU") and not clear if it had purpose since then. Currently, there are code paths that delete hci_conn* from elsewhere than the ordered hdev->workqueue where the RX work runs in. E.g. commit 5af1f84ed13a ("Bluetooth: hci_sync: Fix UAF on hci_abort_conn_sync") introduced some of these, and there probably were a few others before it. It's better to do the locking so that even if these run concurrently no UAF is possible. Move the lookup of hci_conn and associated socket-specific conn to protocol recv handlers, and do them within a single critical section to cover hci_conn* usage and lookup. syzkaller has reported a crash that appears to be this issue: [Task hdev->workqueue] [Task 2] hci_disconnect_all_sync l2cap_recv_acldata(hcon) hci_conn_get(hcon) hci_abort_conn_sync(hcon) hci_dev_lock hci_dev_lock hci_conn_del(hcon) v-------------------------------- hci_dev_unlock hci_conn_put(hcon) conn = hcon->l2cap_data (UAF) Fixes: 5af1f84ed13a ("Bluetooth: hci_sync: Fix UAF on hci_abort_conn_sync") Reported-by: syzbot+d32d77220b92eddd89ad@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=d32d77220b92eddd89ad Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz Cc: stable@vger.kernel.org # 6.12.y Signed-off-by: Yu Junzhe --- v2: standalone linux-6.12.y backport. Subject and changelog match 79a2d4678ba9. This tree has l2cap_conn_hold_unless_zero() and iso_conn_hold_unless_zero(). sco_conn has no kref, so the SCO path is unchanged. include/net/bluetooth/hci_core.h | 11 +++++---- net/bluetooth/hci_core.c | 49 +++++++++++++--------------------------- net/bluetooth/iso.c | 30 ++++++++++++++++++++---- net/bluetooth/l2cap_core.c | 23 +++++++++++++++---- 4 files changed, 66 insertions(+), 47 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index f846865db..22ac4870a 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -843,7 +843,8 @@ extern struct mutex hci_cb_list_lock; /* ----- HCI interface to upper protocols ----- */ int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr); int l2cap_disconn_ind(struct hci_conn *hcon); -void l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags); +int l2cap_recv_acldata(struct hci_dev *hdev, u16 handle, struct sk_buff *skb, + u16 flags); #if IS_ENABLED(CONFIG_BT_BREDR) int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags); @@ -862,16 +863,18 @@ static inline void sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb) #if IS_ENABLED(CONFIG_BT_LE) int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags); -void iso_recv(struct hci_conn *hcon, struct sk_buff *skb, u16 flags); +int iso_recv(struct hci_dev *hdev, u16 handle, struct sk_buff *skb, u16 flags); #else static inline int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags) { return 0; } -static inline void iso_recv(struct hci_conn *hcon, struct sk_buff *skb, - u16 flags) +static inline int iso_recv(struct hci_dev *hdev, u16 handle, + struct sk_buff *skb, u16 flags) { + kfree_skb(skb); + return -ENOENT; } #endif diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 3a713084f..fe2900960 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -3865,13 +3865,14 @@ static void hci_tx_work(struct work_struct *work) static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) { struct hci_acl_hdr *hdr; - struct hci_conn *conn; __u16 handle, flags; + int err; hdr = skb_pull_data(skb, sizeof(*hdr)); if (!hdr) { bt_dev_err(hdev, "ACL packet too small"); - goto drop; + kfree_skb(skb); + return; } handle = __le16_to_cpu(hdr->handle); @@ -3883,23 +3884,13 @@ static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) hdev->stat.acl_rx++; - hci_dev_lock(hdev); - conn = hci_conn_hash_lookup_handle(hdev, handle); - hci_dev_unlock(hdev); - - if (conn) { - hci_conn_enter_active_mode(conn, BT_POWER_FORCE_ACTIVE_OFF); - - /* Send to upper protocol */ - l2cap_recv_acldata(conn, skb, flags); - return; - } else { + err = l2cap_recv_acldata(hdev, handle, skb, flags); + if (err == -ENOENT) bt_dev_err(hdev, "ACL packet for unknown connection handle %d", handle); - } - -drop: - kfree_skb(skb); + else if (err) + bt_dev_dbg(hdev, "ACL packet recv for handle %d failed: %d", + handle, err); } /* SCO data packet */ @@ -3940,13 +3931,14 @@ static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb) static void hci_isodata_packet(struct hci_dev *hdev, struct sk_buff *skb) { struct hci_iso_hdr *hdr; - struct hci_conn *conn; __u16 handle, flags; + int err; hdr = skb_pull_data(skb, sizeof(*hdr)); if (!hdr) { bt_dev_err(hdev, "ISO packet too small"); - goto drop; + kfree_skb(skb); + return; } handle = __le16_to_cpu(hdr->handle); @@ -3956,22 +3948,13 @@ static void hci_isodata_packet(struct hci_dev *hdev, struct sk_buff *skb) bt_dev_dbg(hdev, "len %d handle 0x%4.4x flags 0x%4.4x", skb->len, handle, flags); - hci_dev_lock(hdev); - conn = hci_conn_hash_lookup_handle(hdev, handle); - hci_dev_unlock(hdev); - - if (!conn) { + err = iso_recv(hdev, handle, skb, flags); + if (err == -ENOENT) bt_dev_err(hdev, "ISO packet for unknown connection handle %d", handle); - goto drop; - } - - /* Send to upper protocol */ - iso_recv(conn, skb, flags); - return; - -drop: - kfree_skb(skb); + else if (err) + bt_dev_dbg(hdev, "ISO packet recv for handle %d failed: %d", + handle, err); } static bool hci_req_is_complete(struct hci_dev *hdev) diff --git a/net/bluetooth/iso.c b/net/bluetooth/iso.c index 2733cc8b8..4e3584266 100644 --- a/net/bluetooth/iso.c +++ b/net/bluetooth/iso.c @@ -2424,13 +2424,30 @@ static void iso_disconn_cfm(struct hci_conn *hcon, __u8 reason) iso_conn_del(hcon, bt_to_errno(reason)); } -void iso_recv(struct hci_conn *hcon, struct sk_buff *skb, u16 flags) +int iso_recv(struct hci_dev *hdev, u16 handle, struct sk_buff *skb, u16 flags) { - struct iso_conn *conn = hcon->iso_data; + struct hci_conn *hcon; + struct iso_conn *conn; __u16 pb, ts, len; - if (!conn) - goto drop; + hci_dev_lock(hdev); + + hcon = hci_conn_hash_lookup_handle(hdev, handle); + if (!hcon) { + hci_dev_unlock(hdev); + kfree_skb(skb); + return -ENOENT; + } + + conn = iso_conn_hold_unless_zero(hcon->iso_data); + hcon = NULL; + + hci_dev_unlock(hdev); + + if (!conn) { + kfree_skb(skb); + return -EINVAL; + } pb = hci_iso_flags_pb(flags); ts = hci_iso_flags_ts(flags); @@ -2480,7 +2497,7 @@ void iso_recv(struct hci_conn *hcon, struct sk_buff *skb, u16 flags) /* Complete frame received */ hci_skb_pkt_status(skb) = flags & 0x03; iso_recv_frame(conn, skb); - return; + goto done; } if (pb == ISO_SINGLE) { @@ -2556,6 +2573,9 @@ void iso_recv(struct hci_conn *hcon, struct sk_buff *skb, u16 flags) drop: kfree_skb(skb); +done: + iso_conn_put(conn); + return 0; } static struct hci_cb iso_cb = { diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index bab8caf18..e7915e847 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -7895,13 +7895,24 @@ struct l2cap_conn *l2cap_conn_hold_unless_zero(struct l2cap_conn *c) } EXPORT_SYMBOL(l2cap_conn_hold_unless_zero); -void l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags) +int l2cap_recv_acldata(struct hci_dev *hdev, u16 handle, + struct sk_buff *skb, u16 flags) { + struct hci_conn *hcon; struct l2cap_conn *conn; int len; - /* Lock hdev to access l2cap_data to avoid race with l2cap_conn_del */ - hci_dev_lock(hcon->hdev); + /* Lock hdev for hci_conn, and race on l2cap_data vs. l2cap_conn_del */ + hci_dev_lock(hdev); + + hcon = hci_conn_hash_lookup_handle(hdev, handle); + if (!hcon) { + hci_dev_unlock(hdev); + kfree_skb(skb); + return -ENOENT; + } + + hci_conn_enter_active_mode(hcon, BT_POWER_FORCE_ACTIVE_OFF); conn = hcon->l2cap_data; @@ -7909,12 +7920,13 @@ void l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags) conn = l2cap_conn_add(hcon); conn = l2cap_conn_hold_unless_zero(conn); + hcon = NULL; - hci_dev_unlock(hcon->hdev); + hci_dev_unlock(hdev); if (!conn) { kfree_skb(skb); - return; + return -EINVAL; } BT_DBG("conn %p len %u flags 0x%x", conn, skb->len, flags); @@ -8028,6 +8040,7 @@ void l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags) unlock: mutex_unlock(&conn->lock); l2cap_conn_put(conn); + return 0; } static struct hci_cb l2cap_cb = { -- 2.53.0