Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp874481pxj; Wed, 16 Jun 2021 16:01:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwONw4VosDHIwmnJUpTFmUsPnA2KugXio7mHWEOL3wj9meTLEI3VMZH8NmwqmB0IqPpUw92 X-Received: by 2002:a05:6e02:13e5:: with SMTP id w5mr1342320ilj.112.1623884513229; Wed, 16 Jun 2021 16:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623884513; cv=none; d=google.com; s=arc-20160816; b=b7cCyDinYWMMw5mMlpq0b/1M4JV29ebrIVD15C/MKRN9fF/zu69jC4oiFG2BpZYaKP dGt4FOBRALl1xPpjLOxlqUhasEiTap1QFuqW0pygURj9aMq3zrNN85p9APICDVUMmU3S nflFBRDvass6wkpbx8fW0XEip+Oq1UapFo3rsab90tMorqk5tyy3+JchPMowzAwhwq8F eLCjYY8jkz1ynDzuppcQew0gfZNgJEcEGp2gDLPxjanvKJ8ut3o6V/WXRw5y9W3NFlVU Xs0d98k1tPCbjKTV1zx5EkiWu0LMbL1TBaCV2wqx5IW7KFcohDmWyQe7U9MEaYWAn/iL OYQQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HzNsHBk3AqSnuhEdLVjYvaOCO3fcvhehT1fzrv7FqNA=; b=tbAAZL2DKlFc6qqRlK8TtCty9UmzXrZrTrskj4ViMWXq0FoxIpWNb6DMNc4EXOvabq v8mGFPcTFh45wxOqGENBX5bCTf4aiLykfoAVHjtJ28RMGqWqCP9SG/oLiYbgYagpga6M wo+lGUx/z3ut8IZoeYxpQzfo8qMVyBh2itVkb+lEYzlTK8amMnFoYOETpWeUZM8oJU2y 1iKALWR3iOLv0sBn0rppX3c0eBUvRFiZ9XyiCdxG3N+3D+iN+GBvRueebe+oKuk3SlgQ Nnbqk5XKRXyBRcpXo3BLHKDKpaoxgn4Qz6YxL62zb+fg4CoCpEfQXfqsml/RmgSEqxoc l3jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=B+I+QNXV; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n1si4233795jat.109.2021.06.16.16.01.40; Wed, 16 Jun 2021 16:01:53 -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=@linuxfoundation.org header.s=korg header.b=B+I+QNXV; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235177AbhFPPlO (ORCPT + 99 others); Wed, 16 Jun 2021 11:41:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:51360 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235128AbhFPPit (ORCPT ); Wed, 16 Jun 2021 11:38:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3290C613DF; Wed, 16 Jun 2021 15:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623857789; bh=HVeLsmrSRwJUos9ss1pz455I7/UCxPtH2jgZwRv0/I4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B+I+QNXVInfw/5MU8zSOaFonYU/hCa+9FE/QfXNMgmRIL1loA1ZvEbyX0Vg/0yHF5 FWUZpiUfIpZnSMyMTwMxTVJ+iog3PWmvAAiMKP3pQMykPbhBHWLhPhAtcat9w6jRd9 7LlNt1Qz28UAaAJeuU4ZaaGw4vfMBa+Sk1EnsXsw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+7c2bb71996f95a82524c@syzkaller.appspotmail.com, Anirudh Rayabharam , Benjamin Tissoires , Jiri Kosina , Sasha Levin Subject: [PATCH 5.10 09/38] HID: usbhid: fix info leak in hid_submit_ctrl Date: Wed, 16 Jun 2021 17:33:18 +0200 Message-Id: <20210616152835.697511779@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210616152835.407925718@linuxfoundation.org> References: <20210616152835.407925718@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 17a29ee0ac6c..8d4ac4b9fb9d 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -374,7 +374,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 8578db50ad73..6ed2a97eb55f 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1156,8 +1156,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