Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1143391pxv; Fri, 9 Jul 2021 19:22:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhvD5hq++DKRTFg3/hz23Ls+Czo00AvmIwJg2UtgTB+fv4IPrdffRPBJzvbIyXw6/O8Inb X-Received: by 2002:aa7:de90:: with SMTP id j16mr51102944edv.385.1625883771855; Fri, 09 Jul 2021 19:22:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625883771; cv=none; d=google.com; s=arc-20160816; b=QVs1bI9B66KPlPYDSCmK4DPmM/mkYOmSP0mJge24j3zuwg1tt0veWtWfvaHPR4C+HK SU7DP8NH1cuu8tcEMW4CiDqsANoFwWgByww79Yd0n73YY3x60GsgzFvJWnwzqlDk+H3t Cf5fwzrFb3Hy4s9WXB0p9SelyniepaGX9d83YUag+/6okFCbjrZ7E7xNYkkhOEzL1AKD krpZohBKBkwacmHV1HT5CylGny0hd5jwQ+hyBLv6MHlmiZnoqdfICiXvrReWyEkwKNYW wyrHEDhy2IjJ26g4Tdj/gJTQTFgfZd30kG0RIzn/xS/gk3F26NeF0SNL9GTj/N3xxOEl tPtg== 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=ImxJUm6tP72B+02s4ncaqc1E3khGA7I/Ie2/U9iRpioqEr39uQ88RKH21ZeEn1bVwW +jZq590G3krGZcgqtNtUVddnAiTbcytmKSJKKxzekn9NrvHQo/lY6WboTnYtcdELjuTP 90ropRM4f8/XUgsIotwUHC6KC7r5V7yPFqsW5Q36hkONDB/cjV0Y45yAQHAPM+O0Y4Cu ZY8a8dz4YtTRkzfj8DZhN4YIKqXJJbOJItlNfUIZSu2BU4mDs5tOwHFn4Bb9Kd/4iTcL wp7mBP4ItFk9gRpkrx+TycG9sl9jlyfMfGxSNhPaRVeuZc/hD/jWUJbDL9A0Y9KGIEfS z9vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=a9yMuNP5; 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 hd33si9349678ejc.706.2021.07.09.19.22.28; Fri, 09 Jul 2021 19:22:51 -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=a9yMuNP5; 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 S233027AbhGJCXH (ORCPT + 99 others); Fri, 9 Jul 2021 22:23:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:37792 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232735AbhGJCWE (ORCPT ); Fri, 9 Jul 2021 22:22:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 828AA613D9; Sat, 10 Jul 2021 02:19:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883553; bh=TOcl3h8y0zUeqb5SQcKCPtz9ZLYgerjxGs4W3oevh8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a9yMuNP5ccY0opbDiBVE4ta3rOIynlZ2MIQj5V1Hk/v14AjLgrk4Wv1M9PRduAukA Fqbv0Gy2kjKzm+eewuxK3WPUanr0uPpP9c6vxzjRWZOJe8s9Jw2vuiS+hf8iuO5piS 6XXWGeO/BKu59M93A4tq9sEVwtHjEWPtfg3wZcgM8z1Qp8JYgIlrzI5GJQgcuPhrKs K6DPdEF/mgoOGdS9N+8UcGx/YzEDoIpd/2OoTJMBLlRyZrWLAdF1zTYE6abStAW6hq haspzYWYM8gcy8SeLpt2SAHWWA3lIUUsuOf0FI9Q+eYvL6YkaIP6RqaXYCC8XnYUt0 DH2vJ3VlAsXng== 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.13 062/114] USB: core: Avoid WARNings for 0-length descriptor requests Date: Fri, 9 Jul 2021 22:16:56 -0400 Message-Id: <20210710021748.3167666-62-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710021748.3167666-1-sashal@kernel.org> References: <20210710021748.3167666-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