LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Michal Kubecek <mkubecek@suse.cz>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: syzbot <syzbot+9b57a46bf1801ce2a2ca@syzkaller.appspotmail.com>,
	benjamin.tissoires@redhat.com, jikos@kernel.org,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-usb@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Re: [syzbot] WARNING in hid_submit_ctrl/usb_submit_urb
Date: Tue, 24 Aug 2021 13:50:06 +0200	[thread overview]
Message-ID: <20210824115006.a5zzgxjy6nwakdmg@lion.mk-sys.cz> (raw)
In-Reply-To: <20210819195300.GA8613@rowland.harvard.edu>

[-- Attachment #1: Type: text/plain, Size: 2066 bytes --]

On Thu, Aug 19, 2021 at 03:53:00PM -0400, Alan Stern wrote:
> 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 have also tested this patch on top of 5.14-rc7 on my system and it
does address the original issue (no error/warning messages in kernel log
and communication with the UPS works correctly). So if you are going to
submit the patch formally, feel free to use

Tested-by: Michal Kubecek <mkubecek@suse.cz>

Michal

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  parent reply	other threads:[~2021-08-24 11:50 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-18 15:46 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 [this message]
2021-08-30 19:22             ` Oleksandr Natalenko
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=20210824115006.a5zzgxjy6nwakdmg@lion.mk-sys.cz \
    --to=mkubecek@suse.cz \
    --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=stern@rowland.harvard.edu \
    --cc=syzbot+9b57a46bf1801ce2a2ca@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --subject='Re: [syzbot] WARNING in hid_submit_ctrl/usb_submit_urb' \
    /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

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).