Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1148740pxv; Fri, 9 Jul 2021 19:34:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxb37IKKMJCryd12LgIiUisOosf8J9R3Hwc47JHL4dl04iwkgL0dP547FLk8aGCfwabZC1r X-Received: by 2002:a05:6402:22aa:: with SMTP id cx10mr23602876edb.0.1625884451968; Fri, 09 Jul 2021 19:34:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625884451; cv=none; d=google.com; s=arc-20160816; b=bsfCaqRX0nQxWOVUNOPp1iG2zD8j+2sjFI7gwR/6nciuRAq44sDwSUKvn0jF9ca/mS gNDWRrYhqrtbx1ffoFKxSnLDg2p19ZO3Gul0dAokm2SnXo+PVxW1iq2l9Py+q4arITYs iZXtXS0rulHE1V555w985TctlCRQVBJsUmsCj9o6nK5SzHU5nGi49Lcp53U4qob/fNVf 0s7IDq4iJ3+N6rlk0tec7gAFgqIO2AHqyHX+FZ5ZmSkp7PVYJKIhfZx1aPkpwSOgnpVO H8GsoS4pGRARDXMs6UXWHc3Zn28CjZtdQp5lsN9ZJMNUoH1UhONNkDdtTnZIrux2gYAc 3FWQ== 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=UrOguT6KVn6aYZ8mAlU9PHKbe6XYelxiyeUiXucmOkA=; b=BcuP1HAnCXjzvraOvDoPPQuMeIAjtCFmVWsjyAjztn/y3mSUEqqdHix8qKczcKOuMw I+vQF9ICQAfO5haKDfKYUeNxe5XReD4bHidcdKsNuE6akJFgThNIOKzyfMXUaiqfsFV6 p5rI3nkKsvygjJTkTBSmnW9troMsTDA90j2gTXR2CilS6oa8uyZAG2E4EaZnKvLTIIQJ cmj8WHhONJGqlyd9T4MXRQdUKbZPx62MXhy5Gd2G2bvrWGJGgtZjN8UxZJOK+AN1baAo 5US9bNR0wd/1Vn8nGzZXtLBNz2nRW6OsBH62wpg29AdM/pxMbvcMHw2EciPY4C/3nX+K TZEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kn2dEojz; 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 s11si9681048edh.271.2021.07.09.19.33.48; Fri, 09 Jul 2021 19:34:11 -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=kn2dEojz; 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 S234264AbhGJCdK (ORCPT + 99 others); Fri, 9 Jul 2021 22:33:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:42628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234205AbhGJC3Q (ORCPT ); Fri, 9 Jul 2021 22:29:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DED1F6142D; Sat, 10 Jul 2021 02:25:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883938; bh=YdjrPX0dC2pAWZg7bMEfpM/Ww9iM33zjIjra4OHLvZc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kn2dEojzmC//4MpszbF+MKYkdrk6CIrjSL55qUsqoAKBPlCjLunYuQXBkLH4bMBdY rhyH8kGR4NKLpv5F55xQU0nrMKMQRAQLHPGLxIjuhBlPhart1vu29ZMupJ298scM7A uif4rzO9y7ZulsrkFISA4JwnzI4UJjwZL/XndnOlutDebGZUf8kJ471K7oLK5Dt/mz Ni64aJtANE9htNOZ9I4Vzd+DMkKOXkUtbaBm48gdcDyqE7TdxjHcc3k+sBMXUEccao nPTl8AhN59gdVToonIr0e7jeXzQJfWxh16dxu5ngtwgc2/od4+2f+nP4zFL37oos7S QLAezxJJQWKgQ== 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.10 53/93] USB: core: Avoid WARNings for 0-length descriptor requests Date: Fri, 9 Jul 2021 22:23:47 -0400 Message-Id: <20210710022428.3169839-53-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710022428.3169839-1-sashal@kernel.org> References: <20210710022428.3169839-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 19ebb542befc..dba2baca486e 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c @@ -785,6 +785,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) { @@ -833,6 +836,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