Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1144950pxv; Fri, 9 Jul 2021 19:26:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxv69hfEea5PWTFI9rwiWcjeWoPx/l42mABidbVYSs+RQGTAODFJMaxu1wSuO/xDdjPL9fE X-Received: by 2002:a17:906:7009:: with SMTP id n9mr41312112ejj.66.1625883983802; Fri, 09 Jul 2021 19:26:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625883983; cv=none; d=google.com; s=arc-20160816; b=EeGtoefNjjZ4mT32k+iz1vOJmdB1OO8M11Fn8vZ7npadxeUeMnUCNGe8bnlrZgkG3f iOU/+0fwjU+o5Ya/UpLwLW5e3mPKH9H2AWVyC5inxUnQY9fbvcHt6wkCaMKt/lvDBDvL 5AAffhjqt4P+cshX6hlcN6cBEnEs4+SXJrY31NmdMPfy2n8zNGlfiSIshtiXAwML1p4O Qs51sffwIxGyPNvR4iWq6a4Kq89W1sIzcfQXXaFkgn+7r5SqvNbKaCiX/v2e70btFvM1 qAA3QYG72X+zY2DNBCPmKy6yNse2ETh+yd2hwG8pIFiy29tQ06o2l406sJV0iRJOuM07 djyA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sywKC+kP3d7jytMxfALCBI2ek2OLnXe4gPm/HKMlg4w=; b=Z52Z0LTPsyk5Gj9/BTT4vAdT8px2HQpBeDWCxp7hJbf2YItrqk0jP+SBTD6pnYTEiP bdYh8Ol6PgH7ZgUP3gXWnBkgkpYRGbrMoJ9vVXlTX/BPpAiXfPVMWAfQuR3maTqTj1qc VACUyWsC//G/1ze0AAvplc2qyM+gr2BdM7E0o+y7fPzB0dZNBsqXMj2paXUT9oGiXgLK 7DdHSkqYAxmuwqkAXz8CwecEHlMw7Lv9+VrUC9y91kSQ7ymMAYc0qpXe2DAwWsk/u6Yt 7h6iiXmCFcaAZI3dC+Etbbotf23n+J/2dpZnLWF3Zk01dzhkypYkLd5cWBzBsY9LsdK6 G7Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SA11PgHY; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hs42si8525806ejc.477.2021.07.09.19.26.01; Fri, 09 Jul 2021 19:26:23 -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=k20201202 header.b=SA11PgHY; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233057AbhGJC1H (ORCPT + 99 others); Fri, 9 Jul 2021 22:27:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:42616 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233403AbhGJCZ4 (ORCPT ); Fri, 9 Jul 2021 22:25:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 209DA613E8; Sat, 10 Jul 2021 02:23:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883792; bh=TOcl3h8y0zUeqb5SQcKCPtz9ZLYgerjxGs4W3oevh8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SA11PgHYn/4gsLZQfChljmbDBgRn0WWKyyTYvONZdYAjdiEKJAxZ/vXWpc64E9qmH V6GULPOLSTYmudE1Ffr6triSw+zlVFHqQ+Fmp9N8u20hNOlw/E16MiJu8mIIgBKxS+ +dJ5gb9KneLCQGwXEcPa/rrgLjNhPjn4+fFywRR0zu/93ksHAX8nszKtAgW9/bRVO8 KFq23ZpcAHfVYWRojqggg+tA8rlP1Z+Whq3rpWur3dJRps6QXS8r/6PEAyCtUqrimp xDHTiMJBCbOEAVbnWewGNjPts0YcRfUTLaH75EOrl2mzo3U/YebmosThJMNL/qriLZ Oq0u8OHKrVZ/w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Alan Stern , Johan Hovold , syzbot+7dbcd9ff34dc4ed45240@syzkaller.appspotmail.com, Greg Kroah-Hartman , Sasha Levin , linux-usb@vger.kernel.org Subject: [PATCH AUTOSEL 5.12 057/104] USB: core: Avoid WARNings for 0-length descriptor requests Date: Fri, 9 Jul 2021 22:21:09 -0400 Message-Id: <20210710022156.3168825-57-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710022156.3168825-1-sashal@kernel.org> References: <20210710022156.3168825-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alan Stern [ Upstream commit 60dfe484cef45293e631b3a6e8995f1689818172 ] The USB core has utility routines to retrieve various types of descriptors. These routines will now provoke a WARN if they are asked to retrieve 0 bytes (USB "receive" requests must not have zero length), so avert this by checking the size argument at the start. CC: Johan Hovold Reported-and-tested-by: syzbot+7dbcd9ff34dc4ed45240@syzkaller.appspotmail.com Reviewed-by: Johan Hovold Signed-off-by: Alan Stern Link: https://lore.kernel.org/r/20210607152307.GD1768031@rowland.harvard.edu Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/core/message.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index 30e9e680c74c..4d59d927ae3e 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c @@ -783,6 +783,9 @@ int usb_get_descriptor(struct usb_device *dev, unsigned char type, int i; int result; + if (size <= 0) /* No point in asking for no data */ + return -EINVAL; + memset(buf, 0, size); /* Make sure we parse really received data */ for (i = 0; i < 3; ++i) { @@ -832,6 +835,9 @@ static int usb_get_string(struct usb_device *dev, unsigned short langid, int i; int result; + if (size <= 0) /* No point in asking for no data */ + return -EINVAL; + for (i = 0; i < 3; ++i) { /* retry on length 0 or stall; some devices are flakey */ result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), -- 2.30.2