HID: core: check field offset before dumping input
PATCH 1/1 HID: core: check field offset before dumping input
hid_set_field() passes field->usage + offset to hid_dump_input() before validating offset against field->report_count. field->usage is allocated with exactly report_count entries, so a larger offset is read out of bounds before the existing check rejects it:
BUG: KASAN: slab-out-of-bounds in hid_dump_input+0xcb/0xd0 Read of size 4 at addr ffff88802ab28fc0 by task kworker/1:2/48
Move the bounds check above the hid_dump_input() call so the function returns before the dereference.
--- drivers/hid/hid-core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hid/hid-core.c +3 -2
@@ -1933,13 +1933,14 @@ int hid_set_field(struct hid_field *field, unsigned offset, __s32 value) size = field->report_size; -hid_dump_input (field->report->device, field->usage + offset, value); -if (offset >= field->report_count) {hid_err (field->report->device,"offset (%d) exceeds report_count (%d)\n" , offset, field->report_count);return -1 ; } + +hid_dump_input (field->report->device, field->usage + offset, value); +if (field->logical_minimum <0 ) {if (value !=snto32 (s32ton (value, size), size)) {hid_err (field->report->device,"value %d is out of range\n" , value);
Signature · 1 line
2.43.0
Quoted 42 lines · Deepanshu Kartikey
hid_set_field()passesfield->usage+ offset tohid_dump_input()before validating offset againstfield->report_count.field->usageis allocated with exactlyreport_countentries, so a larger offset is read out of bounds before the existing check rejects it:BUG: KASAN: slab-out-of-bounds in hid_dump_input+0xcb/0xd0 Read of size 4 at addr ffff88802ab28fc0 by task kworker/1:2/48Move the bounds check above the
hid_dump_input()call so the function returns before the dereference.Reported-by [email protected]Tested-by [email protected]Signed-off-by Deepanshu Kartikey <[email protected]>--- drivers/hid/hid-core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/hid/hid-core.c +3
-3@@ -1933,13 +1933,14 @@ int hid_set_field(struct hid_field *field, unsigned offset, __s32 value) size = field->report_size; -hid_dump_input (field->report->device, field->usage + offset, value); -if (offset >= field->report_count) {hid_err (field->report->device,"offset (%d) exceeds report_count (%d)\n" , offset, field->report_count);return -1 ; } + +hid_dump_input (field->report->device, field->usage + offset, value); +if (field->logical_minimum <0 ) {if (value !=snto32 (s32ton (value, size), size)) {hid_err (field->report->device,"value %d is out of range\n" , value); --
Quoted 2 lines
2.43.0
Gentle Reminder. Please let me know the status of this patch
Thanks
Deepanshu
Jiri Kosina
maintainerQuoted 37 lines · Deepanshu Kartikey
Quoted 37 lines
hid_set_field()passesfield->usage+ offset tohid_dump_input()before validating offset againstfield->report_count.field->usageis allocated with exactlyreport_countentries, so a larger offset is read out of bounds before the existing check rejects it:BUG: KASAN: slab-out-of-bounds in hid_dump_input+0xcb/0xd0 Read of size 4 at addr ffff88802ab28fc0 by task kworker/1:2/48Move the bounds check above the
hid_dump_input()call so the function returns before the dereference.Reported-by [email protected]Tested-by [email protected]Signed-off-by Deepanshu Kartikey <[email protected]>--- drivers/hid/hid-core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/hid/hid-core.c +3
-2@@ -1933,13 +1933,14 @@ int hid_set_field(struct hid_field *field, unsigned offset, __s32 value) size = field->report_size; -hid_dump_input (field->report->device, field->usage + offset, value); -if (offset >= field->report_count) {hid_err (field->report->device,"offset (%d) exceeds report_count (%d)\n" , offset, field->report_count);return -1 ; } + +hid_dump_input (field->report->device, field->usage + offset, value); +
Quoted 8 lines
Quoted 6 lines
drivers/hid/hid-core.c +0
-1if (field->logical_minimum <0 ) {if (value !=snto32 (s32ton (value, size), size)) {hid_err (field->report->device,"value %d is out of range\n" , value); --2.43.0
Gentle Reminder. Please let me know the status of this patch
I believe this was already fixed in 7.3 via a13cdb19fcb2.
Signature · 2 lines
Jiri Kosina SUSE Labs