HID: core: Sanitize event code and type when mapping input
authorMarc Zyngier <maz@kernel.org>
Tue, 1 Sep 2020 09:52:33 +0000 (10:52 +0100)
committerchenyt17 <chenyt17@lenovo.com>
Fri, 28 May 2021 07:07:54 +0000 (15:07 +0800)
commitcb9ab822b8283ab54f932348861680208dee8852
treeb01269f77e1153c8200cca3d69ba96883f781931
parentbc2d90ce74b34b02456f3dbbea58aa795e0851f2
HID: core: Sanitize event code and type when mapping input

commit 35556bed836f8dc07ac55f69c8d17dce3e7f0e25 upstream.

When calling into hid_map_usage(), the passed event code is
blindly stored as is, even if it doesn't fit in the associated bitmap.

This event code can come from a variety of sources, including devices
masquerading as input devices, only a bit more "programmable".

Instead of taking the event code at face value, check that it actually
fits the corresponding bitmap, and if it doesn't:
- spit out a warning so that we know which device is acting up
- NULLify the bitmap pointer so that we catch unexpected uses

Code paths that can make use of untrusted inputs can now check
that the mapping was indeed correct and bail out if not.

Mot-CRs-fixed: (CR)
CVE-Fixed: CVE-2020-0465
Bug: 162844689

Cc: stable@vger.kernel.org
Signed-off-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Change-Id: Ida234c943583d8b0274e1eff8bf419ba18978191
Signed-off-by: Jignesh Patel <jignesh@motorola.com>
Reviewed-on: https://gerrit.mot.com/1796758
SME-Granted: SME Approvals Granted
SLTApproved: Slta Waiver
Tested-by: Jira Key
Reviewed-by: Xiangpo Zhao <zhaoxp3@motorola.com>
Submit-Approved: Jira Key
(cherry picked from commit 56763405c6673b69bdc5717596c0b97976b405ac)
drivers/hid/hid-input.c
drivers/hid/hid-multitouch.c
include/linux/hid.h