Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3004404pxy; Sun, 25 Apr 2021 10:42:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHBkzjQgS7t9yU9zI6n4+FWSwrS2oomJpPkd+e89uwoq7n0WA3UCpPOqZzN/zYuypKwq7G X-Received: by 2002:a17:903:2490:b029:e6:faf5:86df with SMTP id p16-20020a1709032490b02900e6faf586dfmr14321779plw.69.1619372570670; Sun, 25 Apr 2021 10:42:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1619372570; cv=pass; d=google.com; s=arc-20160816; b=NUmjpsZAftXKyiky+b1VXN8aMQRqoGEOcAs+Y+R8BpQXXc/DwZhB1ufW0YH3Hqx3B3 8szgfthT9KfikX2JzKSlIFu9QQ+o4Widxf3y0W/Nn1koZZ/R5xubf8aP2iA9yFQJCoDp wUPKC7fHtWTA8knbBRlhXMN0dlHbuvYCdM4CWN4QSH4W/pEUk2fNlUOLe8PiHyiwvtK4 ASQmTsH+7R7lpO7ZUw8dtsi8dyU/SV0EB5NiZMsVwsbDN823S9dfnnDQj2kaWJeaeiO5 OZXixF8CmOrE2gqgUcA8RMWrbaTZz247Cp/2xJGJr7CMj3Zu0xOD7CD0XUTWOb7vkx4+ qj+A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=k/EGKXFAZVuJOd2JkD/RJjW4fi/tHKJRxr2RkqQG2Do=; b=YreS/g7jiXCVKB82YKTbychDTBe6LblzL7l5v9La4sxql2iY6OU8xNb//fkroOOKzg 4OSzAVaADJRsPW5DJsmQ+wvn9uDzw1Ol9ZSLBVbSe8p/WF2SmjfTijyoxKnWTjMHA11W 4S0zCwYQXD16X3uMSe5Y4yKMLCpseu5DpSE7pLCG48xDQS+6RUgNNX26JyKJDPnx3Ecj 5rnWvpaOlmGqpZdmtOjV3Q9aDMUcJvBkjuW3kSJRt3V2A5lA7wjrqD0PNAOi+MInCIQ5 v+uu51oKB/IRNd9t5L3+uiPwjvxxgfuk2Bf1d9YwNaueQ/l5lDURq0p5qfG8dAofYEv3 wlxA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@anirudhrb.com header.s=zoho header.b=MQeLg+Dk; arc=pass (i=1 spf=pass spfdomain=anirudhrb.com dkim=pass dkdomain=anirudhrb.com dmarc=pass fromdomain=anirudhrb.com>); 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w3si14206430pgk.397.2021.04.25.10.42.38; Sun, 25 Apr 2021 10:42:50 -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=@anirudhrb.com header.s=zoho header.b=MQeLg+Dk; arc=pass (i=1 spf=pass spfdomain=anirudhrb.com dkim=pass dkdomain=anirudhrb.com dmarc=pass fromdomain=anirudhrb.com>); 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231174AbhDYRib (ORCPT + 99 others); Sun, 25 Apr 2021 13:38:31 -0400 Received: from sender4-of-o53.zoho.com ([136.143.188.53]:21342 "EHLO sender4-of-o53.zoho.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230329AbhDYRia (ORCPT ); Sun, 25 Apr 2021 13:38:30 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1619372265; cv=none; d=zohomail.com; s=zohoarc; b=fywXrVS5FDz6iU2UMI38X0Fikxn98aH2GUygN9jtSMHGaQcRFey+e8nCvWZRYNSfrcC0DgH3afaGzw/PdOTJXUCjWDPj9+UhJOnq2OMBgSpU7fpz8j2kdn6DAMoVFAaJsiVBaXKEWKMmv1XVJWiX8vci4rSqCQI5+OAZZdOAud0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619372265; h=Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=k/EGKXFAZVuJOd2JkD/RJjW4fi/tHKJRxr2RkqQG2Do=; b=UXRWi7MJ3YF0d33lLIIRegelrktSJhhi6qRGWm7+xK1UPeAQaKZS7mIgkiLBaW/PKi5gTFauYgeBHbSK7xaMX2Km7RFZpxBm3eiHsxame0qkyN87MyoLxGh9pQU2Dh6YaibJsUzM7VOikhFO8FT7cHW3uoKiPnejzYG+k7inKRo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=anirudhrb.com; spf=pass smtp.mailfrom=mail@anirudhrb.com; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1619372265; s=zoho; d=anirudhrb.com; i=mail@anirudhrb.com; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Transfer-Encoding; bh=k/EGKXFAZVuJOd2JkD/RJjW4fi/tHKJRxr2RkqQG2Do=; b=MQeLg+DkcwiBucf3gKN4zHpugUU+ZfFm44TS+mQL0Ckm9C+2cPNv025i49WXlwxK 3L26ZXqb5K88mqgNN50g0ViwD+JvHD/ag1O3xll0MiVaVg7VqdpcPAURcz3ajZD2aqI VovkqqKulT0PClkW/qRPhWaVTULat/J7gvlMG3Jw= Received: from localhost.localdomain (49.207.208.26 [49.207.208.26]) by mx.zohomail.com with SMTPS id 1619372262325930.7778518171191; Sun, 25 Apr 2021 10:37:42 -0700 (PDT) From: Anirudh Rayabharam To: Jiri Kosina , Benjamin Tissoires Cc: gregkh@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, Anirudh Rayabharam , syzbot+7c2bb71996f95a82524c@syzkaller.appspotmail.com, linux-usb@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] usbhid: fix info leak in hid_submit_ctrl Date: Sun, 25 Apr 2021 23:03:53 +0530 Message-Id: <20210425173353.10231-1-mail@anirudhrb.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-ZohoMailClient: External Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 86257ce6d619..4e9077363c96 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 271021e20a3f..10e922cee4eb 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1167,8 +1167,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.26.2