Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2889750pxb; Tue, 24 Aug 2021 09:57:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWKJ6ALy6JJgJRH8DPlcT7hs2tzD135UlRLFY730qcYXiOoZNNNhvqi/9D3rUSTWNnCkzU X-Received: by 2002:a92:1812:: with SMTP id 18mr27051952ily.83.1629824248389; Tue, 24 Aug 2021 09:57:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629824248; cv=none; d=google.com; s=arc-20160816; b=1EzxwcvHkFJkeXqMR9AK5yBigmfPsNiTz3IdgOPkNSO0bLGmKoRLrFhP1zre9eatT6 uBOK9wQqSD7HmoOwMqZQrVkr8ziUXvzFc6SMHY2W2LRTog6TCV+IHVnTF7YRb4aPdCd8 jvt9yFNTBNHwEBJ5hKFK00L4gcV7FcL0hBjbgZfmGmSukQt5cF1sMi7Pa8HqnwaMyMjk v4QV+QL0+eVEHg8sAXtYV23DmUcuDNH2TQ5YdTgCmEbcizSbFio9rpi4KjqFAT9VlrHw LmxNAkHcKU1PFKdRfm0T4NpC7OtIj3TftbWQ/FqkoHUl06rz9pZqQdQibxKxux0wRCl5 pVEQ== 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=lyyZUHoM+My68Ce3C4CU5VAChtXkwfXuJ6sg6PB1D3jFIq1swtNAcBKR23Yw05kWzI v9HyWcgCQad20Y7+Onjgtyc/I7LokpzzpENBGWN5APWhswaCAubyi2V7g/44FuL/+cTy MEf6RTocLNWmyjnq1EWCF+5Ir5NwrpMcGQV8Sl1Xfl0CTN7propxehkLxx5hUlahTG+N 9ZcZ8a7nV+wKZoT8KvmuZh7i7xGFXPsUJZ3MYXDlRVJIJJHXTykS47w4NeD4SDjMt+yI VxrqAxO5vPz+HzHjRovCxR+YTg4+UJapbpw1QXPFB8u8qJPwpe0wQwTrviJRiZdqOnD5 NCkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KMLsG9IH; 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 u10si23964058jat.85.2021.08.24.09.57.15; Tue, 24 Aug 2021 09:57:28 -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=KMLsG9IH; 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 S233604AbhHXQ5E (ORCPT + 99 others); Tue, 24 Aug 2021 12:57:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:38698 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233433AbhHXQ45 (ORCPT ); Tue, 24 Aug 2021 12:56:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 13FE361373; Tue, 24 Aug 2021 16:56:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824172; bh=TOcl3h8y0zUeqb5SQcKCPtz9ZLYgerjxGs4W3oevh8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KMLsG9IHHyRX507b7sIdFbqYAKZMS+iNgxqJl/f8i36Hmne0n3EzMtL97Thsqh8v/ CVkipnWdJKfhUL/Zml5dbRQwHsnfhcj/7lVNvalt6Sw3w8yhF+eHn87BvoHWjgnHR3 L6WrX2GOZlACE4VZ1lUvC0ekXDmMM01qVvoWlB32eqTrmy1Ev+RiUKHUFIRICc9Dg4 17iCTbN01pERHCg3aZnhKmAj9s8IiOqjNVw/l2PVPddcUpZiijvx8r7GHDMckdJjtD 1eUNjaArPHD+AKBuBN7W4pwhtEr9T2376ZVzFxNT7/KmfQtGjN2Jn6911IwJoCidtm xnyNUeZAHutYg== 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.13 003/127] USB: core: Avoid WARNings for 0-length descriptor requests Date: Tue, 24 Aug 2021 12:54:03 -0400 Message-Id: <20210824165607.709387-4-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824165607.709387-1-sashal@kernel.org> References: <20210824165607.709387-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.13.13-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.13.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.13.13-rc1 X-KernelTest-Deadline: 2021-08-26T16:55+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 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