From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 A56F954763 for ; Sat, 8 Aug 2026 04:31:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786163462; cv=none; b=spbGl80uxhn1Ngx3cxbo/ePY3h/uRvKme4n1ldF7d8dvN2KYViDeczabS3pcDeZjAmDqiQlb4Ws3r/+KB6Xok3WifmY42/AFFUDPCoQF7fMz4Fkelgm9vsbdYtFg9rtZr0YyNF1EwgcLz9hvlmaHltFsN0ktcS/P4MTIwEoB9QY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786163462; c=relaxed/simple; bh=FPHAe4ZalTRRep82ITgSnoG0MJEYJSRKN29ZWYyOp2Q=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=W1LGZFSu6p49Bygtzffvk9HNQZT3ditm8qDqtJGuviehbj/HaCoS+RD7rInYrSeKAfEkVRe3Q1QuVcidIYF8ByecPj4xu2lcrDTSz2NfUOeJYdaYe+AtxwBbfrJAXIg78gucxP3ymc64A+jGuAVrSTNJAQH6Lkw+K57hwLdMSeY= 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=onhNdJ9p; arc=none smtp.client-ip=209.85.214.177 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="onhNdJ9p" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2d02b4c3601so2692465ad.3 for ; Fri, 07 Aug 2026 21:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786163461; x=1786768261; 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:content-type; bh=I4oeMnbiZ3A93sA/68pPML7ewKxr/ZgYfLBewFTjvwU=; b=onhNdJ9pyKO+rKBvZ0KEN4qFdkR8N7t2qrhbE1otmWDn+4xoBnoAigwVYq2wbDADMx gQzeFEwtjQMaHp3DlyZK1KG8X73EgbbLKyqaCm64MLW79lobQ1DGEvmkyfShZ1/og6tY HfBsxyZC8KXmwYCymquHVW9zWTe5dHCUW1wnQDCdzwBfzkxT/kDZNIERgHsa428/otBC hPVnpod9veTb2cNv3AaBUbHSGsuRHUBaQ30jImfFboGJ9jbxzT7vc6NEicvOr1I+BOmA 81Dk29OApLlUSaBuFydrejwrmoke+M4EuEZUWGWl9kA4xWS68NBvAbIvIrlctR02DbBr 8qQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786163461; x=1786768261; 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:content-type; bh=I4oeMnbiZ3A93sA/68pPML7ewKxr/ZgYfLBewFTjvwU=; b=UckFplDgw77TjD5ge3dxgYtAUtlmc4L5Ak9OZAy+e2KPgVN26SCuHmhXtj7LcKWTY5 YH1EDkWmguavHhKdXLTPSgSyunBCS/6QbOAbykaDaZ+wqqDKcHRp0V3yhFScddcrxiYg cl8xShzQsJaWnoeBEYnhuTIEAucvHjdPxv7f042ETT/83gfLGpG+6hoIH5ITjqgWAABd rZT4iX3i15FXvmKCNV9DLYC+tTaKPN0qq97wjTcF8I5mho0RqLbZEPP2T3C7GG7ACgbe c31yOJWU4Lr/ma3sT93+O4kKxZTVEyBZujjgp0YKdg3hOZJWgEZ91JiFrRmjAKu6f5Sc I2DA== X-Forwarded-Encrypted: i=1; AHgh+Ro67arfinGniBNteFX0CcmTTn1ucaDqT3Oc3/6VMKvFL10TkkrtmLw7ax4F7xkFtQyzJ40Mz2vXK/b1zgo=@vger.kernel.org X-Gm-Message-State: AOJu0YwKpxGq7+okVg1EnUpKcSTOf1jCh2G6kpvo6zcMc1ZRt0u6v9NI SV+1kxBhWepcronQ12JEIAMgTduk5N0L3ii0dyQvhRc4AhWDYp5tz1pJ X-Gm-Gg: AR+sD112Zc85PrSpISh95kJ5+fRN7fBBOsh/+HWoU+D3UfYWc48s3ijsME7CXQSs07c hWJ1TfpOrAGgM2i9T+3s46e+ww53/HT/Y4uCB+GY3eScLyIKKEiJM2ZXjWjk5KdbTv4YlWtTvp7 cOfWH9p+j/47eyxjkWWu3/xmYGTMG2Zy8FrHu6EpdAZj2Y8uP38IlkR2woz5HBSg+KntEO6de60 JZI1NKBGsNUv7jc0bc6YWU6riAn0dbma6izV8KlrA/AWTH8CBMbiIybsTUDKlx6Ux5Pq14ClEF/ PTU3Xll6LzkAjQuCXZYWunfl3hJ8kemGjBYG44KLEc6JfaG+TlFG3mPlh4KEkQnw6kNjcDMvETm HT0GOKAoKHQh6L2IVAkmi03xyUzcjgIN1KlvEn/yVI64H3CoN7mkk+8i9fGDoWyhbcX2x++HenR UYtUoN9YxfrFZ+OrFRKwvSwShYJ8pxjT1g0iuAYxz5cFTVHlQUYfFEB72tK6Kh+PUEzeR21cn6r wkk0dDDxpFvCXyQ882O7PXgLfbxbOhEAbtxpB82CuvS7o/RaDPMJVqme8rSfmkVDYr8qgaUHPE= X-Received: by 2002:a17:90b:270e:b0:366:3517:1aa2 with SMTP id 98e67ed59e1d1-3903bb0cf61mr29965252a91.0.1786163460506; Fri, 07 Aug 2026 21:31:00 -0700 (PDT) Received: from kernel-dev ([49.36.97.234]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-315beb8844fsm14424443eec.16.2026.08.07.21.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Aug 2026 21:30:59 -0700 (PDT) From: Aditya Chari S To: Johan Hovold , Alex Elder , Greg Kroah-Hartman Cc: greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Aditya Chari S Subject: [PATCH] greybus: usb: fix response buffer size for fixed-length hub requests Date: Mon, 3 Aug 2026 06:32:48 +0530 Message-ID: <20260803010248.339120-1-adi25charis@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 hub_control() sized the Greybus operation's response buffer purely off the caller-supplied wLength. However, per the USB hub class spec, GetHubDescriptor, GetHubStatus, and GetPortStatus have a response length that is fixed by the request type itself, and can be larger than (or independent of) whatever wLength the USB core happens to pass down. This could under-allocate the response buffer for these request types. Special-case these three request types so the response buffer is always large enough for the data the module will actually send back, matching the equivalent handling in usbcore's rh_call_control(). Fall back to wLength for all other request types, as before. Compile-tested with 'make M=drivers/staging/greybus C=1', including sparse, with no warnings. checkpatch --strict is also clean. Note: this driver's hub_control() is currently unreachable at runtime since gb_usb_probe() unconditionally disables USB support pending separate USB core changes. As Project Ara hardware is no longer available, this change has not been tested on physical hardware or with a Greybus module; it was verified only by compilation, sparse, and code review against the equivalent logic in usbcore. Signed-off-by: Aditya Chari S --- drivers/staging/greybus/usb.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/drivers/staging/greybus/usb.c b/drivers/staging/greybus/usb.c index 475f24f20..ea6c0800c 100644 --- a/drivers/staging/greybus/usb.c +++ b/drivers/staging/greybus/usb.c @@ -105,8 +105,29 @@ static int hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, size_t response_size; int ret; - /* FIXME: handle unspecified lengths */ - response_size = sizeof(*response) + wLength; + /* + * Several USB hub class requests have a response length that is + * fixed by the request type rather than by wLength (which may be + * zero, or otherwise smaller than the actual data the module will + * return). Make sure we always allocate enough room for those. + */ + switch (typeReq) { + case GetHubDescriptor: + response_size = sizeof(*response) + + sizeof(struct usb_hub_descriptor); + break; + case GetHubStatus: + response_size = sizeof(*response) + + sizeof(struct usb_hub_status); + break; + case GetPortStatus: + response_size = sizeof(*response) + + sizeof(struct usb_port_status); + break; + default: + response_size = sizeof(*response) + wLength; + break; + } operation = gb_operation_create(dev->connection, GB_USB_TYPE_HUB_CONTROL, @@ -126,10 +147,12 @@ static int hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, if (ret) goto out; - if (wLength) { + if (response_size > sizeof(*response)) { + size_t data_size = response_size - sizeof(*response); + /* Greybus core has verified response size */ response = operation->response->payload; - memcpy(buf, response->buf, wLength); + memcpy(buf, response->buf, data_size); } out: gb_operation_put(operation); -- 2.53.0