From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9411ACA9EC0 for ; Mon, 28 Oct 2019 16:08:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6602821721 for ; Mon, 28 Oct 2019 16:08:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572278902; bh=KO98teaZoJzpBGjKhPj74o8GBsUooaEn+Fz7oAV4mso=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=1SJH+cHbV0RQ1Ed5rSs3KF40kZMweP9O9ValoGBZugS798rDRyhS9XCXr35PGQQ9F rv4jI0kdeldy9Eo0SImcC+DAOHMXk98Wth7tiUJftSSIORj38/m62i+FKT5UIzrUQE 2psYZOqzeY6cop/O6QEgiOlKR+Fqvq2cUoOXiVl4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390805AbfJ1QIV (ORCPT ); Mon, 28 Oct 2019 12:08:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:36528 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730787AbfJ1QIV (ORCPT ); Mon, 28 Oct 2019 12:08:21 -0400 Received: from localhost (100.50.158.77.rev.sfr.net [77.158.50.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B6AC4208C0; Mon, 28 Oct 2019 16:08:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572278901; bh=KO98teaZoJzpBGjKhPj74o8GBsUooaEn+Fz7oAV4mso=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Zi+UV2opPO4w8Il/d4xPqd9M9G6rXGnkiPUlR704ROKDQtKfv8ZeE8q/D/io5eAW2 ZC9eqqPZx1ckO8K+Nv8r9TsDHAS14MeF+Qiy080iER1vh+mgPqwj0sCq2w+WHs1ho4 9HfeeNQcSbX+SkbxmTI+zcnxYswSbflMRfClTxrQ= Date: Mon, 28 Oct 2019 17:08:18 +0100 From: Greg KH To: Alan Stern , Felipe Balbi Cc: Jacky.Cao@sony.com, andreyknvl@google.com, chunfeng.yun@mediatek.com, USB list , syzkaller-bugs@googlegroups.com Subject: Re: [PATCH] USB: gadget: Reject endpoints with 0 maxpacket value Message-ID: <20191028160818.GA257088@kroah.com> References: <00000000000030af530595acdd8b@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org On Mon, Oct 28, 2019 at 10:54:26AM -0400, Alan Stern wrote: > Endpoints with a maxpacket length of 0 are probably useless. They > can't transfer any data, and it's not at all unlikely that a UDC will > crash or hang when trying to handle a non-zero-length usb_request for > such an endpoint. Indeed, dummy-hcd gets a divide error when trying > to calculate the remainder of a transfer length by the maxpacket > value, as discovered by the syzbot fuzzer. > > Currently the gadget core does not check for endpoints having a > maxpacket value of 0. This patch adds a check to usb_ep_enable(), > preventing such endpoints from being used. > > As far as I know, none of the gadget drivers in the kernel tries to > create an endpoint with maxpacket = 0, but until now there has been > nothing to prevent userspace programs under gadgetfs or configfs from > doing it. > > Signed-off-by: Alan Stern > Reported-and-tested-by: syzbot+8ab8bf161038a8768553@syzkaller.appspotmail.com > CC: > > --- > > > [as1925] > > > drivers/usb/gadget/udc/core.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > Index: usb-devel/drivers/usb/gadget/udc/core.c > =================================================================== > --- usb-devel.orig/drivers/usb/gadget/udc/core.c > +++ usb-devel/drivers/usb/gadget/udc/core.c > @@ -98,6 +98,17 @@ int usb_ep_enable(struct usb_ep *ep) > if (ep->enabled) > goto out; > > + /* UDC drivers can't handle endpoints with maxpacket size 0 */ > + if (usb_endpoint_maxp(ep->desc) == 0) { > + /* > + * We should log an error message here, but we can't call > + * dev_err() because there's no way to find the gadget > + * given only ep. > + */ > + ret = -EINVAL; > + goto out; > + } > + > ret = ep->ops->enable(ep, ep->desc); > if (ret) > goto out; > Felipe, I can take this now in my tree if I can get an ack. thanks, greg k-h