Skip to content

Commit 2706687

Browse files
committed
HID: core: Harden s32ton() against conversion to 0 bits
jira LE-4321 cve CVE-2025-38556 Rebuild_History Non-Buildable kernel-4.18.0-553.76.1.el8_10 commit-author Alan Stern <stern@rowland.harvard.edu> commit a6b87bf Testing by the syzbot fuzzer showed that the HID core gets a shift-out-of-bounds exception when it tries to convert a 32-bit quantity to a 0-bit quantity. Ideally this should never occur, but there are buggy devices and some might have a report field with size set to zero; we shouldn't reject the report or the device just because of that. Instead, harden the s32ton() routine so that it returns a reasonable result instead of crashing when it is called with the number of bits set to 0 -- the same as what snto32() does. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Reported-by: syzbot+b63d677d63bcac06cf90@syzkaller.appspotmail.com Closes: https://lore.kernel.org/linux-usb/68753a08.050a0220.33d347.0008.GAE@google.com/ Tested-by: syzbot+b63d677d63bcac06cf90@syzkaller.appspotmail.com Fixes: dde5845 ("[PATCH] Generic HID layer - code split") Cc: stable@vger.kernel.org Link: https://patch.msgid.link/613a66cd-4309-4bce-a4f7-2905f9bce0c9@rowland.harvard.edu Signed-off-by: Benjamin Tissoires <bentiss@kernel.org> (cherry picked from commit a6b87bf) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 14d11ba commit 2706687

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/hid/hid-core.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,12 @@ static s32 snto32(__u32 value, unsigned int n)
7171

7272
static u32 s32ton(__s32 value, unsigned int n)
7373
{
74-
s32 a = value >> (n - 1);
74+
s32 a;
7575

76+
if (!value || !n)
77+
return 0;
78+
79+
a = value >> (n - 1);
7680
if (a && a != -1)
7781
return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
7882
return value & ((1 << n) - 1);

0 commit comments

Comments
 (0)