In the Linux kernel, the following vulnerability has been resolved:
HID: core: fix shift-out-of-bounds in hidreportraw_event
Syzbot reported shift-out-of-bounds in hidreportraw_event.
microsoft 0003:045E:07DA.0001: hidfieldextract() called with n (128) >
UBSAN: shift-out-of-bounds in drivers/hid/hid-core.c:1323:20 shift exponent 127 is too large for 32-bit type 'int' CPU: 0 PID: 0 Comm: swapper/0 Not tainted 6.1.0-rc4-syzkaller-00159-g4bbf3422df78 #0 Hardware name: Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022 Call Trace: <IRQ> _dumpstack lib/dumpstack.c:88 [inline] dumpstacklvl+0x1e3/0x2cb lib/dumpstack.c:106 ubsanepilogue lib/ubsan.c:151 [inline] _ubsanhandleshiftoutofbounds+0x3a6/0x420 lib/ubsan.c:322 snto32 drivers/hid/hid-core.c:1323 [inline] hidinputfetchfield drivers/hid/hid-core.c:1572 [inline] hidprocessreport drivers/hid/hid-core.c:1665 [inline] hidreportrawevent+0xd56/0x18b0 drivers/hid/hid-core.c:1998 hidinputreport+0x408/0x4f0 drivers/hid/hid-core.c:2066 hidirqin+0x459/0x690 drivers/hid/usbhid/hid-core.c:284 _usbhcdgivebackurb+0x369/0x530 drivers/usb/core/hcd.c:1671 dummytimer+0x86b/0x3110 drivers/usb/gadget/udc/dummyhcd.c:1988 calltimerfn+0xf5/0x210 kernel/time/timer.c:1474 expiretimers kernel/time/timer.c:1519 [inline] _runtimers+0x76a/0x980 kernel/time/timer.c:1790 runtimersoftirq+0x63/0xf0 kernel/time/timer.c:1803 _dosoftirq+0x277/0x75b kernel/softirq.c:571 _irqexitrcu+0xec/0x170 kernel/softirq.c:650 irqexit_rcu+0x5/0x20 kernel/softirq.c:662
If the size of the integer (unsigned n) is bigger than 32 in snto32(), shift exponent will be too large for 32-bit type 'int', resulting in a shift-out-of-bounds bug. Fix this by adding a check on the size of the integer (unsigned n) in snto32(). To add support for n greater than 32 bits, set n to 32, if n is greater than 32.