HID: core: Fix out-of-bounds left shift by 32 in s32ton()

Syzbot reported an out-of-bounds shift (32-bit integer shifted left by
32) in the s32ton() routine in the HID core.  This routine converts a
signed 32-bit integer to a signed n-bit integer, and it caps the value
of n at 32.  But when n == 32 there's no need to do anything; it can
simply return the input value.  This will avoid calculating (1 << n)
when n is 32, which was the cause of the invalid shift.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Fixes: 69c02ffde6 ("HID: core: clamp report_size in s32ton() to avoid undefined shift")
Reported-by: syzbot+25a1d2907885b2182275@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/linux-usb/6ac9cbd8.a150a118.27e199.0025.GAE@google.com/
Tested-by: syzbot+25a1d2907885b2182275@syzkaller.appspotmail.com
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/dfa0aa1c-e55e-4316-8307-f72a07383634@rowland.harvard.edu
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
This commit is contained in:
Alan Stern 2026-10-10 13:44:15 -04:00 committed by Benjamin Tissoires
parent 143b379a04
commit 5fe63b415c

View File

@ -71,8 +71,8 @@ static u32 s32ton(__s32 value, unsigned int n)
if (!value || !n)
return 0;
if (n > 32)
n = 32;
if (n >= 32)
return (u32) value;
a = value >> (n - 1);
if (a && a != -1)