Skip to content

Commit 5b4fd69

Browse files
committed
HID: simplify snto32()
jira LE-4395 cve CVE-2025-38556 Rebuild_History Non-Buildable kernel-6.12.0-55.39.1.el10_0 commit-author Dmitry Torokhov <dmitry.torokhov@gmail.com> commit ae9b956 snto32() does exactly what sign_extend32() does, but handles potentially malformed data coming from the device. Keep the checks, but then call sign_extend32() to perform the actual conversion. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Link: https://patch.msgid.link/20241003144656.3786064-1-dmitry.torokhov@gmail.com Signed-off-by: Benjamin Tissoires <bentiss@kernel.org> (cherry picked from commit ae9b956) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 877959e commit 5b4fd69

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

drivers/hid/hid-core.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,9 +1316,7 @@ int hid_open_report(struct hid_device *device)
13161316
EXPORT_SYMBOL_GPL(hid_open_report);
13171317

13181318
/*
1319-
* Convert a signed n-bit integer to signed 32-bit integer. Common
1320-
* cases are done through the compiler, the screwed things has to be
1321-
* done by hand.
1319+
* Convert a signed n-bit integer to signed 32-bit integer.
13221320
*/
13231321

13241322
static s32 snto32(__u32 value, unsigned n)
@@ -1329,12 +1327,7 @@ static s32 snto32(__u32 value, unsigned n)
13291327
if (n > 32)
13301328
n = 32;
13311329

1332-
switch (n) {
1333-
case 8: return ((__s8)value);
1334-
case 16: return ((__s16)value);
1335-
case 32: return ((__s32)value);
1336-
}
1337-
return value & (1 << (n - 1)) ? value | (~0U << n) : value;
1330+
return sign_extend32(value, n - 1);
13381331
}
13391332

13401333
s32 hid_snto32(__u32 value, unsigned n)

0 commit comments

Comments
 (0)