]> git.hungrycats.org Git - linux/commitdiff
HID: core: Fix out-of-bounds left shift by 32 in s32ton()
authorAlan Stern <stern@rowland.harvard.edu>
Sat, 10 Oct 2026 17:44:15 +0000 (13:44 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Nov 2026 17:10:50 +0000 (12:10 -0500)
commit 5fe63b415c636c7f4f6848a8e53bdd4bbf0c300d upstream.

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: 69c02ffde6ed ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/hid/hid-core.c

index a3ff0514f9cdf8daa8adeb57684adfa16beed6d1..a71ddaa810a036a77bcc4006ca7599c34c0261a2 100644 (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)