]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
HID: wacom: Fix OOB write in wacom_hid_set_device_mode()
authorLee Jones <lee@kernel.org>
Wed, 27 May 2026 16:05:26 +0000 (17:05 +0100)
committerBenjamin Tissoires <bentiss@kernel.org>
Thu, 28 May 2026 15:43:16 +0000 (17:43 +0200)
wacom_hid_set_device_mode() currently assumes that the HID_DG_INPUTMODE
usage is always located in the first field (field[0]) of the feature report.
However, a device can specify HID_DG_INPUTMODE in a different field.

If HID_DG_INPUTMODE is in a field other than the first one and the first
field has a report_count smaller than the usage_index of HID_DG_INPUTMODE,
this leads to an out-of-bounds write to r->field[0]->value.

Fix this by storing the field index of HID_DG_INPUTMODE in 'struct
hid_data' during feature mapping.  In wacom_hid_set_device_mode(), use
this stored field index to access the correct field and add bounds
checks to ensure both the field index and the value index are within
valid ranges before writing.

Cc: stable@vger.kernel.org
Fixes: 5ae6e89f7409 ("HID: wacom: implement the finger part of the HID generic handling")
Tested-by: Ping Cheng <ping.cheng@wacom.com>
Reviewed-by: Ping Cheng <ping.cheng@wacom.com>
Signed-off-by: Lee Jones <lee@kernel.org>
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
drivers/hid/wacom_sys.c
drivers/hid/wacom_wac.h

index a32320b351e3eeda96394c090146455014f59c61..2220168bf1164be0a2c3665d2a18d5e43cb338a7 100644 (file)
@@ -356,6 +356,7 @@ static void wacom_feature_mapping(struct hid_device *hdev,
 
                hid_data->inputmode = field->report->id;
                hid_data->inputmode_index = usage->usage_index;
+               hid_data->inputmode_field_index = field->index;
                break;
 
        case HID_UP_DIGITIZER:
@@ -571,9 +572,14 @@ static int wacom_hid_set_device_mode(struct hid_device *hdev)
 
        re = &(hdev->report_enum[HID_FEATURE_REPORT]);
        r = re->report_id_hash[hid_data->inputmode];
-       if (r) {
-               r->field[0]->value[hid_data->inputmode_index] = 2;
-               hid_hw_request(hdev, r, HID_REQ_SET_REPORT);
+       if (r && hid_data->inputmode_field_index >= 0 &&
+           hid_data->inputmode_field_index < r->maxfield) {
+               struct hid_field *field = r->field[hid_data->inputmode_field_index];
+
+               if (field && hid_data->inputmode_index < field->report_count) {
+                       field->value[hid_data->inputmode_index] = 2;
+                       hid_hw_request(hdev, r, HID_REQ_SET_REPORT);
+               }
        }
        return 0;
 }
@@ -2846,6 +2852,7 @@ static int wacom_probe(struct hid_device *hdev,
                return -ENODEV;
 
        wacom_wac->hid_data.inputmode = -1;
+       wacom_wac->hid_data.inputmode_field_index = -1;
        wacom_wac->mode_report = -1;
 
        if (hid_is_usb(hdev)) {
index d4f7d8ca1e7ed1a0de93ce74238dc112554a8cbd..126bec6e5c0c427773c6c2e6632fa177a3ee1dc9 100644 (file)
@@ -295,6 +295,7 @@ struct wacom_shared {
 struct hid_data {
        __s16 inputmode;        /* InputMode HID feature, -1 if non-existent */
        __s16 inputmode_index;  /* InputMode HID feature index in the report */
+       __s16 inputmode_field_index; /* InputMode HID feature field index in the report */
        bool sense_state;
        bool inrange_state;
        bool eraser;