Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp430209pxk; Fri, 11 Sep 2020 10:38:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUL7zHDApKozp9jQ0UU41frIHgRpXuGcF8ia2MXEWfwbhdP7cKcF309xtF6dw2nLeL/P2k X-Received: by 2002:a05:6402:1bc2:: with SMTP id ch2mr3301502edb.60.1599845938076; Fri, 11 Sep 2020 10:38:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599845938; cv=none; d=google.com; s=arc-20160816; b=uoOBC6V1U7/ctx2dyxv77CbK6waTFCbWHqkXEtEXKjTqQ22dNaJN//V3ysiVMXcGkk vTEPN2Gf0H7OASzGmnyV/hKYi5atxVF2wCSSe0EDz/PmnRc4jmt3OW+5rBn9U80K/xdc 2avCyk/5HK7/0XsLIt3dqOGks8fxGps2/K6m5pHgaHlWCAJb3yPK/McX5euJFoc0g61e nCsKuv4tGdSsfvpVnSN6DqEf3DFOXX5EgFuzejB0YrQKYG6JoFjdJSwWVpghiz/AVJi/ j4qmC7/3XvaxaOgZp7NT4n4x4dLqqsgM4k8Ea88mOhN1sidU6EoWtIY7O2fqm0Bg1GuF crDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TbXpBU1iWn/I8h0VxxMQLb/XOgDJypQIUVTHVb8iYSc=; b=kpa28o7EORB8tzZBhpeeBZCLkwLiw67g2QlDpqdtGIazm4ayA95pJJbHl3rsPOwB2T aqtRZPIIsv1ZuBjYyzTWDl/XEmQDhgBGI1mLRCZ9kGH932uyzMiM43p+nSsxG4NBsjwI FMWVwRoAS9dewhjCzM46aDhR79r5N7oH5usa6HPsvQ3scclxcepkTMTmVFSexrYP9zJe Pm1REv9y+PJ4pIH2XfvSclQIk412ePWQEPtTVSElL45wryQIQV+mzki2rGTO109Y8atg +0go6frPsgBT/tlVEs7MAZUbhcCQ1+nzYyAaozIxya08lZz7hqUftXj0XKY//GBnU+AD Xnng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pl6Q6ZDx; 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=fail (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 d17si1739217edy.180.2020.09.11.10.38.35; Fri, 11 Sep 2020 10:38:58 -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=default header.b=pl6Q6ZDx; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726162AbgIKRge (ORCPT + 99 others); Fri, 11 Sep 2020 13:36:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:48326 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725902AbgIKMxc (ORCPT ); Fri, 11 Sep 2020 08:53:32 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0BB9620758; Fri, 11 Sep 2020 12:53:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599828793; bh=3TUk0QMmGSrbMIZSTi77zDVjfJg52osVKczki7C3fyc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pl6Q6ZDxPAg6RyTKOYfJm9FJUs0Vn3EyHU6+B/EyR4xJd6ktw25co+plSIVapsjkC FXmQ2cBAEuFKdIXJZaKKm2ZSZjj61fFSPAFJS9K3qmCZBC9uIE5AwNuWJ2e0FogFxL OZu1cgJ9DI2+2ExRVb3fJ2vLIJ/SNwoeft0Wwuso= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marc Zyngier , Benjamin Tissoires Subject: [PATCH 4.4 01/62] HID: core: Correctly handle ReportSize being zero Date: Fri, 11 Sep 2020 14:45:44 +0200 Message-Id: <20200911122502.469937711@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200911122502.395450276@linuxfoundation.org> References: <20200911122502.395450276@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier commit bce1305c0ece3dc549663605e567655dd701752c upstream. It appears that a ReportSize value of zero is legal, even if a bit non-sensical. Most of the HID code seems to handle that gracefully, except when computing the total size in bytes. When fed as input to memset, this leads to some funky outcomes. Detect the corner case and correctly compute the size. Cc: stable@vger.kernel.org Signed-off-by: Marc Zyngier Signed-off-by: Benjamin Tissoires Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-core.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -1368,6 +1368,17 @@ static void hid_output_field(const struc } /* + * Compute the size of a report. + */ +static size_t hid_compute_report_size(struct hid_report *report) +{ + if (report->size) + return ((report->size - 1) >> 3) + 1; + + return 0; +} + +/* * Create a report. 'data' has to be allocated using * hid_alloc_report_buf() so that it has proper size. */ @@ -1379,7 +1390,7 @@ void hid_output_report(struct hid_report if (report->id > 0) *data++ = report->id; - memset(data, 0, ((report->size - 1) >> 3) + 1); + memset(data, 0, hid_compute_report_size(report)); for (n = 0; n < report->maxfield; n++) hid_output_field(report->device, report->field[n], data); } @@ -1506,7 +1517,7 @@ int hid_report_raw_event(struct hid_devi csize--; } - rsize = ((report->size - 1) >> 3) + 1; + rsize = hid_compute_report_size(report); if (report_enum->numbered && rsize >= HID_MAX_BUFFER_SIZE) rsize = HID_MAX_BUFFER_SIZE - 1;