Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1152137pxv; Fri, 9 Jul 2021 19:41:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxn9Y7UqwQiDmixFB6WBNe8xCVnoNWbPOuZieyBaQs4JgL0voWcaDgg1SHQxX5BPIIvhCDx X-Received: by 2002:a17:906:478b:: with SMTP id cw11mr39818304ejc.241.1625884878730; Fri, 09 Jul 2021 19:41:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625884878; cv=none; d=google.com; s=arc-20160816; b=T7XYxVWZcWZdzVpgbQ1pzyJWdaF/KXiZgMLxLJy8ldLPwsD1ySQ7LM3uD0al0+Ipzf a9HLrP4w7XECH7O5/k5GK1D/YTklOdHK0rgbj3T2Cl1CyyJP5ey+XfKxGysErs78pXpT dF7A9WZVCVo6Ygv/z9ILGSEzJ8MCH6hyKmjd6SIg/EfRMtVPmYOQ2KlRqKL+uUVhjwML MwWKGi1hbXuWUoQ8dWIMqcFg+NMeZTR3vQfYhZriSL8c1t5Yf5kmd36n8EXLeWIPzGI9 OJV2e8Z1OtioX+2rcbe54tHBVADSlZkHqn1h4KFXkjqSCW+3MC/yOcknTyhOdkD25jR3 8CaQ== 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=MqxL/Jzugm5rUNkunKU3OMDTLKJglwKnHFSGapvluLI=; b=Kw0yRu6M/ZpMk1KSzlmbaZLAL+wghZ5GxfZ4uCZJSyX2EK72CUDMI9JBGagiQdE+vj JSVOcMjSkmakqWbF7wVzc1Q2v2fzbuBUtgrBcCN4at45kBgndwlmjcR4Sx0BNlG4RNqZ 0LQPe/8vzBj3IRCBeLVW1q+8AtcW4jSxd1Iq7Q/ndlxQAIGK93A8briSltvnH1BW9yrm SUQcJM9BM92mkBAI9XCMhcduE3r7Ice7HWYec+SznAFmim54okiKuFGsrAbEBiNQc4yx oj/pJmY/pb+G1WmnQPQZxYP0j0peUrpUEOwD9LKv0RCbBBZ/2BEUdPzbQe2T91+x5je5 jYaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pEUcr+ED; 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 hv7si10010468ejc.15.2021.07.09.19.40.55; Fri, 09 Jul 2021 19:41: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=k20201202 header.b=pEUcr+ED; 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 S235302AbhGJCjW (ORCPT + 99 others); Fri, 9 Jul 2021 22:39:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:53326 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234032AbhGJCfa (ORCPT ); Fri, 9 Jul 2021 22:35:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0F2F2613F2; Sat, 10 Jul 2021 02:32:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625884349; bh=PY5otcidCrBlxgzw6sEr1yBO0QN1sHRuzs7o75iBBz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pEUcr+EDkdz1r5MCRz4c/kOHEXj94FGD621b9qz0RSuA6nrQ+IwHDnfAc3/BIUFYS YcKXn4z+SAePRcvaiS8euc6sC8dLcqTkfU0tchI7TICCNbXmdjDOqhcBxrE8mMn2YH 7vjYzwJdF4o3ryrWKX6J1s9F64dhsEZNwESFGjqxh4KmTNoaYoEiv4rFTY5DHLt2an kSNBovt3s/sdAKakCF5suAUYy63HZz3fQHieEAfLGXHQ61etWV+zBk4qN4bgzP+XEr GS3uyc1s52dJq/vgTKG7O0NXaVOHxuGgFReTOtk7c5WS1gOO0A+0LGMawBiMLUJbWq cns8TdXFoyotQ== 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 4.19 20/39] USB: core: Avoid WARNings for 0-length descriptor requests Date: Fri, 9 Jul 2021 22:31:45 -0400 Message-Id: <20210710023204.3171428-20-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710023204.3171428-1-sashal@kernel.org> References: <20210710023204.3171428-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 152228d33ad2..2d1012d4bb33 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c @@ -647,6 +647,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) { @@ -695,6 +698,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