Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2905062pxb; Tue, 24 Aug 2021 10:16:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMMq5Gi9nvao1fapjeEphY3+U/OyVpVHqOTH12Vseq3cwJFKb0AmeRLT3QcS7AU1pvKlvn X-Received: by 2002:a17:907:76d8:: with SMTP id kf24mr13978312ejc.404.1629825412291; Tue, 24 Aug 2021 10:16:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629825412; cv=none; d=google.com; s=arc-20160816; b=AdGSez6Xh9gXJ+DQS32ky67flXMGqDcU2A0RTnSWwCYrej2zgfxLWcsisEF+lrteu1 EfP/w+lE6kp8y9PoeH5xfTE1FpKw/xCyhFb2gYnuHuqSYU51//zgfbMObeC0BrHJNZlg eJfJw44V70vFNhJ1tRVIJrpfeCWCrBOXfxuCNQBJ8FxmYJ4iwVUfqYevehiBWoff9mMB yzqFYB/YKEOz0FzB/5VESkV1wUUR/xOXy94XRmQVZosuqrlPCEv6sDYDoD1x3tmJqGIb KzqgNyXxdUh6mi78vwca5hhBkXkeP3ic0sHThKWPz9OaNgwrNsu6d6pIfnqjzVf41ye0 7rng== 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=S/CkoZu6g2IC8m6X7KsDd6pcxbhRFyqW6VarvaIJi8Y=; b=T5vaVnapETOqpIj5xx2bFWdDVeNnEFF3flFdqwJox1UDzVg0AXG4DZke9/d9gAEcXB dLPL2iqxUxu5JWzwJJo0G4huIaUWbiXAfF0C3Wcx2o+Xc6G1o8g9C+ADeVcNsnhnTgdN 7zC4VFgiev+i5Lx52l30+Cpk8qxK38k0N/Ao5Yh6v8SOvlyvPA3UeA07+yFL8J2k+8pH 1mgbSLVcfnXySc31mcvbfFjWTEJCUlJoLMOETMOJ5nB20J94GqcAtTGeoIZDs6OCsSZ4 Hw72zX1P/ugzjcl8dibWnfHli6yb1M0MUiMRRU76oHjZ5YADHEGJqwUFKWPov6IpQ6gE 0VgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Cen61uSS; 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 u11si3605896edo.414.2021.08.24.10.16.27; Tue, 24 Aug 2021 10:16:52 -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=Cen61uSS; 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 S240047AbhHXRPv (ORCPT + 99 others); Tue, 24 Aug 2021 13:15:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:52062 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239751AbhHXRMJ (ORCPT ); Tue, 24 Aug 2021 13:12:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DEB2461A61; Tue, 24 Aug 2021 17:01:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824480; bh=hFLO14LY+2CjDGzsRluu6Qiid2+Ha5H969MvXV5KH/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cen61uSSevu6G5RKVcB7Vhh91AKJgT85IcT1XHQ6PUxlRHyp7jolgowGHvtpJtaZ9 IQ7G/WAyCS/+oO7ExKo1m3n/yN+3X+H1sog8nEJNw2u8X9hGkPfaPGzmnyS4czJdrc ME6LibpNyhk12ymwywkNNHKoVWJQU1ucluZhR5hVqxKo6klfvN80OqmffGpUYvhSwP tCkid+JEaN26dew+My3BfrRbnl7bL5M0pzbjAvM4VEPvVymQaMj5gl3CbSXIqxzxiu WXYUr2kEaQlcFyvd7gWDiff4yn/sX5ag7RHNkJvUrqXbY5znX190srSz1fxlMk+ktB xqfE9LM/jK7+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 Subject: [PATCH 5.4 12/61] USB: core: Avoid WARNings for 0-length descriptor requests Date: Tue, 24 Aug 2021 13:00:17 -0400 Message-Id: <20210824170106.710221-13-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824170106.710221-1-sashal@kernel.org> References: <20210824170106.710221-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.4.143-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.4.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.4.143-rc1 X-KernelTest-Deadline: 2021-08-26T17:01+00:00 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 041c68ea329f..7ca908704777 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