]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
HID: pidff: Fix null pointer dereference in pidff_find_fields
authorTomasz Pakuła <forest10pl@gmail.com>
Sat, 1 Feb 2025 11:39:02 +0000 (12:39 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Apr 2025 08:45:12 +0000 (10:45 +0200)
[ Upstream commit 22a05462c3d0eee15154faf8d13c49e6295270a5 ]

This function triggered a null pointer dereference if used to search for
a report that isn't implemented on the device. This happened both for
optional and required reports alike.

The same logic was applied to pidff_find_special_field and although
pidff_init_fields should return an error earlier if one of the required
reports is missing, future modifications could change this logic and
resurface this possible null pointer dereference again.

LKML bug report:
https://lore.kernel.org/all/CAL-gK7f5=R0nrrQdPtaZZr1fd-cdAMbDMuZ_NLA8vM0SX+nGSw@mail.gmail.com

Reported-by: Nolan Nicholson <nolananicholson@gmail.com>
Signed-off-by: Tomasz Pakuła <tomasz.pakula.oficjalny@gmail.com>
Reviewed-by: Michał Kopeć <michal@nozomi.space>
Reviewed-by: Paul Dino Jones <paul@spacefreak18.xyz>
Tested-by: Paul Dino Jones <paul@spacefreak18.xyz>
Tested-by: Cristóferson Bueno <cbueno81@gmail.com>
Tested-by: Pablo Cisneros <patchkez@protonmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/hid/usbhid/hid-pidff.c

index 4c94d8cbac43a766c3805e37e5b901b808de6dc3..25dbed076f530467293f3a9a228e0e2ef8ba036b 100644 (file)
@@ -793,6 +793,11 @@ static void pidff_set_autocenter(struct input_dev *dev, u16 magnitude)
 static int pidff_find_fields(struct pidff_usage *usage, const u8 *table,
                             struct hid_report *report, int count, int strict)
 {
+       if (!report) {
+               pr_debug("pidff_find_fields, null report\n");
+               return -1;
+       }
+
        int i, j, k, found;
        int return_value = 0;
 
@@ -917,6 +922,11 @@ static int pidff_reports_ok(struct pidff_device *pidff)
 static struct hid_field *pidff_find_special_field(struct hid_report *report,
                                                  int usage, int enforce_min)
 {
+       if (!report) {
+               pr_debug("pidff_find_special_field, null report\n");
+               return NULL;
+       }
+
        int i;
 
        for (i = 0; i < report->maxfield; i++) {