From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) (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 B880D379C57 for ; Sat, 8 Aug 2026 08:19:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786177179; cv=none; b=mMr7qhkvCdhV3bHFBzIIOXCCuN1q1E2kdX7gEjvaKNiSwskO0qUUpemQvXbmR26AMchJOMTFYDpCMfJfBeEdfjXXqH/DbugkgTzoqQuwpT/2g27aB2VoO712FFz5UiKjBNZzvB/6PTNvZDeesEe0VelJkp/gIoOJZxSfKsIBjv0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786177179; c=relaxed/simple; bh=5OyS1iYeKL7u7M4vZYiR7Emzne9AA2JbDEQkYH6bFd0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PkSGUMkOXceVkMWosM23gGeE1WYCynkPL5x11kv29Aew/yQY0G7Z1fQu6RKdB56dAr/SEIgWwIsT4L0aViclw5Y0mBpb0bjSUwpTWYpuOP8nAeKK7s3hLHZ3ekG+vW8n9IRjOrcc8zKc5CGdhr3ocROBE3UqnEFRb+kBdS36VTI= 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=GWyUnNdE; arc=none smtp.client-ip=209.85.222.182 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="GWyUnNdE" Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-92e5c92c389so13830985a.3 for ; Sat, 08 Aug 2026 01:19:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786177174; x=1786781974; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=0XHpkyOFc3Yjfcej75lDn7ECxMF/ltH1IpONNgmjGAQ=; b=GWyUnNdEO8qmklTS4DACABpoWKMSu3DrVyxQAU/c+SvXsOW21GHJk1P7RADGICTv2T jJk2w3G4Wci7sMd5ghOhd2IZG/UxkqZG2S96Z6hV9rsSPuOKjmQS4ryzAgXAICXsbgQY hfcNyT0oZVTauliBErMdyySg/iwq1DnXlk7I4JDyX6E2U2bDXaTFdy3qSoeooaXEDXLl Ja8aHLfeQLjeIsRDDZ7Pw6jTuT/L/sKBGE09DZOqWJt2PkiFVPbYfw659bi4AA+dqs1a Z0qi4bE4Y18b1QmdEeFttKQp3WrDKB+LPmdlq553KQowiI2AUERHhQERKNCY+0aQVaiW z+xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786177174; x=1786781974; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0XHpkyOFc3Yjfcej75lDn7ECxMF/ltH1IpONNgmjGAQ=; b=SF/B6jf0/ZYuZaSmMwSgH+tHbZaWsoY8pDpKspHDLHIzYY/PWxx7Kvn5e81n30KAjU +ivVhkP6lwMPVQDcvv4SW1LZ9p/W6T69dMHNXw1vDoHxEfnUyWgZ+8ybD+uW0fAhjgl6 keJuXYRUpaw5j0ye5yGMDwyU1BIypk7d1qE0tABa3V6Ww07ncpCtfYSlE+KsIxBkFeuu DWv4vhqAoPbLvnJHi+jvIGAt4cGM8VLbW0GxGgj3Yosqf4ZiIAqHVq+f9Ac21S9IUJ/4 eEOICIPyoa7vsV83MMggzutavoiMcUGQimJFeeyA1AxKtaXu9t/T2oqRehiWBWvgNkyI NA4g== X-Forwarded-Encrypted: i=1; AHgh+RofbtMPfpSjugffCNlCNVIIsuEDRoBy/5pla1icT5NXFxwogGf+0CBT+jopRUvGD6LZ7iUnvLHYMyWvAjg=@vger.kernel.org X-Gm-Message-State: AOJu0YwB8V5ivlYeM7Osq7iOnyrav5yfeTynqCyVwW/JVCrrgO8siWWf CAOxlramdjqpDvt/HwQtVThvB9VzbX5OodlmOxcq3dTqGyNAxp53Qic2 X-Gm-Gg: AR+sD12/YftPws7Usb6DgK51YzopJjj5nOcTVwDhRa4fJgyw/m5JXJBEPnmLaMQlrUd 5RR3lZySdou534IbeD/OmIUlupy57TiTFLMKvPlPNYixFwh9IH3KfEw4SrAu7fHWUhjiD1qbIOt wqPOMb9QB/6tt21EXEL+mWKzUY7dIFIV0GZaW9l1uuki/LIkFnJFWQbYla8Z6fydY9x9jTGwGzi erXU5hLhMXVS/Z3BSaPPHnB0crXOwBLYkcKoQEhyYwV8SfG8dcTzoFDI6/7FwiqanFpjvTauZ4h dFPcaYfYv4FFxKmgDzqhlnDS2hx49yMR7WwImloLstRbapvpu0a+7+tWB4mJISTNfxH3TPyPrC1 Ge9KjEmFj8Qq7cdhQ07BUHMOae+B5YmdNHdNDWxyL4tX6MAwf/aslVPsZ7wGZ5zzEh1uAbf11ew Z0zUdvFMIDwcHsiKBMmeIvIgBnpmsg8QWaf+Jhyn8YmhcYdlSEbSmHpA== X-Received: by 2002:a05:620a:a113:b0:92e:2c3a:a15c with SMTP id af79cd13be357-9364922a47bmr2817911385a.29.1786177174375; Sat, 08 Aug 2026 01:19:34 -0700 (PDT) Received: from localhost ([172.216.11.43]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9366e279f0esm324796585a.38.2026.08.08.01.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Aug 2026 01:19:33 -0700 (PDT) Date: Sat, 8 Aug 2026 11:19:27 +0300 From: Dan Carpenter To: Aditya Chari S Cc: Johan Hovold , Alex Elder , Greg Kroah-Hartman , greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] greybus: usb: fix response buffer size for fixed-length hub requests Message-ID: References: <20260803010248.339120-1-adi25charis@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260803010248.339120-1-adi25charis@gmail.com> On Mon, Aug 03, 2026 at 06:32:48AM +0530, Aditya Chari S wrote: > 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. What is the impact? Does it truncate the buffer or does it lead to a buffer overflow? Presumably Greg knows off the top of his head since he maintains USB, but I'm not familiar with it. Which function does the memcpy() so I can check? > > 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. > It sort of matches rh_call_control() except GetPortStatus here is always 8 where in rh_call_control() it's sometimes 4, sometimes 8. > 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. We disabled USB support in commit a96493560cd1 ("greybus: usb: disable protocol driver") which was 11 year ago now. I almost doubt it's ever going to be fixed. People are probably using out of tree versions of this driver. > > 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 */ So the story here we are using AI to try to address this FIXME... We are still assigning: request->wLength = cpu_to_le16(wLength); Where is that used? This kind of gets back to the impact question. In rh_call_control() we allocate the buffer with: /* * tbuf should be at least as big as the * USB hub descriptor. */ tbuf_size = max_t(u16, sizeof(struct usb_hub_descriptor), wLength); tbuf = kzalloc(tbuf_size, mem_flags); struct usb_hub_descriptor is larger than the other two sizes. Here, now, we have changed it to allocate a buffer which is potentially smaller than request->wLength. Is that an issue? Greg probably knows the answer off the top of his head again for this but I'm a USB newbie. > - if (wLength) { > + if (response_size > sizeof(*response)) { > + size_t data_size = response_size - sizeof(*response); > + > /* Greybus core has verified response size */ Where does this verification happen? > response = operation->response->payload; > - memcpy(buf, response->buf, wLength); > + memcpy(buf, response->buf, data_size); > } regards, dan carpenter