linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleksandr Natalenko <oleksandr@natalenko.name>
To: syzbot <syzbot+9b57a46bf1801ce2a2ca@syzkaller.appspotmail.com>,
	Alan Stern <stern@rowland.harvard.edu>
Cc: benjamin.tissoires@redhat.com, jikos@kernel.org,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-usb@vger.kernel.org, mkubecek@suse.cz,
	syzkaller-bugs@googlegroups.com
Subject: Re: [syzbot] WARNING in hid_submit_ctrl/usb_submit_urb
Date: Mon, 30 Aug 2021 21:22:39 +0200	[thread overview]
Message-ID: <2760703.iRigd37PT7@natalenko.name> (raw)
In-Reply-To: <20210819195300.GA8613@rowland.harvard.edu>

Hello.

On čtvrtek 19. srpna 2021 21:53:00 CEST Alan Stern wrote:
> On Thu, Aug 19, 2021 at 10:35:11AM -0700, syzbot wrote:
> > Hello,
> > 
> > syzbot has tested the proposed patch but the reproducer is still
> > triggering an issue: WARNING in hid_submit_ctrl/usb_submit_urb
> > 
> > cm6533_jd 0003:0D8C:0022.0001: submit_ctrl: maxpacket 64 len 0 padlen 0
> > ------------[ cut here ]------------
> > usb 1-1: BOGUS control dir, pipe 80000280 doesn't match bRequestType a1
> 
> Ah.   The padding code doesn't add anything if the length is
> already a multiple of the maxpacket value, and of course 0 is such
> a multiple.
> 
> The following simplified variant of Michal's patch should fix the
> problem.
> 
> Alan Stern
> 
> #syz test:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
> 794c7931a242
> 
> Index: usb-devel/drivers/hid/usbhid/hid-core.c
> ===================================================================
> --- usb-devel.orig/drivers/hid/usbhid/hid-core.c
> +++ usb-devel/drivers/hid/usbhid/hid-core.c
> @@ -377,27 +377,23 @@ static int hid_submit_ctrl(struct hid_de
>  	len = hid_report_len(report);
>  	if (dir == USB_DIR_OUT) {
>  		usbhid->urbctrl->pipe = usb_sndctrlpipe(hid_to_usb_dev(hid), 
0);
> -		usbhid->urbctrl->transfer_buffer_length = len;
>  		if (raw_report) {
>  			memcpy(usbhid->ctrlbuf, raw_report, len);
>  			kfree(raw_report);
>  			usbhid->ctrl[usbhid->ctrltail].raw_report = NULL;
>  		}
>  	} else {
> -		int maxpacket, padlen;
> +		int maxpacket;
> 
>  		usbhid->urbctrl->pipe = usb_rcvctrlpipe(hid_to_usb_dev(hid), 
0);
>  		maxpacket = usb_maxpacket(hid_to_usb_dev(hid),
>  					  usbhid->urbctrl->pipe, 0);
> -		if (maxpacket > 0) {
> -			padlen = DIV_ROUND_UP(len, maxpacket);
> -			padlen *= maxpacket;
> -			if (padlen > usbhid->bufsize)
> -				padlen = usbhid->bufsize;
> -		} else
> -			padlen = 0;
> -		usbhid->urbctrl->transfer_buffer_length = padlen;
> +		len += (len == 0);	/* Don't allow 0-length reports */
> +		len = round_up(len, maxpacket);
> +		if (len > usbhid->bufsize)
> +			len = usbhid->bufsize;
>  	}
> +	usbhid->urbctrl->transfer_buffer_length = len;
>  	usbhid->urbctrl->dev = hid_to_usb_dev(hid);
> 
>  	usbhid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir;

I've tried both Michal's patch as well as this one, and both work for me, 
hence feel free to add this:

Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>

once the fix is submitted.

Thanks!

-- 
Oleksandr Natalenko (post-factum)



  parent reply	other threads:[~2021-08-30 19:23 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-18 15:46 [syzbot] WARNING in hid_submit_ctrl/usb_submit_urb syzbot
2021-08-18  9:14 ` syzbot
2021-08-18 18:49   ` Alan Stern
2021-08-18 20:13     ` syzbot
2021-08-19 15:26       ` Alan Stern
2021-08-19 17:35         ` syzbot
2021-08-19 19:53           ` Alan Stern
2021-08-20  0:40             ` syzbot
2021-08-20 14:06               ` Alan Stern
2021-08-24 11:53                 ` Jiri Kosina
2021-08-24 12:34                   ` Benjamin Tissoires
2021-08-31  9:51                   ` Benjamin Tissoires
2021-08-31 13:34                     ` Alan Stern
2021-08-31 19:53                       ` Jiri Kosina
2021-09-01 15:38                     ` Alan Stern
2021-09-01 15:51                       ` Michal Kubecek
2021-08-24 11:50             ` Michal Kubecek
2021-08-30 19:22             ` Oleksandr Natalenko [this message]
2021-08-18 19:01   ` Alan Stern
2021-08-18 19:39 ` syzbot

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=2760703.iRigd37PT7@natalenko.name \
    --to=oleksandr@natalenko.name \
    --cc=benjamin.tissoires@redhat.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mkubecek@suse.cz \
    --cc=stern@rowland.harvard.edu \
    --cc=syzbot+9b57a46bf1801ce2a2ca@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    /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;
as well as URLs for NNTP newsgroup(s).