mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, Bin Yu <byu@xidian.edu.cn>,
	Cheng Wen <wencheng@xidian.edu.cn>
Subject: Re: [PATCH] usb: usbtest: prevent divide by zero in simple_io() with zero length
Date: Fri, 16 Oct 2026 10:49:42 -0400	[thread overview]
Message-ID: <5287f274-2130-445f-a67b-d12bd7ee3a2e@rowland.harvard.edu> (raw)
In-Reply-To: <20261016072750.34256-1-25031212351@stu.xidian.edu.cn>

On Fri, Oct 16, 2026 at 03:27:50PM +0800, YuanZhe Liu wrote:
> A divide error oops was observed in simple_io():
> 
> 	usbtest 1-1:1.0: TEST 3:  write/1 0..0 bytes 16307 times
> 	Oops: divide error: 0000 [#1] SMP KASAN
> 	RIP: 0010:simple_io+0x2c4/0x540 drivers/usb/misc/usbtest.c:497
> 
> The variable-length tests (test 3 and test 4) compute the next URB
> size with "len %= max", where max is the original
> urb->transfer_buffer_length. However, when a zero-length transfer is
> requested (param->length == 0), simple_alloc_urb() still returns a valid
> URB with transfer_buffer_length set to 0. On the first vary update,
> "len %= max" divides by zero and the kernel oopses.
> 
> Commit 564e69893c63 ("USB: usbtest: prevent a divide by zero bug") added
> the equivalent zero check to alloc_sglist(), which covers the
> scatterlist tests (test 7/8), but the single-URB variable-length path in
> simple_io() was left unprotected.
> 
> Fix this by returning -EINVAL early from simple_io() when vary is
> requested but max is zero, so the divide by zero never occurs.
> Zero-length transfers without vary remain valid for the other callers of
> simple_io().
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Cc: stable@vger.kernel.org
> Co-developed-by: Bin Yu <byu@xidian.edu.cn>
> Signed-off-by: Bin Yu <byu@xidian.edu.cn>
> Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
> Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
> Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
> ---

Reviewed-by: Alan Stern <stern@rowland.harvard.edu>

>  drivers/usb/misc/usbtest.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
> index 8759df49be28..e2f5e6be353a 100644
> --- a/drivers/usb/misc/usbtest.c
> +++ b/drivers/usb/misc/usbtest.c
> @@ -466,6 +466,9 @@ static int simple_io(
>  	int			retval = 0;
>  	unsigned long		expire;
>  
> +	if (vary && !max)
> +		return -EINVAL;
> +
>  	urb->context = &completion;
>  	while (retval == 0 && iterations-- > 0) {
>  		init_completion(&completion);
> -- 
> 2.34.1

      reply	other threads:[~2026-10-16 14:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16  7:27 YuanZhe Liu
2026-10-16 14:49 ` Alan Stern [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5287f274-2130-445f-a67b-d12bd7ee3a2e@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=25031212351@stu.xidian.edu.cn \
    --cc=byu@xidian.edu.cn \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=wencheng@xidian.edu.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®