diff mbox series

[3/5] HID: lenovo: Check hid_get_drvdata() returns non NULL in lenovo_event()

Message ID 20210215203814.699633-3-hdegoede@redhat.com (mailing list archive)
State New
Delegated to: Jiri Kosina
Headers show
Series [1/5] HID: lenovo: Fix false positive errors on setting tp10ubkbd LEDs | expand

Commit Message

Hans de Goede Feb. 15, 2021, 8:38 p.m. UTC
The HID lenovo probe function only attaches drvdata to one of the
USB interfaces, but lenovo_event() will get called for all USB interfaces
to which hid-lenovo is bound.

This allows a malicious device to fake being a device handled by
hid-lenovo, which generates events for which lenovo_event() has
special handling (and thus dereferences hid_get_drvdata()) on another
interface triggering a NULL pointer exception.

Add a check for hid_get_drvdata() returning NULL, avoiding this
possible NULL pointer exception.

Fixes: bc04b37ea0ec ("HID: lenovo: Add ThinkPad 10 Ultrabook Keyboard support")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
 drivers/hid/hid-lenovo.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series


diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c
index 9b80b1685b53..50ae770a4fb1 100644
--- a/drivers/hid/hid-lenovo.c
+++ b/drivers/hid/hid-lenovo.c
@@ -498,6 +498,9 @@  static int lenovo_event_cptkbd(struct hid_device *hdev,
 static int lenovo_event(struct hid_device *hdev, struct hid_field *field,
 		struct hid_usage *usage, __s32 value)
+	if (!hid_get_drvdata(hdev))
+		return 0;
 	switch (hdev->product) {