Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3740794pxv; Mon, 28 Jun 2021 11:37:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwq8wG1hJpz34fmudSndXQCHI9MqcSrM+o2j1fWuuxz3bpH/pdoMT628JkstBxOk+23uu4 X-Received: by 2002:a05:6638:3726:: with SMTP id k38mr875224jav.140.1624905434414; Mon, 28 Jun 2021 11:37:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624905434; cv=none; d=google.com; s=arc-20160816; b=tU3TuCXCKLx7JUgW/e+1vx779pKMELdvJV6KSROvG8fcqeXfQXJUG2eQxRqNhbElWs c7TmF6tsAvGJNzD7AI6nzZ6gLiBRYFL1uSZmz3OHuE7oqBJ+dK6O6dbqb1j0uo4ewRdx mjvpvXHvUjjYu829JYLhGoNTtvlAP+9NCmdGCiDZZ1i5i7Q/lJES5EtOYzNPxdBs4HJ8 WFCxfsEFXoTs0BsjKQq7XKeAHqF7irOluoxTpJ2qPHJGriA//P4Ac+O3ec+qfrMy/Iu0 EfECu7YIoY/i1/rLQzHtlu8mmhx6/Ta5traihJNrDkYu5ciR/ee3P6ry6BDZMYaYQrGh DKvw== 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=IZVxUle7/dRwtIBU2XXE+2ai8dqtlIV1meMh8Sb65RE=; b=gZ92kML/fUGBJzQkHtWRPSxDZrmWqmlksMxlFOJSrCWXQ5NdDuU0cD1bkgvk0NYNbO z1WdmUKNoQN+9rnozjy6FsEudXSdbAD54+Ija7qnUPoMtK2FEgBuOZ8G7dacTxK64r8c wzaBtUsPlvjNj5BcXBNsKaPsm2URwCUz9D+IjNybw0euNy3sfEng4D5v1mZT38X9J74Y WXKow1H8tnIlT0XaERl0R7X0s3TLWkamqYZgq668MMmSVYC4kPMRPGhmpk/F5BRmwxya X2llEdKnc0vovGPvGABisQf7FodmlnRC4FdNtoJZ4ifNBYS0J9nTVyG1Ipx6f0fXQZU3 yKOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tgjIFMWN; 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 d5si18079117ilc.20.2021.06.28.11.37.00; Mon, 28 Jun 2021 11:37:14 -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=tgjIFMWN; 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 S235799AbhF1PHP (ORCPT + 99 others); Mon, 28 Jun 2021 11:07:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:54506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236320AbhF1OrU (ORCPT ); Mon, 28 Jun 2021 10:47:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D1C9661CA3; Mon, 28 Jun 2021 14:36:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624890994; bh=udkCOC6Hz1MXtaCm4KFABL+LowYHouaHndMAfGaCQBo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tgjIFMWNZr/Mtq6eRZ4q5TgjHBRBlthkYmUkKBvXpXinXm951qzv8m9xwddXb17ST nx9atkTlZt1n5llnidI9VCWyvcBJ5RqNov84dQlja4Op8PafkoG5Bdp2ZMpTfOx3G9 /EuB0Qn86oBcJVDz1aPQbnehQ0vXAmLxOvESZ8eG2hWb8/nvWfB126BP9prQxEPD04 ONDd35/+CS1w1LrUaqA8gwG3cWhudRDg6xJPIAqORbctq3GUiXWV2KHH0v0l7pF2H3 XOOFRHpmIRwxNaTFb4LYRi2hU+nqTCLRDlDQmEG7xMRdP81BDhBdVnpViopTZJhdcw 7pzrvBiagpf+Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Anirudh Rayabharam , syzbot+7c2bb71996f95a82524c@syzkaller.appspotmail.com, Benjamin Tissoires , Jiri Kosina , Sasha Levin Subject: [PATCH 4.14 04/88] HID: usbhid: fix info leak in hid_submit_ctrl Date: Mon, 28 Jun 2021 10:35:04 -0400 Message-Id: <20210628143628.33342-5-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628143628.33342-1-sashal@kernel.org> References: <20210628143628.33342-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.238-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.14.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.14.238-rc1 X-KernelTest-Deadline: 2021-06-30T14:36+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: Anirudh Rayabharam [ Upstream commit 6be388f4a35d2ce5ef7dbf635a8964a5da7f799f ] In hid_submit_ctrl(), the way of calculating the report length doesn't take into account that report->size can be zero. When running the syzkaller reproducer, a report of size 0 causes hid_submit_ctrl) to calculate transfer_buffer_length as 16384. When this urb is passed to the usb core layer, KMSAN reports an info leak of 16384 bytes. To fix this, first modify hid_report_len() to account for the zero report size case by using DIV_ROUND_UP for the division. Then, call it from hid_submit_ctrl(). Reported-by: syzbot+7c2bb71996f95a82524c@syzkaller.appspotmail.com Signed-off-by: Anirudh Rayabharam Acked-by: Benjamin Tissoires Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/usbhid/hid-core.c | 2 +- include/linux/hid.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index 98916fb4191a..46b8f4c353de 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -373,7 +373,7 @@ static int hid_submit_ctrl(struct hid_device *hid) raw_report = usbhid->ctrl[usbhid->ctrltail].raw_report; dir = usbhid->ctrl[usbhid->ctrltail].dir; - len = ((report->size - 1) >> 3) + 1 + (report->id > 0); + len = hid_report_len(report); if (dir == USB_DIR_OUT) { usbhid->urbctrl->pipe = usb_sndctrlpipe(hid_to_usb_dev(hid), 0); usbhid->urbctrl->transfer_buffer_length = len; diff --git a/include/linux/hid.h b/include/linux/hid.h index d07fe33a9045..5a2c55ed33fa 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1114,8 +1114,7 @@ static inline void hid_hw_wait(struct hid_device *hdev) */ static inline u32 hid_report_len(struct hid_report *report) { - /* equivalent to DIV_ROUND_UP(report->size, 8) + !!(report->id > 0) */ - return ((report->size - 1) >> 3) + 1 + (report->id > 0); + return DIV_ROUND_UP(report->size, 8) + (report->id > 0); } int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size, -- 2.30.2