Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp276705pxb; Thu, 25 Feb 2021 02:08:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJzOUg4Vf/9iY2wFFD0tFPzLGVjYSeuMgoXHkgaA6gVnOURUFrFG5XGk4P7SZKuI3yJoWYjs X-Received: by 2002:a17:906:780b:: with SMTP id u11mr1933568ejm.492.1614247685324; Thu, 25 Feb 2021 02:08:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614247685; cv=none; d=google.com; s=arc-20160816; b=NfsUcjfmcJ32thF+6sW2t2c9Jq2SGwtY0YHu9AjAxY6qElrsOW1wDI/CEL8z46EoB4 NeihWF9f5z9GQVCM76UqCexRB7bLFLzaWj1XYND3gZ6WM2fJwS3R+O2AdkHYynxXFtsY sk4pfRM+iD9oksz94ugq/X2bnIfFr+K2DuAXlQVFGhxWVVl11Nlv+8Z/XuAkYc7iKMVL bAwGnPWwxKc9FTOD8phECPxCnfQAQxXNiXXbsMEwHSUDk+Zqdm00PVuHWEzth+oT+sh2 z3muRofUnt8mKLJpiLsco42EjZC86P1uWFAq/XWUM1VVBUnlwDgAfhAyiuIy5zj8EDvW 3FmA== 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=6SoK97EGprPVL0Vj746VC2PQw4PMlvCpt7L1k+NAnug=; b=z1EvAWTvJKXyIefxenR2hI9lSDsdBlEHdHA1Bx2oMlwD8EsVq3xmzEj7iJVfhldkUS Gyw4NCbRvKsMjH3o8pYNFGBP2tHtm3iLtSvVgztDrpb2osuYxB1X3oK6dBMbiYmMxZxP Pqu1OtRfUgJLvTrfaUGjmR5aRoy/JRwQ1RQoObnN3CUhsd+Mt+qdrlGqoL/JD3vW1M0x GgqMZ04YIoUKp3q5LCiQ9opARz2XUjfvxwa0SAafeIK98NAS7X6+MrOLGmAaEN7wILbH 1JKQrs+VKOttPCn/ajuJ3a5F66yh0HHalIrCPTbNtUERCE2ehBzO8yt8IzCefmtP8JHQ 4cUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0UyQb1Cd; 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 j26si3088344edq.184.2021.02.25.02.07.43; Thu, 25 Feb 2021 02:08:05 -0800 (PST) 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=0UyQb1Cd; 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 S233922AbhBYKG1 (ORCPT + 99 others); Thu, 25 Feb 2021 05:06:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:33384 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235509AbhBYJ6D (ORCPT ); Thu, 25 Feb 2021 04:58:03 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 615A964F13; Thu, 25 Feb 2021 09:54:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614246883; bh=0cvQT/OwTLVEuuXM4LgLBjDxKi1tlOI9rg/xaVRGIzI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0UyQb1CdPEhxWhb+HCDwq8qhY6SEFyJd+eXd9XRpbTCCRw3ijDWvGoYj6Kcd8hTNt IrSv/XkdAIEgCkj65+E3wVvLSlMy+5IcytuW+SAj8Sa3//y79SHrxRxs3ZCXIdHXj4 JhD1abh5o6JgLUg3jx8zlpasVDkDqLJSVEXt7Dso= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Will McVicker , Jiri Kosina Subject: [PATCH 5.10 02/23] HID: make arrays usage and value to be the same Date: Thu, 25 Feb 2021 10:53:33 +0100 Message-Id: <20210225092516.653936201@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210225092516.531932232@linuxfoundation.org> References: <20210225092516.531932232@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: Will McVicker commit ed9be64eefe26d7d8b0b5b9fa3ffdf425d87a01f upstream. The HID subsystem allows an "HID report field" to have a different number of "values" and "usages" when it is allocated. When a field struct is created, the size of the usage array is guaranteed to be at least as large as the values array, but it may be larger. This leads to a potential out-of-bounds write in __hidinput_change_resolution_multipliers() and an out-of-bounds read in hidinput_count_leds(). To fix this, let's make sure that both the usage and value arrays are the same size. Cc: stable@vger.kernel.org Signed-off-by: Will McVicker Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -90,7 +90,7 @@ EXPORT_SYMBOL_GPL(hid_register_report); * Register a new field for this report. */ -static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values) +static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages) { struct hid_field *field; @@ -101,7 +101,7 @@ static struct hid_field *hid_register_fi field = kzalloc((sizeof(struct hid_field) + usages * sizeof(struct hid_usage) + - values * sizeof(unsigned)), GFP_KERNEL); + usages * sizeof(unsigned)), GFP_KERNEL); if (!field) return NULL; @@ -300,7 +300,7 @@ static int hid_add_field(struct hid_pars usages = max_t(unsigned, parser->local.usage_index, parser->global.report_count); - field = hid_register_field(report, usages, parser->global.report_count); + field = hid_register_field(report, usages); if (!field) return 0;