HID: wacom: Fix OOB write in wacom_hid_set_device_mode()
Subsystems (3)
PATCH 1/1 HID: wacom: Fix OOB write in wacom_hid_set_device_mode()
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.
--- drivers/hid/wacom_sys.c | 13 ++++++++++--- drivers/hid/wacom_wac.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-)
drivers/hid/wacom_sys.c +10 -3
@@ -341,6 +341,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 :
@@ -556,9 +557,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 ; }
@@ -2819,6 +2825,7 @@ static int wacom_probe(struct hid_device *hdev,return error; wacom_wac->hid_data.inputmode =-1 ; + wacom_wac->hid_data.inputmode_field_index =-1 ; wacom_wac->mode_report =-1 ;if (hid_is_usb (hdev)) {
drivers/hid/wacom_wac.h +1 -0
@@ -298,6 +298,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 invert_state;
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Quoted 15 lines · Lee Jones
wacom_hid_set_device_mode()currently assumes that theHID_DG_INPUTMODEusage is always located in the first field (field[0]) of the feature report. However, a device can specifyHID_DG_INPUTMODEin a different field.If
HID_DG_INPUTMODEis in a field other than the first one and the first field has areport_countsmaller than theusage_indexofHID_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_INPUTMODEin 'structhid_data' during feature mapping. Inwacom_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.
Quoted 3 lines
Fixes 5ae6e89f7409 ("HID: wacom: implement the finger part of the HID generic handling")Signed-off-by Lee Jones <[email protected]>
Patch looks sensible to me. Thank you for your effort, Lee!
Cheers,
Ping
Quoted 59 lines
--- drivers/hid/wacom_sys.c | 13 ++++++++++--- drivers/hid/wacom_wac.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-)drivers/hid/wacom_sys.c +10
-3@@ -341,6 +341,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 :@@ -556,9 +557,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 ; }@@ -2819,6 +2825,7 @@ static int wacom_probe(struct hid_device *hdev,return error; wacom_wac->hid_data.inputmode =-1 ; + wacom_wac->hid_data.inputmode_field_index =-1 ; wacom_wac->mode_report =-1 ;if (hid_is_usb (hdev)) {drivers/hid/wacom_wac.h +1
-1@@ -298,6 +298,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 invert_state; --2.54.0.563.g4f69b47b94-goog
Quoted 16 lines · Ping Cheng
Quoted 15 lines · Lee Jones
wacom_hid_set_device_mode()currently assumes that theHID_DG_INPUTMODEusage is always located in the first field (field[0]) of the feature report. However, a device can specifyHID_DG_INPUTMODEin a different field.If
HID_DG_INPUTMODEis in a field other than the first one and the first field has areport_countsmaller than theusage_indexofHID_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_INPUTMODEin 'structhid_data' during feature mapping. Inwacom_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.
Quoted 8 lines
Quoted 3 lines
Fixes 5ae6e89f7409 ("HID: wacom: implement the finger part of the HID generic handling")Signed-off-by Lee Jones <[email protected]>Patch looks sensible to me. Thank you for your effort, Lee!
Tested-by Ping Cheng <[email protected]>Reviewed-by Ping Cheng <[email protected]>
Thank you Ping, I appreciate your review.
HID folks - any movement on this please?
Signature · 1 line
Lee Jones
Benjamin Tissoires
maintainerQuoted 22 lines · Lee Jones
Quoted 20 lines · Ping Cheng
Quoted 18 lines · Lee Jones
wacom_hid_set_device_mode()currently assumes that theHID_DG_INPUTMODEusage is always located in the first field (field[0]) of the feature report. However, a device can specifyHID_DG_INPUTMODEin a different field.If
HID_DG_INPUTMODEis in a field other than the first one and the first field has areport_countsmaller than theusage_indexofHID_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_INPUTMODEin 'structhid_data' during feature mapping. Inwacom_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.Fixes 5ae6e89f7409 ("HID: wacom: implement the finger part of the HID generic handling")Signed-off-by Lee Jones <[email protected]>
Quoted 9 lines
Quoted 4 lines
Patch looks sensible to me. Thank you for your effort, Lee!
Tested-by Ping Cheng <[email protected]>Reviewed-by Ping Cheng <[email protected]>Thank you Ping, I appreciate your review.
HID folks - any movement on this please?
I wanted to apply it today, but the patch conflicts with our current for-7.1/upstream-fixes.
Could you rebase on top of this branch so we can take this without me messing with your patch?
Cheers,
Benjamin
Quoted 30 lines · Benjamin Tissoires
Quoted 29 lines · Lee Jones
Quoted 16 lines · Ping Cheng
Quoted 15 lines · Lee Jones
wacom_hid_set_device_mode()currently assumes that theHID_DG_INPUTMODEusage is always located in the first field (field[0]) of the feature report. However, a device can specifyHID_DG_INPUTMODEin a different field.If
HID_DG_INPUTMODEis in a field other than the first one and the first field has areport_countsmaller than theusage_indexofHID_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_INPUTMODEin 'structhid_data' during feature mapping. Inwacom_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.Quoted 8 lines
Quoted 3 lines
Fixes 5ae6e89f7409 ("HID: wacom: implement the finger part of the HID generic handling")Signed-off-by Lee Jones <[email protected]>Patch looks sensible to me. Thank you for your effort, Lee!
Tested-by Ping Cheng <[email protected]>Reviewed-by Ping Cheng <[email protected]>Thank you Ping, I appreciate your review.
Quoted 8 lines
Quoted 2 lines
HID folks - any movement on this please?
I wanted to apply it today, but the patch conflicts with our current for-7.1/upstream-fixes.
Could you rebase on top of this branch so we can take this without me messing with your patch?
Sure. Leave it with me. Probably be early next week.
Signature · 1 line
Lee Jones
Quoted 35 lines · Lee Jones
Quoted 33 lines · Benjamin Tissoires
Quoted 31 lines · Lee Jones
Quoted 16 lines · Ping Cheng
Quoted 15 lines · Lee Jones
wacom_hid_set_device_mode()currently assumes that theHID_DG_INPUTMODEusage is always located in the first field (field[0]) of the feature report. However, a device can specifyHID_DG_INPUTMODEin a different field.If
HID_DG_INPUTMODEis in a field other than the first one and the first field has areport_countsmaller than theusage_indexofHID_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_INPUTMODEin 'structhid_data' during feature mapping. Inwacom_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.Quoted 8 lines
Quoted 3 lines
Fixes 5ae6e89f7409 ("HID: wacom: implement the finger part of the HID generic handling")Signed-off-by Lee Jones <[email protected]>Patch looks sensible to me. Thank you for your effort, Lee!
Tested-by Ping Cheng <[email protected]>Reviewed-by Ping Cheng <[email protected]>Thank you Ping, I appreciate your review.
HID folks - any movement on this please?
Quoted 7 lines
Quoted 5 lines
I wanted to apply it today, but the patch conflicts with our current for-7.1/upstream-fixes.
Could you rebase on top of this branch so we can take this without me messing with your patch?
Sure. Leave it with me. Probably be early next week.
Are you sure this conflicted?
I just rebased it onto hid/for-7.1/upstream-fixes without issue.
Signature · 1 line
Lee Jones
Quoted 40 lines · Lee Jones
Quoted 38 lines · Lee Jones
Quoted 36 lines · Benjamin Tissoires
Quoted 22 lines · Lee Jones
Quoted 20 lines · Ping Cheng
Quoted 18 lines · Lee Jones
wacom_hid_set_device_mode()currently assumes that theHID_DG_INPUTMODEusage is always located in the first field (field[0]) of the feature report. However, a device can specifyHID_DG_INPUTMODEin a different field.If
HID_DG_INPUTMODEis in a field other than the first one and the first field has areport_countsmaller than theusage_indexofHID_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_INPUTMODEin 'structhid_data' during feature mapping. Inwacom_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.Fixes 5ae6e89f7409 ("HID: wacom: implement the finger part of the HID generic handling")Signed-off-by Lee Jones <[email protected]>Quoted 9 lines
Quoted 4 lines
Patch looks sensible to me. Thank you for your effort, Lee!
Tested-by Ping Cheng <[email protected]>Reviewed-by Ping Cheng <[email protected]>Thank you Ping, I appreciate your review.
HID folks - any movement on this please?
I wanted to apply it today, but the patch conflicts with our current for-7.1/upstream-fixes.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Could you rebase on top of this branch so we can take this without me messing with your patch?
Sure. Leave it with me. Probably be early next week.
Are you sure this conflicted?
I just rebased it onto hid/for-7.1/upstream-fixes without issue.
Rebased patch here (not sure if it's actually different:
https://lore.kernel.org/all/[email protected]/
Signature · 1 line
Lee Jones