From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f176.google.com (mail-dy1-f176.google.com [74.125.82.176]) (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 85EBC78F29 for ; Fri, 10 Apr 2026 16:19:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775837988; cv=none; b=tNtAwFsE6QkosPKKdxPgO98HxxGZBUooGod/tt4tUL71vcqu6sZTzaiDqXDY/gNnoBTefDdSxmTexeCGsh+t0cYuJP/mUW8kLeU+Hthj386wPqhu3ypu5qEWzFgeVK8boDg473bD2jkUIAhwFvHNE+GomJsfSg1yE54CeMST/9U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775837988; c=relaxed/simple; bh=2sqkraGKOjrNPsVZIuk32nKx2edaLTfYst6vQGlwrmM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V81rM8UCG74rkwee3rFS4hLb72SZ/KgDL1BCQ7q3eBc+Ymbf2jSQoinYcHxnunhqKxgE+tb3bH4puu/jDtRi/WYDgOIEQm5xCE+rYBYsycoFmjdzvZlcjLS3Iiyfw1u6/1c/r3TsyW54znIPLFqZOqOgp45TD9cS7NiGMkH58zA= 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=qVrdJUHj; arc=none smtp.client-ip=74.125.82.176 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="qVrdJUHj" Received: by mail-dy1-f176.google.com with SMTP id 5a478bee46e88-2bdd40d3c61so1903276eec.1 for ; Fri, 10 Apr 2026 09:19:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775837987; x=1776442787; 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; bh=2gOqRIDekvHj7WoWPfMJtNauE9B+cpTSvzavFMCjRXk=; b=qVrdJUHjQ56jzFk0WWSrBYiTb2wXflV6s1msRcrEt1ViP2zWrpX3FmGCXvUu/PMNEK RFtUVQwmRD+bbRaEKsinjnGooz8QDryAkGF80dfehY20LKwD+aI4Ve3WhhDy+NKMqRfC 2ct6nBn0nkUSnlU+k9cT9/v7KNxMDnexqjy0daHEsvqOYl5hDIqJx19fGlPQt8ofvtT4 T8duYP5kENVHC7Y1kZdgOmSEjUpuZFM+8nYNUTDYF/+OVPADxh6Ium/GYOZcGeaznhSF 3v0l2h2qwGPIWWnWo3ICdnYcnjsOkqNq/q+pqsR07Rz+8qVCU8Q1fY6yf+XVJKgv/5LR PxDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775837987; x=1776442787; 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; bh=2gOqRIDekvHj7WoWPfMJtNauE9B+cpTSvzavFMCjRXk=; b=TiESmZfNdY915z3T0EqOI8PBJsKfEmY6spsRbnk5zPy01gaGIiv+SCc58d+RHb80Cl GqW8Jgxja1R36RB1ybcBvfPbynjpezhYHSG4xMHyQQ8UIqb32Y8JfwfVvpwKsbTZGAWU DZGS0y94AqTzeWpyypshVpJhVqdE0CEjZZpPjqZ3euoNah4hdFsgcPo/ZtuBLbsttXmC jJLjOFcsyDnh1hUCF9Clinzz1niRjyIeTcO4PK5ZJNZ8GFU4Jh+kvOks/17pi60N8Siv f2ns/Q/8jr2fQe+L44+WHyB8fczeOwS7lcL2GExi2JxpDoVw5cvJXWFofb10kSVvYxV1 irYg== X-Forwarded-Encrypted: i=1; AJvYcCWHMv8wS5Ypnynfa5b5KFDHrap8vSQZXk372gUYKe1kmZdrlEo/bvtr/B7rcSDs8RzfZIgPv8YKabyefPE=@vger.kernel.org X-Gm-Message-State: AOJu0YzFR1ELZrFWv9Qdt+5C69c9FxgeYUPZUk9wt9UtRaXefJXmdHtl 1QRbr8Z4Wnxpxt3Ucy72VWfDRhnxH19v93GNJn3PChgW4WMEUzrRz7/xsUcEROZr X-Gm-Gg: AeBDietFCyJ8UxnZWlvNzS7xP9/AIMGl1aR6FfC264tY0OXs4nzF/G93C/kauQZeDez wkb1/EuGcDGlIDVNCS6NF6FpXj/WvgE/IJ1ainfiCqT2EZEaCUE9vWXNccs0r/qP6KsvPiBW2YO GfOaY8pXpMy45fsvShVK2dvVEIQ8lmM4FhomXkdvQQBN+yIFVCx4PaSR9Dxdi0Y9injYEmASpst NVKeDbETBjkRmJU1McEG6RN/xfhvDWQcRseWajmui7sDzS8mrYPMoF2R8iwQcy9rEvrqqfdQtPq pE4HgPqjhqrZe1BD4+SOD/dQZOr+rYpuNdIGmS68aC5vIovsrbnPu7CJ80OgnSuFw2f9ga6ciMJ yfCoHQFJUb3t9Q4PdcF3mVqMAPNPJ5C+sfwcYWFbRtYXM2WYLPEzVFWV9HLfD2xNa5np52cG9z8 nxEaN2eyZTwlxt/U+Qy0Qnbl74oDOBbMzEdIZE5MtFnOmYBPJ1V0Hp8R/IPwoDURc0gA== X-Received: by 2002:a05:7301:19af:b0:2c0:bfe3:b95c with SMTP id 5a478bee46e88-2d5870ad63emr2521678eec.4.1775837986601; Fri, 10 Apr 2026 09:19:46 -0700 (PDT) Received: from localhost.localdomain (104.194.93.216.16clouds.com. [104.194.93.216]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2d55faab010sm4958395eec.12.2026.04.10.09.19.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Apr 2026 09:19:46 -0700 (PDT) From: hkbinbin To: marcel@holtmann.org, luiz.dentz@gmail.com Cc: gregkh@linuxfoundation.org, linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, ZhiTao Ou Subject: [PATCH v2] Bluetooth: hci_event: fix OOB read and infinite loop in hci_le_create_big_complete_evt Date: Fri, 10 Apr 2026 16:19:36 +0000 Message-ID: <20260410161936.2589459-1-hkbinbinbin@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260331055032.1883139-1-hkbinbinbin@gmail.com> References: <20260331055032.1883139-1-hkbinbinbin@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: ZhiTao Ou hci_le_create_big_complete_evt() iterates over BT_BOUND connections for a BIG handle using a while loop, accessing ev->bis_handle[i++] on each iteration. However, there is no check that i stays within ev->num_bis before the array access. When a controller sends a LE_Create_BIG_Complete event with fewer bis_handle entries than there are BT_BOUND connections for that BIG, or with num_bis=0, the loop reads beyond the valid bis_handle[] flex array into adjacent heap memory. Since the out-of-bounds values typically exceed HCI_CONN_HANDLE_MAX (0x0EFF), hci_conn_set_handle() rejects them and the connection remains in BT_BOUND state. The same connection is then found again by hci_conn_hash_lookup_big_state(), creating an infinite loop with hci_dev_lock held. Fix this by: - Breaking out of the loop when i reaches ev->num_bis and cleaning up all remaining BT_BOUND connections, then terminating the BIG since a mismatch between the host and controller state indicates failure. - Properly cleaning up the connection when hci_conn_set_handle() fails, instead of calling continue which leaves it in BT_BOUND state where it would be found again by the same lookup on the next iteration. Fixes: a0bfde167b50 ("Bluetooth: ISO: Add support for connecting multiple BISes") Cc: stable@vger.kernel.org Signed-off-by: ZhiTao Ou --- net/bluetooth/hci_event.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 286529d2e554..64b5b497c491 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -7085,9 +7085,15 @@ static void hci_le_create_big_complete_evt(struct hci_dev *hdev, void *data, continue; } + if (i >= ev->num_bis) + break; + if (hci_conn_set_handle(conn, - __le16_to_cpu(ev->bis_handle[i++]))) + __le16_to_cpu(ev->bis_handle[i++]))) { + hci_connect_cfm(conn, HCI_ERROR_UNSPECIFIED); + hci_conn_del(conn); continue; + } conn->state = BT_CONNECTED; set_bit(HCI_CONN_BIG_CREATED, &conn->flags); @@ -7096,7 +7102,22 @@ static void hci_le_create_big_complete_evt(struct hci_dev *hdev, void *data, hci_iso_setup_path(conn); } - if (!ev->status && !i) + if (conn) { + /* More bound connections than BIS handles reported by the + * controller -- treat this as a failure for the entire BIG + * and clean up any remaining BT_BOUND connections. + */ + do { + hci_connect_cfm(conn, HCI_ERROR_UNSPECIFIED); + hci_conn_del(conn); + } while ((conn = hci_conn_hash_lookup_big_state(hdev, + ev->handle, + BT_BOUND, + HCI_ROLE_MASTER))); + + hci_cmd_sync_queue(hdev, hci_iso_term_big_sync, + UINT_PTR(ev->handle), NULL); + } else if (!ev->status && !i) { /* If no BISes have been connected for the BIG, * terminate. This is in case all bound connections * have been closed before the BIG creation @@ -7104,6 +7125,7 @@ static void hci_le_create_big_complete_evt(struct hci_dev *hdev, void *data, */ hci_cmd_sync_queue(hdev, hci_iso_term_big_sync, UINT_PTR(ev->handle), NULL); + } hci_dev_unlock(hdev); } -- 2.51.0