Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3085529pxa; Tue, 25 Aug 2020 11:01:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKXSF6YRNo+USRSPSRJCjxSGOntxsvMm7wPxImdi1MDeFsDKRJKsadCYBikA2XlVOzq7fz X-Received: by 2002:a17:906:6cd:: with SMTP id v13mr11615212ejb.307.1598378490780; Tue, 25 Aug 2020 11:01:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598378490; cv=none; d=google.com; s=arc-20160816; b=KfTxR1Z9Yokv2O8vX3izZV94Sue8CibOhqLzkic3tQ0/q7Dsb8l2g0R1h3qNTHDvJ8 JUvvd7zxyU9VZg1HnE29qE2U0vRFT7fmHsI4UTu7+PYQkXQxjGtQqT7MSUEAOloXagE0 34RnNyAuwIcr8Td2EN+nYbj13cKlmjhFPvpJASnmH+3LrYDjyLbP+i1x1cxC6m9SVH6u nWhCBqR7nIgVV9cE/JuBOJzGAOdLsrnyEI33TsrIVh8dUWB+wnzz4tot1f0xabUEaa0x 7vO7vPDdqk+a2cbUYVH6KPCLzYYG4QqkKGa3MgGGbhQiSEHtntviKIAOYBz5KdJHe4X8 WRUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=0Ba80wNWhjqtBuCuUmKpijISvcor87h/w5K5rmE2wlg=; b=kstNtq7HRERW3Z+xf9AjPouvtctXPfYQ2cvNf1Ltkc+k96lcimwZcmed++FGXGy7n+ RI29jK0o6DIM5TLhJQqxb6za9r2hVpLQ2+/VSy9DKAbPG/pjwSITA2oqjrmqulQCwFPY RZRwcYjTcqBTAA0iiCG9GN0eFOvIj2BuvsIFNTXyAxmrMWLeAzk7uph540meLj+M46Hs tL9tFmPtfF1yoxvV5usmW0Fc2kIEfQfimQn7qsQi6OGDfGsLXpkIZ5E9vM9N4WYKbPUQ tOV5Mo18Q7WN2Per8/3zlpssK1y8GGV9F8CPAcDsfmsOKPqbKrAEOAoekBgIQ8/gibV4 1XnA== 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 g16si9525806ejf.103.2020.08.25.11.01.06; Tue, 25 Aug 2020 11:01:30 -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 S1726119AbgHYSA2 (ORCPT + 99 others); Tue, 25 Aug 2020 14:00:28 -0400 Received: from netrider.rowland.org ([192.131.102.5]:35865 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726158AbgHYSA1 (ORCPT ); Tue, 25 Aug 2020 14:00:27 -0400 Received: (qmail 375693 invoked by uid 1000); 25 Aug 2020 14:00:26 -0400 Date: Tue, 25 Aug 2020 14:00:26 -0400 From: Alan Stern To: yanfei.xu@windriver.com Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] USB: core: limit access to rawdescriptors which were not allocated Message-ID: <20200825180026.GA375466@rowland.harvard.edu> References: <20200825161659.19008-1-yanfei.xu@windriver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200825161659.19008-1-yanfei.xu@windriver.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 26, 2020 at 12:16:59AM +0800, yanfei.xu@windriver.com wrote: > From: Yanfei Xu > > When using systemcall to read the rawdescriptors, make sure we won't > access to the rawdescriptors never allocated, which are number > exceed the USB_MAXCONFIG. > > Reported-by: syzbot+256e56ddde8b8957eabd@syzkaller.appspotmail.com > Signed-off-by: Yanfei Xu > --- > drivers/usb/core/sysfs.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c > index a2ca38e25e0c..1a7a625e5f55 100644 > --- a/drivers/usb/core/sysfs.c > +++ b/drivers/usb/core/sysfs.c > @@ -895,7 +895,8 @@ read_descriptors(struct file *filp, struct kobject *kobj, > * configurations (config plus subsidiary descriptors). > */ > for (cfgno = -1; cfgno < udev->descriptor.bNumConfigurations && > - nleft > 0; ++cfgno) { > + nleft > 0 && > + cfgno < USB_MAXCONFIG; ++cfgno) { > if (cfgno < 0) { > src = &udev->descriptor; > srclen = sizeof(struct usb_device_descriptor); This is not the right way to fix the problem. Instead, we should make sure that udev->descriptor.bNumConfigurations is always <= USB_MAXCONFIG. That's what this code in usb_get_configuration() is supposed to do: int ncfg = dev->descriptor.bNumConfigurations; ... if (ncfg > USB_MAXCONFIG) { dev_warn(ddev, "too many configurations: %d, " "using maximum allowed: %d\n", ncfg, USB_MAXCONFIG); dev->descriptor.bNumConfigurations = ncfg = USB_MAXCONFIG; } If you want to fix the bug, you need to figure out why this isn't working. Alan Stern