From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (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 0E4B8282F16 for ; Tue, 12 May 2026 01:43:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778550232; cv=none; b=kH2mlnmKF0+w+xHbEK3D+3nVkN7+TBYIEvL63lUhY0B0j2qd/VURJdpq9ZFIKdUgt5Ngg2/0BQH63UfDbOlZ3TOkFUGua2abmF3pLxmSt2RBQV11kvwVuxm3HiPGkIKtIQz6h/kPWkwzq63ujv6NX9a6besSjL9P57DC3YqpiM0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778550232; c=relaxed/simple; bh=QpqCFytlXuR0d8C9ucsJ7tz8T+DtLuvL8tttel4gvf0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=j8ZhJ/F+Q2u2JBI9pbHcL5OqFQY6RIJhIQ5mMe0vhYNXz6a+nV8RYdcVvlL5lHbOf8bODN558naWGTq8LQADP7L8TqRRrmxFEhst6AbjsWk/srdLW8gqdOVaUXS3E1pTEH0cTrYfhNTtcblNRmljKTzHYU5zdhNQpig657Jydxo= 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=PhXfLr+u; arc=none smtp.client-ip=209.85.160.180 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="PhXfLr+u" Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-50e63771d91so51521081cf.0 for ; Mon, 11 May 2026 18:43:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778550230; x=1779155030; 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=fYpbANSKVGqlN+ZVCrKmCGjaI+L8XQ7CXzh383M1XaI=; b=PhXfLr+uyJIdFsQwba6mRTa0U4z38gu45rjDB4X6IypEqlxwT+6YhzsZuj5xrR7E3r fj2N0VQD1m5WwtiUjV1BTI7k79uVzy9LfdnL6wfwuYf/Zh5ymppqGuRFRhNPygdPORu1 poepuI6tz2VktIBi3CYCKCo/6lhhRaAJpLTYpPKq65T/tmp7iAIEwOQFPadipsDf2mCh dvVbItaIJuq2nTTrF5s+EMWxwqBhok2JDLUOdoDMxJmqKhW8AIjWn3q+Nrvm7etAPJqp dabiYqYo8zp9lK6PaeM6ss5cY/vDFfQJWVyhlc0Tt0G2d5wXy1ZyP0G17fDmyfpU2Cv7 Pneg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778550230; x=1779155030; 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=fYpbANSKVGqlN+ZVCrKmCGjaI+L8XQ7CXzh383M1XaI=; b=bWI0ezZmYwLf4XCjdqF8vOox77Pnf5mbTq6sdS32+i12kjQ4ZPRZ6V7pRT1jGnXPcI ZVx/i/doQMPKMLyplzE1wcpN89kk4hlwMPLGVYlFDqyCVRc8vAY1VKuuz3ITxYaTPTCD PnHTyqB7T4+O3ZGguShGxodDVkPZVQ9WwijKbckwdPw+vZxvDiYQVigTqoa1b1AT9ov/ Y9n55VTaVY4RSGGgUsVB7rBtwg4m5ovY7zVnFDYwphxNU1m4OBkmjXaSK++DhlDWNH97 ctWI+YsXQGHxuBS+snc4hIBzCfQv0y+EeWj87fR2ZM3PbXQYfaLezBdRDQq19zSEzlWS 16Gg== X-Forwarded-Encrypted: i=1; AFNElJ/ud8EuKD5qZsqrRYzG4lqjTHlQWgcwCeYxGpvZsVXiqbvr9tuf55Umdt1qTWIyxSR9V40Js7Vt6XaFNqY=@vger.kernel.org X-Gm-Message-State: AOJu0Ywo+lRWJr7dtgkvGX8OdV6qGnbgOrRv7ED2xjc+9m4qaG9roLb6 hiVvdcfCbttrR1ozjmkL04CnpzCpx82VHGpRQGPN7na5ced0uH6fnyYI X-Gm-Gg: Acq92OF0nSlpMZPljRKKWiSfPUAb+ZQWZvFW/3JIw+MbFsbCnS95OSfKWurDZ+Zym1T zGQxUjsMeOhjdKMo6lW+rtFJ3Vfjd9xySK8G5bVBbMgv3HwXC/IudUccM/0WlD90wCqD4BjSYTj zp6Z0sKGNdVsCo+afXwkZuCeLzDn8cWdsaCrPKjZXlAMF8uTsEUXiAWiRyVkXhUuOHmDeVICnrK P6/9re+j2p13VvB+BbKEV1Ch8YBgaGCr4mM+v6yLeua1TagmIE4ymWocuhNkd6PSy6KKNGgJngi QaXnI7usiX5aEOPirn9Kn4ULxaAfJEA5Wxp2XGlsqJ6iTo1CK65da7Qe9mIvFNtBrJS3Fw0DxCl gO0vcWqRjjFcuWOMdKH+7oBCrDYaPtF8+FBfu+rQJ6SxXQUXRVaN0dLHepyL+5+ZdX9Y6JrqoMg GjtxRNENRQEWlHberzFANTTksDmW5+uKtOdotGL/9G2vNA/JU7nL89oDvvJ6tb93qH99mpzpBy5 DCp/Ze2lilXO0c= X-Received: by 2002:a05:622a:4c0d:b0:50f:b7f6:d626 with SMTP id d75a77b69052e-514a0b700femr186281521cf.47.1778550229877; Mon, 11 May 2026 18:43:49 -0700 (PDT) Received: from jeremy.kali (srv1619992.hstgr.cloud. [2a02:4780:75:55a3::1]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8bf3a43665fsm109591116d6.20.2026.05.11.18.43.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 18:43:49 -0700 (PDT) From: Jeremy Erazo To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] usb: gadget: composite: fix integer underflow in WebUSB GET_URL handling Date: Tue, 12 May 2026 01:43:43 +0000 Message-ID: <20260512014343.3770664-1-mendozayt13@gmail.com> X-Mailer: git-send-email 2.53.0 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. Reported-by: Jeremy Erazo Signed-off-by: Jeremy Erazo --- 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