From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C05A37CD4D for ; Sun, 12 Apr 2026 20:29:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776025762; cv=none; b=drPznpc/CO6hJM8Gd4+bnME+U7mm+SqEotc61N31TR6rbbnDatNSeGF14Zb9tDCt/26bX6THDHmg+Jl5mZGoMgQUM7FwCmf9pqtA2v9Wq3aUuWBCDuxVMlv/1xYGqkvjiKFojTUN2c+nPy64nal4jw9lZW7IVnO6veln6QTMaEQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776025762; c=relaxed/simple; bh=3rqtvqqZTGtxKH38oOYjEvWW5C96W0zbTJWPHwN4xk8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=GHatCSnIqOvTp6fGez/i7PwEEFmogC0R64sTG8oTYZoyQp6qYWThwfP7VOHsdAPpxl5qXgu7BXiiqsyGb5CFkkFHVKgxZbLgAOj/5k9Iw5am5x95SxXJayfuPylXxFy69IN3Z65DK0IePrciHlnxCA9C3RFpdnommc3GtAe7NMY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OocIG0p7; arc=none smtp.client-ip=209.85.221.43 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.b="OocIG0p7" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-43cfac48bc7so2473963f8f.0 for ; Sun, 12 Apr 2026 13:29:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776025760; x=1776630560; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=9Id0UBUp6u8lf/UjsSjAE4ozbDe+gUA5wuiQY3ynuDI=; b=OocIG0p7aC5kRfRhxgeD3Vsh+UwI/7SPAYzgDpHG/r773+jDcRxzVj4R2r/lMEZLSi W6lyWeSuQOHQHVZIoYrN18O5LRk4uC1gJz/h18KMh42UBIH7wmISfUipKxSrV1RodkU5 ONRqYN66YN7GzIUwGSiLzEW/M6MHn0SpSdYpCPkyLyZZKQMP6Nsnd/NTvqlV75LOMoV5 K3vF41vtWneAIJakbaMT+G7gfds8m0BZbWE0uBTHilIEjCXbUdnLqknSUptz9QAM4mXa qhoJBlhF/eG/E4uAaVX9SND3SI5RnYOb93lpgsgZGKAMaEpjwC5hyG5FGWjkfjurdWK4 FVSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776025760; x=1776630560; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=9Id0UBUp6u8lf/UjsSjAE4ozbDe+gUA5wuiQY3ynuDI=; b=JXHB7wqscGa8U4N7sDkMT78K4d74WubS9wd2es4Y+pk34rHPuPLlXFcY/o1vxm2wbf fN10LZGOg/yMoCq/lLixmAi1+Iz+wtg0BWUMIY9bIHCpOcbItTI6mttuEbe+OHwcoKQq foY9PLTkn4t4yVPhjAtym2M14tBtbxav8BejYFttBiE3dsYoTgJN9bL6pVUqQdUD20p1 tInS0zzCOP+RZZAh2sqDtLBV+r7NM4GQ8S+t07AQ+4kY/VT1o95W4qoHBo5jHIPBB9Ie ASmeUgeMgYMKNCyTr1QH3L/5Pidu/GsoCX2Hg8slTwmxis2EKNUZFTtsThip70M4xoUd QtCQ== X-Forwarded-Encrypted: i=1; AFNElJ8CZQgwLzh52z/LkmKYV+NKWEGilenBcjwf8oc4FX3ThlIjKd+KJKBP1U7CNM5GW6+delmp4c5PNZnmmh8=@vger.kernel.org X-Gm-Message-State: AOJu0YxNzqL5+v9EjS18hiRmvDLcjqwWIOR3ayOaX57cXZxMP/F2Xl8t 0nUqj58qTDUIik1pv8mCD9qp0RlXRGvOquKs5/esqM2HWF2afnQ2F0ZU X-Gm-Gg: AeBDietgPcjD9gUmiv23slhJhqJayDf7QEtDw9Thk3dONxf/5OXer6lLlIysQ59fnV9 jg6k6PbDSsP1ylPD5S0KU709v9sXKThEZ8/UkHoXAHdIgkP4grLA/SWWExmD/t3D4x8cYrLyGK1 9nnrj8WiwWvip2KLUu5uGHExnDrVwG/phKvU8lbEcl6XYYLU6IKCr07SeGYMm2lAsSUQS0BDsOq b2tHCeSR3ACe7VZzxVd3baQNdBtfmTxVCqpHl1AcsCX6/Z6b1li5XUprcIYRAMQf7Dl3DjK6pDC XFMkjDAReDZTDwyEl+JMb0szYEb+SyDCUvW4xOx/FTN4D6f5jyDXy4h+GWJwwj05mGChEzaraFG MhOh7pTpc09CUeFGBmXNrl8Youu55MNlX6+XtItUGE9FDbfzX24w10zYkp1a2Gp/KH/KVHOMGJt +XyZ+gO23mNSdf6VcZQ79wfEp9EJgUSUurod3eyBtVFYbm1PmUnWOtdMMFYeSh1zlklJCy7vEMj JAF2jHM57Kh X-Received: by 2002:a5d:5d10:0:b0:43d:1bf6:930 with SMTP id ffacd0b85a97d-43d642dd09bmr16220327f8f.47.1776025759377; Sun, 12 Apr 2026 13:29:19 -0700 (PDT) Received: from dohko.chello.ie (188-141-5-72.dynamic.upc.ie. [188.141.5.72]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63de2a69sm27240736f8f.4.2026.04.12.13.29.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Apr 2026 13:29:18 -0700 (PDT) From: David Carlier To: Marcel Holtmann , Luiz Augusto von Dentz Cc: Pauli Virtanen , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, David Carlier , stable@vger.kernel.org, Luiz Augusto von Dentz Subject: [PATCH v4] Bluetooth: hci_conn: fix potential UAF in create_big_sync Date: Sun, 12 Apr 2026 21:29:16 +0100 Message-ID: <20260412202916.196282-1-devnexen@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- v3 -> v4: combine v2's hci_dev_lock() wrapping in create_big_complete() with v3's refcount. hci_conn_del() now runs under hdev->lock as required by hci_conn_hash_del()'s list_del_rcu() on hdev->conn_hash (Pauli Virtanen review). hci_conn_put() is placed outside hci_dev_unlock() via a two-label unlock/done pattern so the final put (which resolves to kfree() via bt_link_release) does not nest under hdev->lock. v2 -> v3 (Luiz): keep object alive across the async boundary via hci_conn_get() at the queue site and hci_conn_put() in the completion callback. v1 -> v2: handle -ECANCELED and validate conn under hci_dev_lock() in create_big_complete(). v3: https://lore.kernel.org/r/20260410201343.229470-1-luiz.dentz@gmail.com v1: https://lore.kernel.org/r/20260408155638.95927-1-devnexen@gmail.com 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 11d3ad8d2551..9fa6901aae9f 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -2130,6 +2130,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.phys == BIT(1)) flags |= MGMT_ADV_FLAG_SEC_2M; @@ -2204,11 +2207,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, __u8 sid, @@ -2336,10 +2352,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