From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (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 109973C8C49 for ; Tue, 12 May 2026 16:05:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778601939; cv=none; b=JcM1tFDLKOj2fbiPL7He/WtEP10Sid2Nph1iVOMDO1+VL+XkwRzJ8Hyy/qSb0jxWheUackA07BMI77anoy0TUupQhdCFlvL5OvRGPhx3CcLetwO/i+BjyJzN1jpOL2S0dwjb0BS+cqMDzhuhML6SHzYKIRbasO0kSfreCZSFmsQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778601939; c=relaxed/simple; bh=oFLU835hnkQ0S4QHH8e6Y68/BW2CchKOk0YRBCmJeaI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o5X3zhbCz5YdNuJ+9PBP8Xb2ufZrbWnQ6j3yAJws+5V1LOtZBLnaB90CNknaIfUK4amhI5209OEKa8SI8Hn2XDCmknZfOs9dVO/MP7bza2jeeEGwdUko3yleguMYU1u9nXAIWwtjCgV83sfX7SyymU/kLzPQ0mEc7UPQw+ARId0= 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=Ewspg6dd; arc=none smtp.client-ip=209.85.160.171 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="Ewspg6dd" Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-5102582e23eso42559811cf.1 for ; Tue, 12 May 2026 09:05:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778601937; x=1779206737; 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=pJVGtLX4Hm7QXav4cdi4atZzWJUm1596Y32TKWTpJs0=; b=Ewspg6ddG2mSZ878szVA3HbFaz6E0iH10Ob322vOq5fYfbHk+iC7zEwxS3JTL0nQoV IoxBo6W4LL0Jw5p6hMB+o+TNYGs6BlZpsNwG7MKWSEJWUXw8YIwQ38cNyQKFoo2AHcYy bD9XL6JRUK4+Dk0z8ef1rg2LKboV7LcLHFrKgee5da6oSy3mQBmE6PjCoCd1jbcQhdVt 5R1eEEmVANEXJHfqZlvSD6Oh1loyNhwgWf12kP3mZKyKbFOXHGzzTgsflrbJAqa/XLHp 20RO3qKe3NnXJaMb6xlbyh3LjggVyaUHLCOe73nz8gi8IIjXEtp11OrGDE6UNh6ZcoIW DprA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778601937; x=1779206737; 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=pJVGtLX4Hm7QXav4cdi4atZzWJUm1596Y32TKWTpJs0=; b=ibtA2JwDr3fTHY+8pArVMBqY1Y6dMB5khJANNhwYZJy6v18QUF9htsg2Te/17gDRLh iHYYezppP/3FuE2e+AYkYHErd75eLzquaIV2nrz+e2XX9R7btUjmzvjbVF4A4K20QhuY jai5cvGQLx80do3HXTGANvHfUtksn1UT+HMy5zHv/qBZ8a8lBZAT+LgJ8t/o+aALGkxj uB0Xu6qfdtHJxBVvFzHxkx4++0guWUccs0zZS4psRtR//dkhDi9ezKdgfFUPH+qWNkxW oKqb9DcEyzavsgAl3o2Rdn2Gm+aL8VC+wxUOEgTxVLyabG0RVb+/0h06dibb6kEkCeqv 4bOA== X-Forwarded-Encrypted: i=1; AFNElJ9MgOcKPVtKLnkUrdISBlRLJ45o5sSlbVuL/rDuX1q0S74tYAGTVXrfev7TFFEJx84674n9ifufHoImxpc=@vger.kernel.org X-Gm-Message-State: AOJu0Yw6mAIxVjfn0KEkPPAMIRITeSGasCYLnyU1tFIjR+tLMI9tn06Z K/5Yltfmu+A7mtiK4GC0El3zqniobmQs2bmsqoaZo/ELYZCntM+7ODBn5YPrq0G9JNiloQ== X-Gm-Gg: Acq92OGrHvYcr9ZKdR1aCc69wWRUg7PvtyppGwxl/muF0i2RCuWwL2ft6sIYTfY3Rsq Zp60w8X66yx0WhDNVpf2FfCde2UXs0mhnFJU4HFcR26P+zuP8I6Zj726wN6OfAhpHd6A1HSB/ay qSRk8Lk+7yecsf5B8eO2crwQ825pt5DwAlKHwBbyrcfe+DG6eCM3qzqa005SFiFvdOzGAQlldt7 AKO3g0Q4EqYhCQ2XyNU4SPzf77tyP8uqKERwRkNULWAFSsLRRSdcgS+JNCFM+uBqyf6pp94MqwV 4KL164/DrGiAkgNA98cNeucu6MaeobazsDllyiGzRyDjreKV0izrpHCfCy5YY0hmTdSDWAK5cfj nJWu+sGJTeuwfjHZ0zp780iIhhrUvVqhHSTJIKMvvge2XiluiP48l/ukm8KN8cXM7EXvkTH28Xm pihM0mYr/RqmocJsaERfXA91UbSBCG6v1jSleM96aWNNvOeHDk4OA2PHuzPYlMlvK/G8Bgs4Eya S5OKosFyhrbdg4= X-Received: by 2002:a05:622a:4d86:b0:50f:ba44:ce5f with SMTP id d75a77b69052e-514a0a69e31mr210098491cf.22.1778601936659; Tue, 12 May 2026 09:05:36 -0700 (PDT) Received: from jeremy.kali (srv1619992.hstgr.cloud. [2a02:4780:75:55a3::1]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-5148fa78723sm118135811cf.3.2026.05.12.09.05.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 09:05:36 -0700 (PDT) From: Jeremy Erazo To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v3] usb: gadget: composite: fix integer underflow in WebUSB GET_URL handling Date: Tue, 12 May 2026 16:05:30 +0000 Message-ID: <20260512160530.352318-1-mendozayt13@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026051227-concerned-geiger-b8a6@gregkh> References: <2026051227-concerned-geiger-b8a6@gregkh> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The WebUSB GET_URL handler in composite_setup() narrows landing_page_length to fit the host-supplied wLength using landing_page_length = w_length - WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + landing_page_offset; If wLength is smaller than WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH the unsigned subtraction wraps, and the subsequent memcpy(url_descriptor->URL, cdev->landing_page + landing_page_offset, landing_page_length - landing_page_offset); ends up copying close to UINT_MAX bytes from cdev->landing_page into cdev->req->buf. KASAN reports a slab-out-of-bounds in composite_setup on the kmalloc-2k gadget_info allocation, and FORTIFY_SOURCE traps the memcpy as a 4294967293-byte field-spanning write into url_descriptor->URL (size 252). A USB host can reach this from a single SETUP packet against any gadget that has webusb/use=1 and a landingPage configured. Handle the small-wLength case before the math: when the host requested fewer bytes than the URL descriptor header, only the header is meaningful and no URL bytes need to be copied. Setting landing_page_length to landing_page_offset makes the existing memcpy a no-op and leaves the descriptor returned to the host unchanged for all larger wLength values. Fixes: 93c473948c58 ("usb: gadget: add WebUSB landing page support") Cc: stable@vger.kernel.org Signed-off-by: Jeremy Erazo --- Changes in v3: - Add missing version-change notes below the --- separator. Changes in v2: - Drop the self Reported-by tag. - Add Fixes tag. - Cc stable. drivers/usb/gadget/composite.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index a902184bd..dc3664374 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -2172,7 +2172,10 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) sizeof(url_descriptor->URL) - WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + landing_page_offset); - if (w_length < WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + landing_page_length) + if (w_length < WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH) + landing_page_length = landing_page_offset; + else if (w_length < + WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + landing_page_length) landing_page_length = w_length - WEBUSB_URL_DESCRIPTOR_HEADER_LENGTH + landing_page_offset; -- 2.53.0