From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384383; b=NKaUOur7PyjxTJ5hJyOC8K3iispQDI9LhRsqXsHUmzY77xmKwLBk+oGu/t8a/M610DvM mmbIKknxJrkl/dSDICDKI/EOwtwENdQia079Fa+iYFxhygMpgR5eymdhxoOvqVYfPSuQx /2+5EsJXG6uSJaxDArSfaHypEX8Nb3xoy98Mqo44PXXMvCvjztq+tohBDQBmmtZLVChD7 BfyAWJ4wmBJjdTOR1uodco00JQdnP0mM5BH1jKyDiDhNp17jMoNY6tBApVMGsoGttuAhS Hgs0xa+w20khwiDcD4mOzLmyFVr8c0IbtHKBJMy8lFdd+PoEqLzYXErqNFcBoevWh+w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384383; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=hi2SYaxv+QWtjGEsEhCTPFWGBN5ELeBcBMPwp45G6vw=; b=ZUh1KgTLLU8na2R7KeHcJzUNm8i3WoA9IYed/xfJaoWNLNqaa/YV+y4bc/5MvJqjpULi 975A9cLnTz1v23P368J/QnOQgl7qzUK4EuYH7LinzFuewQ4SAQxEc1rMO49DLPFEwc0Oa 8he/V9jHg9luO7EM8PCDElIaCUOGkKMAYm8DjrJS2xvd96ccfghMn0NTxHP7Mcay7iEIP QxKihiTjGeKJQTvlVM57Ort+DXIJ4V3I4Hk1I3cNvvYf88WLr/M23+JFIYuq48LOKiGpL 2DKaSk8X/G42SeZP0EcXkOr7zBmQ9Q4neVj56+qjIlOrd8Iu+Piwf+kLJoLY6ocD2IA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=OeKIJuqE; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F402C606A322; Fri, 4 Dec 2026 11:39:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=OeKIJuqE Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13CD71F000C2; Fri, 4 Dec 2026 11:39:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384382; bh=hi2SYaxv+QWtjGEsEhCTPFWGBN5ELeBcBMPwp45G6vw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OeKIJuqECB+xw/AZjuHw3MVtHx5W9rtL6HMIv5P2ToQzJnIOJIIomgGJzXURzHwFz 8WSqTbf7wiAMnav4JobKO+A4XbgbChZIjgl7Bv43i35PLUl9m7lueeh9EgbUGSZqKe dEHtV8YXFSYw5F2g1gI2e/iF3LF1DOlS92Ozkcg4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yifan Zhang , Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 6.6 0126/1167] Bluetooth: validate retained LE Create CIS command length Date: Fri, 4 Dec 2026 18:52:33 +0900 Message-ID: <20261204100705.367415396@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yifan Zhang [ Upstream commit 1eb52f35fc8fb06ab7f2973fff29cba81f96b947 ] hci_cs_le_create_cis() retrieves the parameters of the previously sent command without their length. It then trusts num_cis and walks the flexible cis[] array when a controller reports a failed command. A five-byte HCI command containing only num_cis can therefore make the handler read beyond the command skb. KASAN reports: BUG: KASAN: slab-out-of-bounds in hci_cs_le_create_cis Read of size 2 hci_cs_le_create_cis hci_cmd_status_evt hci_event_packet Add a length-returning saved-command helper and require the fixed header and complete CIS array before walking it. The reproducer no longer triggers a KASAN report with this change. Fixes: 26afbd826ee3 ("Bluetooth: Add initial implementation of CIS connections") Closes: https://lore.kernel.org/linux-bluetooth/179317462624.87574.6271582002629080499@stu.pku.edu.cn/ Signed-off-by: Yifan Zhang Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- include/net/bluetooth/hci_core.h | 2 ++ net/bluetooth/hci_core.c | 18 ++++++++++++++---- net/bluetooth/hci_event.c | 7 ++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index b13687023a0f2..9599656b33b11 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -2208,6 +2208,8 @@ void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb); void hci_send_iso(struct hci_conn *conn, struct sk_buff *skb); void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode); +void *hci_sent_cmd_data_len(struct hci_dev *hdev, __u16 opcode, + size_t *len); void *hci_recv_event_data(struct hci_dev *hdev, __u8 event); u32 hci_conn_get_phy(struct hci_conn *conn); diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index eaceb86b5c3cd..4c2289103ff92 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -3142,7 +3142,8 @@ int __hci_cmd_send(struct hci_dev *hdev, u16 opcode, u32 plen, EXPORT_SYMBOL(__hci_cmd_send); /* Get data from the previously sent command */ -static void *hci_cmd_data(struct sk_buff *skb, __u16 opcode) +static void *hci_cmd_data(struct sk_buff *skb, __u16 opcode, + size_t *len) { struct hci_command_hdr *hdr; @@ -3154,23 +3155,32 @@ static void *hci_cmd_data(struct sk_buff *skb, __u16 opcode) if (hdr->opcode != cpu_to_le16(opcode)) return NULL; + if (len) + *len = skb->len - HCI_COMMAND_HDR_SIZE; + return skb->data + HCI_COMMAND_HDR_SIZE; } /* Get data from the previously sent command */ -void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode) +void *hci_sent_cmd_data_len(struct hci_dev *hdev, __u16 opcode, size_t *len) { void *data; /* Check if opcode matches last sent command */ - data = hci_cmd_data(hdev->sent_cmd, opcode); + data = hci_cmd_data(hdev->sent_cmd, opcode, len); if (!data) /* Check if opcode matches last request */ - data = hci_cmd_data(hdev->req_skb, opcode); + data = hci_cmd_data(hdev->req_skb, opcode, len); return data; } +/* Get data from the previously sent command */ +void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode) +{ + return hci_sent_cmd_data_len(hdev, opcode, NULL); +} + /* Get data from last received event */ void *hci_recv_event_data(struct hci_dev *hdev, __u8 event) { diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 33e513f033c26..e8b504959bd5f 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -4259,6 +4259,7 @@ static void hci_cs_le_create_cis(struct hci_dev *hdev, u8 status) { struct hci_cp_le_create_cis *cp; bool pending = false; + size_t len; int i; bt_dev_dbg(hdev, "status 0x%2.2x", status); @@ -4266,10 +4267,14 @@ static void hci_cs_le_create_cis(struct hci_dev *hdev, u8 status) if (!status) return; - cp = hci_sent_cmd_data(hdev, HCI_OP_LE_CREATE_CIS); + cp = hci_sent_cmd_data_len(hdev, HCI_OP_LE_CREATE_CIS, &len); if (!cp) return; + if (len < sizeof(*cp) || + len < struct_size(cp, cis, cp->num_cis)) + return; + hci_dev_lock(hdev); /* Remove connection if command failed */ -- 2.53.0