From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 19D92330B30; Tue, 21 Jul 2026 21:13:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784668424; cv=none; b=V7nC3RJzeuCPymXHiJqgeiDZ/mR/j+yqH0hBbiHRJ78tV7W3IBOzXcv4fUaLT6M1ztBeqR61CSTuQkMW8ySdmNInkQcgKecj/quLBKRnBloIpg0QPosWBh3HzJqDfTCo3QsY3ZP+DHuj56Xb7kDreUxOKWIcKb4BuNdFTEMYEWw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784668424; c=relaxed/simple; bh=1P5xQKCe25hgV1EirqKMvXcHDJjW641YZhclaWD3Q54=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RBDt80UMJdMFvfbXhL7H/Owf01ftEMhcg+Wocf9BSW1p2S0WCIf4d2CpzlPvhwqmvg+4Qi08l94/MX8PJOfKWX0dGidK9hxTowv16ZEEeDtRMkRXM9o/fTZPrKcd8wsNMvGHjtEFn6joTkeeaakIkOFp91XokeA9R157tLTq2LY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=YldGhPJ/; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="YldGhPJ/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77B861F000E9; Tue, 21 Jul 2026 21:13:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784668423; bh=CNKFviCcZ6wk5b9L7F6rL1M3ZqZauIAqf0zlEUchvOw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YldGhPJ/o12a6jNy5W0U6XEOoeP4vYU5W4Lxc73/T3ZE9EdpdhCJ4A7sgsF617ECE QQ5G494QgqL/jXynADjgvKPjpbqVWoDnGx0u+kh/dxIVWa54aT5LpuVgL0u0j7oW/G o4PAyHYJs3r3Rk782NNUtNyMlQSoce8cQVNqKHu0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable , Maoyi Xie Subject: [PATCH 6.1 0170/1067] usb: gadget: composite: fix dead empty check in the USB_DT_OTG handler Date: Tue, 21 Jul 2026 17:12:51 +0200 Message-ID: <20260721152428.393930983@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152424.521567757@linuxfoundation.org> References: <20260721152424.521567757@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Maoyi Xie commit f8f680609c2b3ab795ffcd6f21585b6dfc46d395 upstream. The OTG branch of composite_setup() falls back to the first configuration when none is selected: if (cdev->config) config = cdev->config; else config = list_first_entry(&cdev->configs, struct usb_configuration, list); if (!config) goto done; ... memcpy(req->buf, config->descriptors[0], value); list_first_entry() never returns NULL. On an empty list it returns container_of() of the list head. So the "if (!config)" check is dead. When cdev->configs is empty, config points at the head inside struct usb_composite_dev. config->descriptors[0] reads whatever sits at that offset. The memcpy copies up to w_length bytes of it into the response buffer. cdev->configs can be empty in two cases. One is a teardown race on gadget unbind with a control transfer in flight. The other is a driver that sets is_otg before it adds a config. A reproducer that holds cdev->configs empty triggers a KASAN fault in this branch. Use list_first_entry_or_null() so the existing check does its job. Fixes: 53e6242db8d6 ("usb: gadget: composite: add USB_DT_OTG request handling") Cc: stable Signed-off-by: Maoyi Xie Link: https://patch.msgid.link/20260527150832.2943293-1-maoyixie.tju@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/composite.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -1855,9 +1855,10 @@ composite_setup(struct usb_gadget *gadge if (cdev->config) config = cdev->config; else - config = list_first_entry( + config = list_first_entry_or_null( &cdev->configs, - struct usb_configuration, list); + struct usb_configuration, + list); if (!config) goto done;