Skip to content

Commit b17d081

Browse files
rddunlapksacilotto
authored andcommitted
HID: core: detect and skip invalid inputs to snto32()
BugLink: https://bugs.launchpad.net/bugs/1918974 [ Upstream commit a0312af ] Prevent invalid (0, 0) inputs to hid-core's snto32() function. Maybe it is just the dummy device here that is causing this, but there are hundreds of calls to snto32(0, 0). Having n (bits count) of 0 is causing the current UBSAN trap with a shift value of 0xffffffff (-1, or n - 1 in this function). Either of the value to shift being 0 or the bits count being 0 can be handled by just returning 0 to the caller, avoiding the following complex shift + OR operations: return value & (1 << (n - 1)) ? value | (~0U << n) : value; Fixes: dde5845 ("[PATCH] Generic HID layer - code split") Signed-off-by: Randy Dunlap <rdunlap@infradead.org> Reported-by: syzbot+1e911ad71dd4ea72e04a@syzkaller.appspotmail.com Cc: Jiri Kosina <jikos@kernel.org> Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com> Cc: linux-input@vger.kernel.org Signed-off-by: Jiri Kosina <jkosina@suse.cz> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
1 parent 5994d72 commit b17d081

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/hid/hid-core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,9 @@ EXPORT_SYMBOL_GPL(hid_open_report);
13001300

13011301
static s32 snto32(__u32 value, unsigned n)
13021302
{
1303+
if (!value || !n)
1304+
return 0;
1305+
13031306
switch (n) {
13041307
case 8: return ((__s8)value);
13051308
case 16: return ((__s16)value);

0 commit comments

Comments
 (0)