Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1095404pxk; Thu, 3 Sep 2020 23:40:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnprv/BM3gkyIyM7N+GHpgQFT8Mltj6u4cOOOsyN2p9WlKJXy0cgvuZOVE/uLItqVmmJsn X-Received: by 2002:aa7:d30b:: with SMTP id p11mr1917649edq.80.1599201612491; Thu, 03 Sep 2020 23:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599201612; cv=none; d=google.com; s=arc-20160816; b=q27+W1GZy1oyOsg+T8MBLQmzEBEgiwISCsDG+6NG14VWDDTKXRSEA4Ue6ucIHH3ZZs 9fuiSRLNWjBivTSgSihS4NJu+sc+CEJzy7g0we34/h1VQZqXGQOK5wAlJbnmDkoJAVNR LeKXA1fuj6XKBqPi1foeYTPZS4mLXgpTd83gAcz4uI3W7EkqYCq5uDyPLPdCDXRwpk85 DGRKlj7QKOjUWVAet1we9THwrHaB8QvVOCuI2I6OAQxNj94orlMkKibyGJ2USOR3kA+u mUJMXhe4EDkz20ndRu6hPcRzURIYOhMqP9r7rAuztVW2bzIYkt0YcCUvzcY4Smfa30Mj HPKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=5A9DlW0oqC8kO+S36C5RYkod45pqK5Qc/6AEilQISqY=; b=qhccRsbUggTFHcs7wbxPy/HyMc2yQARvB6H7g+sCAyNhQqYqauH31rgS+gwRz+HXZC Z1Q6ViwGkhvQL8Tq/CquDJss4NvBF6kC7TJak/yRc+Ysj7jP8t63oyN4VTxOhfrfcGRt 0vYSlPc8DQNLJMCi0ZKhMRxi92ycD+dM9O/CmUAvO1EIgI5+VO5Yp2NwzdzfpyVjBiB4 VTm7RxEzg23tA+5XIlXS77TnI+Ja/63CEpbg5TjLONjtqbSsdrZkSMYtTn+2n22qpUdN yq92GnVnjixi+xGOLu44uXnfZSiJbhTFyCnh+/o/QzUDJO0ovDI/Pm80fYk9hT3HWpbD HStg== 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 e10si3497655ejk.32.2020.09.03.23.39.49; Thu, 03 Sep 2020 23:40:12 -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 S1728669AbgIDGjL (ORCPT + 99 others); Fri, 4 Sep 2020 02:39:11 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:10811 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726251AbgIDGjL (ORCPT ); Fri, 4 Sep 2020 02:39:11 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id A6DF026C41212103A2AA; Fri, 4 Sep 2020 14:39:05 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Fri, 4 Sep 2020 14:38:59 +0800 From: Zeng Tao To: CC: Zeng Tao , stable , "Alan Stern" , chenqiwu , , Subject: [PATCH] usb: core: fix slab-out-of-bounds Read in read_descriptors Date: Fri, 4 Sep 2020 14:37:44 +0800 Message-ID: <1599201467-11000-1-git-send-email-prime.zeng@hisilicon.com> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/usb/core/sysfs.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index a2ca38e..8d13419 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c @@ -889,7 +889,11 @@ read_descriptors(struct file *filp, struct kobject *kobj, 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). @@ -914,6 +918,7 @@ read_descriptors(struct file *filp, struct kobject *kobj, off -= srclen; } } + usb_unlock_device(udev); return count - nleft; } -- 2.8.1