Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp850977pxb; Thu, 19 Aug 2021 12:54:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAxX0DCcAUhl2nlbmawhLrORPVt2eMf1nvvyBnCn+C/IUkqkg4SFm/WC9c7JD5vIn3lnXb X-Received: by 2002:a5d:8e11:: with SMTP id e17mr13090518iod.138.1629402848006; Thu, 19 Aug 2021 12:54:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629402847; cv=none; d=google.com; s=arc-20160816; b=MkTrJL6u5UZ4T9hmOGJRz9xVLSfbd86A+P3K2cQhKS+FkZKYYvIjFKL74WPI1rgRv8 FcMJUgMw/TQGz/fIIcW0r0k2PIzfKUYgW+eD0tqxP14xVHupE42CC8PBTGL7DWu1yus/ +TssRpkf1sqSAGu4xpjfVrYC1bu5N0NfoUx19r0A3GMBZbDYyHnQelEp3TcfGPjyZIf9 h35t7NUZ1Sz+culC+MkmBoMDVN8vw+vKR6heHRileTr8WbT8V56XKQUgofvKPedo/PWi qg/N2qcPXDFjhI3VfIETp4q9drdnbWDSKPz0LjgRBGGSOGeQCmSyau5O2ulwNz0RO1Js bzRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=EjD+HTzv/27M8wMIy0SaHXZYyso9QQ6ZLhWvQ1UYmHI=; b=h39MyiGFaRKQFMKC2aS2RXXSX2cNotvQ7x4Hah7/CRKGhZgj2in7nAG4o1RN9KsS21 lho4IlezWi4bDUcGfVE/mn8uJSolaSBsdyXM4qNGWAs+dNm+C7fS2/BkHe9bT5oRoRz2 auW4RXWPtDctkwUx0ETRXE6zUtgtZQmcMcIzMGf2ybJqG+NeP7F4TwmtRs97OMMUSOi3 D0+90y0xbs6zpVV1VSX2UBbJv6xnpwjH3Nw5Jyz7VaGXzOueBIrARJkoZvaoIw6mZS02 zH8lSv8gzkuLPCgbRZQiebDpOklsgLdFZPRUVFbZHQXaZ+p7KLTWTN75nyGixWMHKrSl 5S7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x10si758654ilg.50.2021.08.19.12.53.56; Thu, 19 Aug 2021 12:54:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234834AbhHSTxn (ORCPT + 99 others); Thu, 19 Aug 2021 15:53:43 -0400 Received: from netrider.rowland.org ([192.131.102.5]:45923 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S231294AbhHSTxi (ORCPT ); Thu, 19 Aug 2021 15:53:38 -0400 Received: (qmail 10514 invoked by uid 1000); 19 Aug 2021 15:53:00 -0400 Date: Thu, 19 Aug 2021 15:53:00 -0400 From: Alan Stern To: syzbot 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 Message-ID: <20210819195300.GA8613@rowland.harvard.edu> References: <20210819152626.GD228422@rowland.harvard.edu> <00000000000009e24705c9ecf9b3@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <00000000000009e24705c9ecf9b3@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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;