From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE86C39E9A5 for ; Wed, 13 May 2026 17:16:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778692577; cv=none; b=Q8W4XY1Tg8x0Ruf1eTMTVZT59TkI5VOH1PBHo1TKgVUIuXvR35ghvHhKLcFM1VWx9Zj276rIlZhvNo+6rkaZL9wklogmtSQvVXDV12jUI1T+OmMWzMa1HvfWfaBPRNxpT4CZ6Z1nI602GJC6E/N/i05IkJ0acZcYBaajryzUBM4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778692577; c=relaxed/simple; bh=G9ABYHTFAfYI4gLrkPCOFti7/xCpWK2Xhh537YJT7OU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kwd+6EomVSwbpAxk3g16T1vPP7h4JK/bGEuV3Ft/FJx1XKF8I6+wE7+7Q6fJCr6qtboCOYB+6X/astUhiONn+yeflhKDQ5NP3Ix6JDIJMyxY7+uKA+yx6YOPptz/Rj7pa5j4SjBo0HkI7ifeNtRNYQzyn2v35qAupx5zE4hLhAo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pMwtncWo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pMwtncWo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FA85C2BCB7; Wed, 13 May 2026 17:16:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778692577; bh=G9ABYHTFAfYI4gLrkPCOFti7/xCpWK2Xhh537YJT7OU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pMwtncWonW/QkfL1al/kTqFWvNLMzVdRDH7simP3+PNWgG6CLu8QUiTXrRUvac+QU mVmiNYw2X9JnKCYW6aqVkvRgXcfhoUc80GDL4plAVe5PSxlaxLUBJKHHCVBMFmlpDu obwsJU57SvGtIMEJEZCfbguyZ2KrnXxmOs4b9hAE91v+z8LR9ndR5wcTh0a95gi+Ar J7BZMj+sZV29AIeEnBmnUzClKKFD6c2QWI9fPycUYPKyLnQopUb+kshxVffi3nBg7H ml66yFO5NlBi/j9Xo7gIjIyqy7rBCBS1eq0XfuU3SSIIePslcPT4ixP/N59JUkJ5Os PdVEeTMu8xyNQ== From: Sasha Levin To: stable@vger.kernel.org Cc: David Carlier , Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 6.12.y] Bluetooth: hci_conn: fix potential UAF in create_big_sync Date: Wed, 13 May 2026 13:16:14 -0400 Message-ID: <20260513171614.3877718-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026051230-precook-activate-fb0b@gregkh> References: <2026051230-precook-activate-fb0b@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: David Carlier [ Upstream commit 0beddb0c380bed5f5b8e61ddbe14635bb73d0b41 ] Add hci_conn_valid() check in create_big_sync() to detect stale connections before proceeding with BIG creation. Handle the resulting -ECANCELED in create_big_complete() and re-validate the connection under hci_dev_lock() before dereferencing, matching the pattern used by create_le_conn_complete() and create_pa_complete(). Keep the hci_conn object alive across the async boundary by taking a reference via hci_conn_get() when queueing create_big_sync(), and dropping it in the completion callback. The refcount and the lock are complementary: the refcount keeps the object allocated, while hci_dev_lock() serializes hci_conn_hash_del()'s list_del_rcu() on hdev->conn_hash, as required by hci_conn_del(). hci_conn_put() is called outside hci_dev_unlock() so the final put (which resolves to kfree() via bt_link_release) does not run under hdev->lock, though the release path would be safe either way. Without this, create_big_complete() would unconditionally dereference the conn pointer on error, causing a use-after-free via hci_connect_cfm() and hci_conn_del(). Fixes: eca0ae4aea66 ("Bluetooth: Add initial implementation of BIS connections") Cc: stable@vger.kernel.org Co-developed-by: Luiz Augusto von Dentz Signed-off-by: Luiz Augusto von Dentz Signed-off-by: David Carlier Signed-off-by: Luiz Augusto von Dentz [ kept stable's `qos->bcast.out.phy == 0x02` context line instead of upstream's renamed `qos->bcast.out.phys == BIT(1)` ] Signed-off-by: Sasha Levin --- net/bluetooth/hci_conn.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index bf1c39be05211..f89af453cb3b1 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -2051,6 +2051,9 @@ static int create_big_sync(struct hci_dev *hdev, void *data) u32 flags = 0; int err; + if (!hci_conn_valid(hdev, conn)) + return -ECANCELED; + if (qos->bcast.out.phy == 0x02) flags |= MGMT_ADV_FLAG_SEC_2M; @@ -2125,11 +2128,24 @@ static void create_big_complete(struct hci_dev *hdev, void *data, int err) bt_dev_dbg(hdev, "conn %p", conn); + if (err == -ECANCELED) + goto done; + + hci_dev_lock(hdev); + + if (!hci_conn_valid(hdev, conn)) + goto unlock; + if (err) { bt_dev_err(hdev, "Unable to create BIG: %d", err); hci_connect_cfm(conn, err); hci_conn_del(conn); } + +unlock: + hci_dev_unlock(hdev); +done: + hci_conn_put(conn); } struct hci_conn *hci_bind_bis(struct hci_dev *hdev, bdaddr_t *dst, @@ -2230,10 +2246,11 @@ struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst, BT_BOUND, &data); /* Queue start periodic advertising and create BIG */ - err = hci_cmd_sync_queue(hdev, create_big_sync, conn, + err = hci_cmd_sync_queue(hdev, create_big_sync, hci_conn_get(conn), create_big_complete); if (err < 0) { hci_conn_drop(conn); + hci_conn_put(conn); return ERR_PTR(err); } -- 2.53.0