HID: multitouch: fix integer overflow in set_abs()
Subsystems (2)
PATCH 1/1 HID: multitouch: fix integer overflow in set_abs()
It is possible for a malicious HID device to trigger a signed integer overflow (undefined behaviour) in set_abs() in the following expression by supplying bogus logical maximum and minimum values:
int fuzz = snratio ? (fmax - fmin) / snratio : 0;
For example, if the logical_maximum is INT_MAX and logical_minimum is -1 then (fmax - fmin) resolves to INT_MAX + 1, which does not fit in a 32-bit signed int, so the subtraction overflows. Fix this by computing the difference in a 64 bit context.
--- drivers/hid/hid-multitouch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hid/hid-multitouch.c +2 -1
@@ -540,7 +540,8 @@ static void set_abs(struct input_dev *input, unsigned int code, {int fmin = field->logical_minimum;int fmax = field->logical_maximum; -int fuzz = snratio ? (fmax - fmin) / snratio :0 ; +s64 diff = (s64 )fmax - (s64 )fmin; +int fuzz = snratio ? (int )div_s64 (diff, snratio) :0 ;input_set_abs_params (input, code, fmin, fmax, fuzz,0 );input_abs_set_res (input, code,hidinput_calc_abs_res (field, code)); }
Signature · 1 line
2.39.5
Quoted 9 lines · Qasim Ijaz
It is possible for a malicious HID device to trigger a signed integer overflow (undefined behaviour) in
set_abs()in the following expression by supplying bogus logical maximum and minimum values:int fuzz = snratio ? (fmax - fmin) / snratio : 0;For example, if the
logical_maximumisINT_MAXandlogical_minimumis -1 then (fmax - fmin) resolves toINT_MAX+ 1, which does not fit in a 32-bit signed int, so the subtraction overflows.
The question is if it matters with -fwrapv?
Quoted 24 lines
Fix this by computing the
difference in a 64 bit context.Fixes 5519cab477b6 ("HID: hid-multitouch: support for PixCir-based panels")Signed-off-by Qasim Ijaz <[email protected]>--- drivers/hid/hid-multitouch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/hid/hid-multitouch.c +2
-1@@ -540,7 +540,8 @@ static void set_abs(struct input_dev *input, unsigned int code, {int fmin = field->logical_minimum;int fmax = field->logical_maximum; -int fuzz = snratio ? (fmax - fmin) / snratio :0 ; +s64 diff = (s64 )fmax - (s64 )fmin; +int fuzz = snratio ? (int )div_s64 (diff, snratio) :0 ;input_set_abs_params (input, code, fmin, fmax, fuzz,0 );input_abs_set_res (input, code,hidinput_calc_abs_res (field, code)); }
Signature · 2 lines
js suse labs
Quoted 5 lines · Jiri Slaby
Quoted 4 lines · Qasim Ijaz
It is possible for a malicious HID device to trigger a signed integer overflow (undefined behaviour) in
set_abs()in the following expression by supplying bogus logical maximum and minimum values:
Quoted 7 lines
Quoted 5 lines
int fuzz = snratio ? (fmax - fmin) / snratio : 0;For example, if the
logical_maximumisINT_MAXandlogical_minimumis -1 then (fmax - fmin) resolves toINT_MAX+ 1, which does not fit in a 32-bit signed int, so the subtraction overflows.The question is if it matters with -fwrapv?
Ah yea thanks for bringing this up Jiri. I think you might be correct, after doing some research it looks like the kernel enables -fno‑strict‑overflow which implies -fwrapv which leads to wrap around instead of UB If I undestand correctly. So with that in mind this patch probably doesn't do anything useful, do you agree?
Thanks
qasim.
Quoted 30 lines
Quoted 25 lines
Fix this by computing the
difference in a 64 bit context.Fixes 5519cab477b6 ("HID: hid-multitouch: support for PixCir-based panels")Signed-off-by Qasim Ijaz <[email protected]>--- drivers/hid/hid-multitouch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/hid/hid-multitouch.c +2
-1@@ -540,7 +540,8 @@ static void set_abs(struct input_dev *input, unsigned int code, {int fmin = field->logical_minimum;int fmax = field->logical_maximum; -int fuzz = snratio ? (fmax - fmin) / snratio :0 ; +s64 diff = (s64 )fmax - (s64 )fmin; +int fuzz = snratio ? (int )div_s64 (diff, snratio) :0 ;input_set_abs_params (input, code, fmin, fmax, fuzz,0 );input_abs_set_res (input, code,hidinput_calc_abs_res (field, code)); }Signature · 2 lines
js suse labs
Quoted 12 lines · Qasim Ijaz
Quoted 11 lines · Jiri Slaby
Quoted 9 lines · Qasim Ijaz
It is possible for a malicious HID device to trigger a signed integer overflow (undefined behaviour) in
set_abs()in the following expression by supplying bogus logical maximum and minimum values:int fuzz = snratio ? (fmax - fmin) / snratio : 0;For example, if the
logical_maximumisINT_MAXandlogical_minimumis -1 then (fmax - fmin) resolves toINT_MAX+ 1, which does not fit in a 32-bit signed int, so the subtraction overflows.
Quoted 7 lines
Quoted 1 line
The question is if it matters with -fwrapv?
Ah yea thanks for bringing this up Jiri. I think you might be correct, after doing some research it looks like the kernel enables -fno‑strict‑overflow which implies -fwrapv which leads to wrap around instead of UB If I undestand correctly. So with that in mind this patch probably doesn't do anything useful, do you agree?
Yes, it correctly wraps around. But the question remains :). Does it matter or not?
thanks,
Signature · 2 lines
js suse labs
Quoted 15 lines · Jiri Slaby
Quoted 14 lines · Qasim Ijaz
Quoted 12 lines · Jiri Slaby
Quoted 9 lines · Qasim Ijaz
It is possible for a malicious HID device to trigger a signed integer overflow (undefined behaviour) in
set_abs()in the following expression by supplying bogus logical maximum and minimum values:int fuzz = snratio ? (fmax - fmin) / snratio : 0;For example, if the
logical_maximumisINT_MAXandlogical_minimumis -1 then (fmax - fmin) resolves toINT_MAX+ 1, which does not fit in a 32-bit signed int, so the subtraction overflows.The question is if it matters with -fwrapv?
Quoted 9 lines
Quoted 5 lines
Ah yea thanks for bringing this up Jiri. I think you might be correct, after doing some research it looks like the kernel enables -fno‑strict‑overflow which implies -fwrapv which leads to wrap around instead of UB If I undestand correctly. So with that in mind this patch probably doesn't do anything useful, do you agree?
Yes, it correctly wraps around. But the question remains :). Does it matter or not?
probably not. From what I can tell it doesn't look like any further security issues occur as a result of the wrap around behaviour so i think its probably best to drop this patch.
thanks,
qasim
Quoted 4 lines
thanks,
Signature · 2 lines
js suse labs