Skip to content

Commit 14d11ba

Browse files
committed
HID: stop exporting hid_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 c653ffc The only user of hid_snto32() is Logitech HID++ driver, which always calls hid_snto32() with valid size (constant, either 12 or 8) and therefore can simply use sign_extend32(). Make the switch and remove hid_snto32(). Move snto32() and s32ton() to avoid introducing forward declaration. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Link: https://patch.msgid.link/20241003144656.3786064-2-dmitry.torokhov@gmail.com [bentiss: fix checkpatch warning] Signed-off-by: Benjamin Tissoires <bentiss@kernel.org> (cherry picked from commit c653ffc) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 0b37d9c commit 14d11ba

File tree

3 files changed

+32
-38
lines changed

3 files changed

+32
-38
lines changed

drivers/hid/hid-core.c

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,34 @@ static int hid_ignore_special_drivers = 0;
5050
module_param_named(ignore_special_drivers, hid_ignore_special_drivers, int, 0600);
5151
MODULE_PARM_DESC(ignore_special_drivers, "Ignore any special drivers and handle all devices by generic driver");
5252

53+
/*
54+
* Convert a signed n-bit integer to signed 32-bit integer.
55+
*/
56+
57+
static s32 snto32(__u32 value, unsigned int n)
58+
{
59+
if (!value || !n)
60+
return 0;
61+
62+
if (n > 32)
63+
n = 32;
64+
65+
return sign_extend32(value, n - 1);
66+
}
67+
68+
/*
69+
* Convert a signed 32-bit integer to a signed n-bit integer.
70+
*/
71+
72+
static u32 s32ton(__s32 value, unsigned int n)
73+
{
74+
s32 a = value >> (n - 1);
75+
76+
if (a && a != -1)
77+
return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
78+
return value & ((1 << n) - 1);
79+
}
80+
5381
/*
5482
* Register a new report for a device.
5583
*/
@@ -423,7 +451,7 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
423451
* both this and the standard encoding. */
424452
raw_value = item_sdata(item);
425453
if (!(raw_value & 0xfffffff0))
426-
parser->global.unit_exponent = hid_snto32(raw_value, 4);
454+
parser->global.unit_exponent = snto32(raw_value, 4);
427455
else
428456
parser->global.unit_exponent = raw_value;
429457
return 0;
@@ -1299,39 +1327,6 @@ int hid_open_report(struct hid_device *device)
12991327
}
13001328
EXPORT_SYMBOL_GPL(hid_open_report);
13011329

1302-
/*
1303-
* Convert a signed n-bit integer to signed 32-bit integer.
1304-
*/
1305-
1306-
static s32 snto32(__u32 value, unsigned n)
1307-
{
1308-
if (!value || !n)
1309-
return 0;
1310-
1311-
if (n > 32)
1312-
n = 32;
1313-
1314-
return sign_extend32(value, n - 1);
1315-
}
1316-
1317-
s32 hid_snto32(__u32 value, unsigned n)
1318-
{
1319-
return snto32(value, n);
1320-
}
1321-
EXPORT_SYMBOL_GPL(hid_snto32);
1322-
1323-
/*
1324-
* Convert a signed 32-bit integer to a signed n-bit integer.
1325-
*/
1326-
1327-
static u32 s32ton(__s32 value, unsigned n)
1328-
{
1329-
s32 a = value >> (n - 1);
1330-
if (a && a != -1)
1331-
return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
1332-
return value & ((1 << n) - 1);
1333-
}
1334-
13351330
/*
13361331
* Extract/implement a data field from/to a little endian report (bit array).
13371332
*

drivers/hid/hid-logitech-hidpp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3013,13 +3013,13 @@ static int m560_raw_event(struct hid_device *hdev, u8 *data, int size)
30133013
120);
30143014
}
30153015

3016-
v = hid_snto32(hid_field_extract(hdev, data+3, 0, 12), 12);
3016+
v = sign_extend32(hid_field_extract(hdev, data + 3, 0, 12), 11);
30173017
input_report_rel(hidpp->input, REL_X, v);
30183018

3019-
v = hid_snto32(hid_field_extract(hdev, data+3, 12, 12), 12);
3019+
v = sign_extend32(hid_field_extract(hdev, data + 3, 12, 12), 11);
30203020
input_report_rel(hidpp->input, REL_Y, v);
30213021

3022-
v = hid_snto32(data[6], 8);
3022+
v = sign_extend32(data[6], 7);
30233023
if (v != 0)
30243024
hidpp_scroll_counter_handle_scroll(hidpp->input,
30253025
&hidpp->vertical_wheel_counter, v);

include/linux/hid.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,6 @@ const struct hid_device_id *hid_match_device(struct hid_device *hdev,
919919
struct hid_driver *hdrv);
920920
bool hid_compare_device_paths(struct hid_device *hdev_a,
921921
struct hid_device *hdev_b, char separator);
922-
s32 hid_snto32(__u32 value, unsigned n);
923922
__u32 hid_field_extract(const struct hid_device *hid, __u8 *report,
924923
unsigned offset, unsigned n);
925924

0 commit comments

Comments
 (0)