From nobody Mon Jun 8 17:38:30 2026 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 01FE73F39E7 for ; Wed, 27 May 2026 15:08:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779894521; cv=none; b=I3OxReNc3tYRhXXRTj8YRR5bfDiaa6oNgpBE8KKEmc4JZLK+UXx9ztP2ITtCzJ6Q7rmwI1pUkSIPUCufRrZuXSeNoVJgA3R/nOM8NlZO8vkcPJFFN6kYhoMvcWwAR+RhJcs0Q6GLDdul5dWKUAoQZQP9CF/4XnnKxeOmzlDs8I0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779894521; c=relaxed/simple; bh=ftJA1esdt5l+bw3g7t5Q7tLNGvcMDoD6AYCXN62BQ/8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Y0gHH9yNC8wO3y6VHlqepWMvny0RmyeHOepmX36GSQw6n4+uTzPRHXvlLDCn1AOqIzn7EgmXobMHauGqYdn1TEPfl4SMkigDr14gFN+F8oU+IG1ToKwfGyoRzhqAoGfhOunYG77w06VWHzloBNNMh8YLxMuE+gqSlAofsiS49lw= 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=sgOZl3Y2; arc=none smtp.client-ip=209.85.210.181 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="sgOZl3Y2" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-82f8893bff3so5541480b3a.2 for ; Wed, 27 May 2026 08:08:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779894519; x=1780499319; 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=fDJ8S5hbiqIsI65l369Il1cSJ90Nc3vvPmKDZOmRp7I=; b=sgOZl3Y24iuxBKWB2wwnZfzKq4WsTClNd1KQWZOxIFwyyWwfjYwHl4QzCrIkgsoBxM SByojtrQS+FSLZQPVAfPcHZCUHuAcNlrQJ8cWlMzrKMdr4fB5ROQsz4R9MzGDEIBHaJp HLYBpK0BowH868NVRPQv/zNtn5lFFUFeaQIzNzeVksf1ImYcoM783wMrCEuMA5X0774F lw1NA58Wug8jFRN5xks74FSXKGRxi8wqwxREgTFB7M95STFTeopgbVPj8F2EspTmGcxW PFM2M6W1VbL+fnG8oZfIhxZHe3ag8xbsoU2U46V4M8IJqIvf2DMykaUQl5FWwkTIF4tt Ippg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779894519; x=1780499319; 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=fDJ8S5hbiqIsI65l369Il1cSJ90Nc3vvPmKDZOmRp7I=; b=TJtgxdvlAcwUmctWh33JSyn09jzJ71Np8FkMbNxV6UwPKxzu+V5S4/+w4lHyZlgJHj Vtk2MXqpnNHpzMrjoIU6WhHe6blycC5LLcemW8F8FhG0pNY1F4gELC8bc1eLhxBCagh0 LkvZgWzE2LSiGFpEyQ1ThHSC4PVqW+htKLqdfxJk67Va0PfSXRszU303im6yV3+tuQzB 3rqILnbFp/hKBd6IbnbHkC2NHbmAfwE5ueg9416V3CQLmR0HVC5p/gpua1ylKKFWMbch qh8cIB6PKzRvPCJ7Jj1L06aj2IoEPyH3gMUq2/nvLuFZeX8o7Sk91YcboeygecfnaQZN m6zQ== X-Forwarded-Encrypted: i=1; AFNElJ82IenfGsThIZtOxxrWcTH9qDNpHr3VYNqluMtFMqMJAF1M6fjclBgF+QPGnNIZi1texdaCL/MCKQjjuUU=@vger.kernel.org X-Gm-Message-State: AOJu0YyjD2Miy9652zItMCj6fVsdPO9r0ctiDfDX6j7PKk0Mz4M2Nrqg rE1OpoeHbS2iKME/nS5OWXukrDYkolGWDAmIsSK/QrQhEgUXdBS1QDyj X-Gm-Gg: Acq92OE6tUTJMgZFP2be7WWRDqJ+iI4BJcnTfNECgdK05efnMw+5r2Uvtj7ov7bUy7/ eAWm9E4tYA4Ldi2oTpBUVIfwVEU8nroAsEDj7U6bgcqIa46p08R26M595dWIf5aN2fUBERNZ8RA 7NukOGfgHvwUy5vtmzT3Dg/isAzrEIigAn3mDfTMlvDr6G+w/B14viwtL1WwmEsOSz0ph4V6ENe VbqcE8ULQM0iPP+6sHjnyXsrSbqvT8ARXkIWUOfxcNYqbis94zW+O2LVDxfiwyqdMj47nrQM9Cy TbPiP23yMxZuYJ/gHXWW0ZbMFSWOmTFiGy3y8tWD50fH8F+2YVO+gGeXuF6QjfcV3bp1qHt77DX h6AznM8TllfoUA4hdFLRkG9SOIgUVyjxPmyUd49LcGCTRpOHOQlm9f5lRj/hBbMVw2NfuAXbTRL /Ae1ysamL+BgNf6Ua5DZov8rvWBShichjX8V9RAawtJ5yg4u9oSplOk/jYN47ij5OwpJICOw== X-Received: by 2002:a05:6a00:3e06:b0:82c:6f07:299f with SMTP id d2e1a72fcca58-8415f3e81a6mr20982338b3a.14.1779894519182; Wed, 27 May 2026 08:08:39 -0700 (PDT) Received: from csl-conti-dell7858.ntu.edu.sg ([155.69.195.57]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-841d72eac34sm2874346b3a.49.2026.05.27.08.08.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 08:08:38 -0700 (PDT) From: Maoyi Xie To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Maoyi Xie , stable@vger.kernel.org Subject: [PATCH] usb: gadget: composite: fix dead empty check in the USB_DT_OTG handler Date: Wed, 27 May 2026 23:08:32 +0800 Message-Id: <20260527150832.2943293-1-maoyixie.tju@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The OTG branch of composite_setup() falls back to the first configuration when none is selected: if (cdev->config) config =3D cdev->config; else config =3D 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 handli= ng") Cc: stable@vger.kernel.org Signed-off-by: Maoyi Xie --- This is the fix for the problem I reported on linux-usb on 2026-05-20 [1]. The full KASAN report and the reproducer are in that message. [1] https://lore.kernel.org/linux-usb/20260519184106.2356558-1-maoyixie.tju= @gmail.com/ drivers/usb/gadget/composite.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index a902184bdf82..a5e7c6495949 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -1863,9 +1863,10 @@ composite_setup(struct usb_gadget *gadget, const str= uct usb_ctrlrequest *ctrl) if (cdev->config) config =3D cdev->config; else - config =3D list_first_entry( + config =3D list_first_entry_or_null( &cdev->configs, - struct usb_configuration, list); + struct usb_configuration, + list); if (!config) goto done; =20 --=20 2.34.1