Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3777132pxv; Mon, 28 Jun 2021 12:36:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNu7D8AKxdQ1+M0bJEa8zcoeayLjymQSDxu/152wrlIKnqotCy4zcirOqyb7sh3ECyiQ2O X-Received: by 2002:a02:a906:: with SMTP id n6mr1012393jam.87.1624908963128; Mon, 28 Jun 2021 12:36:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624908963; cv=none; d=google.com; s=arc-20160816; b=eFodU49Tbi7V5GCI2DtoI4re5Y77NCFqt0OVOQYHRMGgbgBADPWT/2bS1gRkejhhCc l/1BNKExEBWRvuyFuBJHNFumeeTrp6K8rJTn4GTs0ShZMJyqA4nhZXKy3uNGXNCKorbz ROzDGUg0UIZkCDjczYhRwKPDIwoXAsLth7sJCdoM+OViZdtFX8E9Qmpkdil3jxrDcuax OLERKvHGhbXD+KbqGVpaiA1YREvqSEbQ7debxnjOJBtyF1SBsmB24t0MxJPqV7vJX/5T rfzJLarnClxEHpPSdjWkgEmma7FNf83XzubURbHRxwo/NRs0djAZcqInRWY907XoNeRd DRMA== 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=BnW28xOCVxfpIb+FAZ05ztwm2eguBTrtcHrNF88OSgA=; b=Oj6ZHNIV1NHW17Epws0Ef7B9RYJFuHPXu2Sw2XZV+CSxq7Dgi/somUaeCoVu2vxQ5P d11nJQC+S7GF8Px9OmvCUZTSR+ZdG9sGFz+Uy0qyXOTh+7BnVfQ364itYnBdl7yYYE6L Tyr11a36JKHUu3w5Re7FIztR8FuP8tOLezjWkqHSs58RvL0pp5iQhtQxRgV4Dso0j8Vl y7dHZtJt9T+QG0bm1sj2AETD4PCoQH1+GW3CG+0muC1n2VuYS00rtoDCH/Tq6iY5UN0a R3mymLqMuEuJYXMEgDCivooIvUYiLH4EC09KT6X5jcXQeH6XdNIQnYorlCr5zEVZYebu dOXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=O58jm7HZ; 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 p5si19069024ilm.31.2021.06.28.12.35.50; Mon, 28 Jun 2021 12:36:03 -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=O58jm7HZ; 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 S234662AbhF1OxR (ORCPT + 99 others); Mon, 28 Jun 2021 10:53:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:43650 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235409AbhF1Ojy (ORCPT ); Mon, 28 Jun 2021 10:39:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8F02E61C7C; Mon, 28 Jun 2021 14:33:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624890792; bh=+3Z0i9Fp8X7Qb7YZFM5htfaEaUJ9zsnntqbfrvLllPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O58jm7HZK0UC1RKmraUMJ3szsySZIBmZY74i0NTfTnVtM77deLS8mauLcF3Vanzjp OXUZZz4ilYvge1KckErkxuHRCk8T2BFrn0ZIyhUZ30w12CVO+aA1Be1ofrD4RW/d0j DwpuxZbAm0OwpRTXoazl8CjZ1DkdLNyo8vpv5yN058ZN+aRA0I8XN51BowOR3UEnCX B3E1hynSlmdoo2Tjpw2rnK2T634OaAL22LNfiEUdDyWw6m77Eb7NBVGE/vUC0EZn43 j7ghor8qKVqq3SVnxKHyPqOsIFwmQRq+OGC+sWNAjx9s2a1kvNaEBal2YZ31U7QUUo x8nPGeDUAajEA== 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.19 005/109] HID: usbhid: fix info leak in hid_submit_ctrl Date: Mon, 28 Jun 2021 10:31:21 -0400 Message-Id: <20210628143305.32978-6-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628143305.32978-1-sashal@kernel.org> References: <20210628143305.32978-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.19.196-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.19.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.19.196-rc1 X-KernelTest-Deadline: 2021-06-30T14:32+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 1e6f8b0d00fb..6b6db57b49d6 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -377,7 +377,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 4dcce83ca378..c833948aade0 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1151,8 +1151,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