Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3300293pxk; Mon, 21 Sep 2020 10:03:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxddTISQK9EzEIT+5uTIrLD/qhkJ7ADd3dON9QDtGZpI2hRgfJ4ErWd56RbZ3PXEP2nDSgV X-Received: by 2002:a17:906:4b41:: with SMTP id j1mr401378ejv.1.1600707798016; Mon, 21 Sep 2020 10:03:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600707798; cv=none; d=google.com; s=arc-20160816; b=qzPtUF7o55MsNOgg5eT0FWKKVJfHKyuQAoWPR4GeH+7gAFgmGLco5Cl7y9JRFa6jvl T7zod7na6Qa7KW5QmsTPTLauZak/B/JiAv5G3gwHJCdseHVG7m/GTnmkyMRV7JE5xRQt G5X2kcTrSShc4NzDnZw+Rvys1liKIaoIsnhQ8IMvvUn93Vkq3JW9lNJZGf46ZKJByK99 wZgMd1AfY0e7pHf0i23j/JV1VW1YBVI0lV/0Ma27a0tIBFM/Ax25u3qF0ws3bLexR7vX gqeMk0LpMb4ZFTlnk72TR9RKoirkrnlYbVSCdq0E5sSWQixTT3iODHx7apOxZEteXCaW 9ThA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nSL7rrNQ0jNOIHnLIfY6pzGeNzf27kuUP+f63hACSPM=; b=NYk1OEBlkTVVuAYzI+uCWPQKURt8Clj7i5mhW3HeMOyEYbICKcyNxVnvXZaUapFFve I3e7EUsJX0ovC4LeLL87AfKE1nQnIvNxA9EKpbNeqLG5ST1ubplOVKZKSvNMX/QvmLdw d1xnN3BHlQD4QzYBBPH1RuFsgEn/Wuo1k4wEkMblho82cBUI7fVdyoyGOkJy9LOQCsAK Ty6j/AVGofviYw7f0613j/Th9rbcfU2m1NABSE3VIOEoEw2oXqcW0bNH/WHl0PcTbDOr lI+tMmV7/R2M9sLRFbj0t8y/FCpzM+NH8yXtM0mkcULSC4NduwyurIGVA+0o8B6GLRR0 vGyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="A4xTSaN/"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si8636947edx.169.2020.09.21.10.02.53; Mon, 21 Sep 2020 10:03:18 -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; dkim=pass header.i=@kernel.org header.s=default header.b="A4xTSaN/"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730402AbgIURBv (ORCPT + 99 others); Mon, 21 Sep 2020 13:01:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:40642 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728075AbgIUQjH (ORCPT ); Mon, 21 Sep 2020 12:39:07 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 3D3702399C; Mon, 21 Sep 2020 16:39:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706341; bh=PU7N8QyiDXDa2AM2iHqNtGwW+FFE/9PP90fqZpQAWqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A4xTSaN/81xddpb6QhmgHCF752Q7yFA/q4U3vc74WiVMSIa7fseE5CkkgU+IS+o1b MHnjPr16ZSa2BQeWuxzwzuEfNl2mMHcA8kq6Fh46jiYjSlNk1vDtbW9qyBt0vJ/zZa diUOpf80OsGK1Ma+LQMBMVHhRB4iLKmaZjz/VZQ4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alan Stern , syzbot+256e56ddde8b8957eabd@syzkaller.appspotmail.com, Zeng Tao Subject: [PATCH 4.14 54/94] usb: core: fix slab-out-of-bounds Read in read_descriptors Date: Mon, 21 Sep 2020 18:27:41 +0200 Message-Id: <20200921162038.038774891@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162035.541285330@linuxfoundation.org> References: <20200921162035.541285330@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zeng Tao commit a18cd6c9b6bc73dc17e8b7e9bd07decaa8833c97 upstream. The USB device descriptor may get changed between two consecutive enumerations on the same device for some reason, such as DFU or malicius device. In that case, we may access the changing descriptor if we don't take the device lock here. The issue is reported: https://syzkaller.appspot.com/bug?id=901a0d9e6519ef8dc7acab25344bd287dd3c7be9 Cc: stable Cc: Alan Stern Reported-by: syzbot+256e56ddde8b8957eabd@syzkaller.appspotmail.com Fixes: 217a9081d8e6 ("USB: add all configs to the "descriptors" attribute") Signed-off-by: Zeng Tao Link: https://lore.kernel.org/r/1599201467-11000-1-git-send-email-prime.zeng@hisilicon.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/sysfs.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c @@ -865,7 +865,11 @@ read_descriptors(struct file *filp, stru size_t srclen, n; int cfgno; void *src; + int retval; + retval = usb_lock_device_interruptible(udev); + if (retval < 0) + return -EINTR; /* The binary attribute begins with the device descriptor. * Following that are the raw descriptor entries for all the * configurations (config plus subsidiary descriptors). @@ -890,6 +894,7 @@ read_descriptors(struct file *filp, stru off -= srclen; } } + usb_unlock_device(udev); return count - nleft; }