Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp273829pxb; Thu, 25 Feb 2021 02:03:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5zurDAvz5D6pTzR5z8BdBM51r7xO/RhVgf7IH+pDNk5PAmZVQMcnP3hHal0fzLuyA2Y0m X-Received: by 2002:aa7:d38e:: with SMTP id x14mr2047988edq.127.1614247385448; Thu, 25 Feb 2021 02:03:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614247385; cv=none; d=google.com; s=arc-20160816; b=ixBd8qZv1YNvqSUKpV14o8WDYbduiYynF4NspBraMt8vRfR581HbFy0f47DIAACnND tzXTXPpdqmgdTPQPN3ybFzzh5jcM6k915ROIgEb3/Wwm8LDjq0H9Vy/GjxsBrsErww8B dS8zxC5Pb3AyBbdzxk9b4lsnfsTPodp1XX7vD6x5V51S2/BlxHpCFLlO2Faew4okuws6 pEbuYmvb40V+X64mhtgDJ0UijclUofiu+5/8vrDNCponXDZykmobcadL1O0xAVA+NJWg aV4OpM8GckTKUc5rPUxvfV/X1G2SpM12Ji4oyDWqhyyYMCJ46/O7WEM/cyU9BIen2Vm7 siow== 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=o4UG6JpwhTJjynU7DKsO2DoOso4Ybn7CHEtm8maUtzhguFE+GStPtFxXsyqmdBGKzF 7Eq04qAr3KtwVp2diWjsL5wBqHDgi71VyKyKKMLAxyES+hHunGZ6pHSL+xPnIsQbmw1B 3leOSTfGIZwl4oGDkKFlYd3Gom/mTJEmtT6A6tVCmkyCxw3ONgo876Nt+67LlnbG+BFw 1T87WgL3c0HZUsDD97o1VxZ2hg/4FfzZ8M6tPyNFD+xJdsyiRlReR24S63lGjFdbZlMs c7ZaVaf5YUwEEj3Tk7VLUqGbiiR1MrkiBRC4W1Vd9sstdbGY04LIafSX7Qh5ntbU0n/S CGUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZOnmNAxp; 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 ao9si2304030ejc.331.2021.02.25.02.02.42; Thu, 25 Feb 2021 02:03: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=ZOnmNAxp; 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 S235267AbhBYJ5y (ORCPT + 99 others); Thu, 25 Feb 2021 04:57:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:33382 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235515AbhBYJzn (ORCPT ); Thu, 25 Feb 2021 04:55:43 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 91EAA64EDB; Thu, 25 Feb 2021 09:54:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614246846; bh=0cvQT/OwTLVEuuXM4LgLBjDxKi1tlOI9rg/xaVRGIzI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZOnmNAxpBBBV8qEwEoB7U6G/tQLFWXBW4Xls2FQbzEdvGxjC+zEUdi4mFdl/YBs6L YJHemI9IDP2WHK57eI+CcdVuW2Ha/tS4N4uMIPgek00CM1h+umO+IiiDuXXx1sLA+p AUPIBFyeJqBju959kGhHq1ncc3mlrvnmVFHT2I9w= 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.11 02/12] HID: make arrays usage and value to be the same Date: Thu, 25 Feb 2021 10:53:36 +0100 Message-Id: <20210225092515.134226281@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210225092515.015261674@linuxfoundation.org> References: <20210225092515.015261674@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;