Skip to content

Commit 0b37d9c

Browse files
committed
HID: simplify snto32()
jira LE-4321 cve CVE-2025-38556 Rebuild_History Non-Buildable kernel-4.18.0-553.76.1.el8_10 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 12d8cbb commit 0b37d9c

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
@@ -1300,9 +1300,7 @@ int hid_open_report(struct hid_device *device)
13001300
EXPORT_SYMBOL_GPL(hid_open_report);
13011301

13021302
/*
1303-
* Convert a signed n-bit integer to signed 32-bit integer. Common
1304-
* cases are done through the compiler, the screwed things has to be
1305-
* done by hand.
1303+
* Convert a signed n-bit integer to signed 32-bit integer.
13061304
*/
13071305

13081306
static s32 snto32(__u32 value, unsigned n)
@@ -1313,12 +1311,7 @@ static s32 snto32(__u32 value, unsigned n)
13131311
if (n > 32)
13141312
n = 32;
13151313

1316-
switch (n) {
1317-
case 8: return ((__s8)value);
1318-
case 16: return ((__s16)value);
1319-
case 32: return ((__s32)value);
1320-
}
1321-
return value & (1 << (n - 1)) ? value | (~0U << n) : value;
1314+
return sign_extend32(value, n - 1);
13221315
}
13231316

13241317
s32 hid_snto32(__u32 value, unsigned n)

0 commit comments

Comments
 (0)