Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3819817pxv; Mon, 28 Jun 2021 13:45:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+jzA3Umln43Bob3tvwtdXYJO6wewb0g+tbWlW1W/OETpylJikZ3s8GkhuY6CeGmrEMcaJ X-Received: by 2002:a05:6e02:ce:: with SMTP id r14mr18973876ilq.298.1624913123058; Mon, 28 Jun 2021 13:45:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624913123; cv=none; d=google.com; s=arc-20160816; b=Qnp2VvPF6wjt3veZizOY/1uXG9b1tKrL65o+T6Pb8zOUY8HKkXpiCste0q3CDj/qc6 hYO7XP3gygUMnRRdNTbSjvOHrX17b4cic8SA6qIcUa8GUDVqbLHCjF9DgiMQjjGA7blU xND4XjaHFc8bvJhgS1vKLnl2L5hpc2zduAmObRVb43MHT0pQYgu+d6V/uAz6RyqXxi1x dzPKcZQmkHn2ODzjKTcYN65MJiamUYOEaWoDAwy9s7oFCqdVWb+4QuFfQC4fZyDkoqj6 5UKCLVdJmnkrzE+HHmvREOoZm8vyVTh6R0ttpRNKOfsPk9ikN8KEFT2N+jBfINauM6mW LEww== 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=A4ozLe0HOtQa/WIwDM3i7fecMO8iqh1U31RRfGHOX2A=; b=BS8iDk9DA3m4qiWsGyBpS31BprrQKiTd4ZLnac5DvEJa8zbnEM+zYGZn9mn2AVhZLp lDEOVrqJ2j0moHuP11AkOdwTT5qhBb6EKgBM1/zMVZA6T8T4j8LZ46krvR4soKgREshn xEHvyTgu6bHMo6Z/EggiLy2BdgUD/IoG1rT/0WirDAC22dBLgLO9VA0aqaNyaamz6Dlr uHqdRfBE8OR54UuOCuE2q5EhRbvHWO4x7zQDPn8EsreP9Bq/lvkHSVjNnnExI8ixcfFN ebas6KmBNImm2b5P1/kDbJOi5pXlRNdHPUrdSnQ3VKUwrrgz2+Iq6gHYynUaLj5nDJGp iGbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Z+YoxJyS; 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 d5si18361275ilc.20.2021.06.28.13.45.09; Mon, 28 Jun 2021 13:45:23 -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=Z+YoxJyS; 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 S236625AbhF1PSM (ORCPT + 99 others); Mon, 28 Jun 2021 11:18:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:33816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236867AbhF1O4O (ORCPT ); Mon, 28 Jun 2021 10:56:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 41122619BF; Mon, 28 Jun 2021 14:40:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624891208; bh=ZMRYJ2E5UzaUn6wvHbPgIaGmRjOuSSXEp0XbRGK7eek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z+YoxJySvANBGlU0UifsV9lILWzKKmhPdynzCj+FzZVxlLbv2syQhzx55iDY3c5HE Z3MV8K7wxcGL1jUu88dofsaNS9iKUTseBhsh5pbvrasmGlHlViTiLKbLzP44fdP/WP aO/9n7E3AlisuE0LkRgIx0GLS27QvM0lox2ck7B4HghGCn6IiwZXYt1hcA+94I2YDL VaHGsD95w8tZHC1NiAENIHSEN5pv8kiq8ue1aBRepa6TMTus8GVFilCHSESU8rK9Rd Rh2/27Xh+RHAAEY7FVqSPS/roxKmMpstDX5mwv8cc6po93uuiyt8fqoDj+v3ILlmF7 +cYS8vRQjFeZg== 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.9 04/71] HID: usbhid: fix info leak in hid_submit_ctrl Date: Mon, 28 Jun 2021 10:38:56 -0400 Message-Id: <20210628144003.34260-5-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628144003.34260-1-sashal@kernel.org> References: <20210628144003.34260-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.9.274-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.9.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.9.274-rc1 X-KernelTest-Deadline: 2021-06-30T14:39+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 7838343eb37c..b6600329a272 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -372,7 +372,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 41c372573a28..2ed6850356ea 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1127,8 +1127,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