Skip to content

Commit bfb0195

Browse files
author
Jiri Kosina
committed
Merge branch 'for-6.17/core' into for-linus
- hardening of HID core parser against conversion to 0 bits in s32ton() by buggy/malicious devices (Alan Stern)
2 parents 069e79a + a6b87bf commit bfb0195

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

drivers/hid/hid-core.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,12 @@ static s32 snto32(__u32 value, unsigned int n)
6666

6767
static u32 s32ton(__s32 value, unsigned int n)
6868
{
69-
s32 a = value >> (n - 1);
69+
s32 a;
7070

71+
if (!value || !n)
72+
return 0;
73+
74+
a = value >> (n - 1);
7175
if (a && a != -1)
7276
return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
7377
return value & ((1 << n) - 1);
@@ -659,9 +663,9 @@ static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
659663
default:
660664
if (item->tag >= HID_MAIN_ITEM_TAG_RESERVED_MIN &&
661665
item->tag <= HID_MAIN_ITEM_TAG_RESERVED_MAX)
662-
hid_warn(parser->device, "reserved main item tag 0x%x\n", item->tag);
666+
hid_warn_ratelimited(parser->device, "reserved main item tag 0x%x\n", item->tag);
663667
else
664-
hid_warn(parser->device, "unknown main item tag 0x%x\n", item->tag);
668+
hid_warn_ratelimited(parser->device, "unknown main item tag 0x%x\n", item->tag);
665669
ret = 0;
666670
}
667671

@@ -2806,7 +2810,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
28062810
{
28072811
struct hid_device *hdev = container_of(dev, struct hid_device, dev);
28082812

2809-
return scnprintf(buf, PAGE_SIZE, "hid:b%04Xg%04Xv%08Xp%08X\n",
2813+
return sysfs_emit(buf, "hid:b%04Xg%04Xv%08Xp%08X\n",
28102814
hdev->bus, hdev->group, hdev->vendor, hdev->product);
28112815
}
28122816
static DEVICE_ATTR_RO(modalias);

drivers/hid/hid-debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3726,7 +3726,7 @@ static ssize_t hid_debug_events_read(struct file *file, char __user *buffer,
37263726
*/
37273727
if (!list->hdev || !list->hdev->debug) {
37283728
ret = -EIO;
3729-
set_current_state(TASK_RUNNING);
3729+
__set_current_state(TASK_RUNNING);
37303730
goto out;
37313731
}
37323732

drivers/hid/hid-lg4ff.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ static ssize_t lg4ff_combine_show(struct device *dev, struct device_attribute *a
956956
return 0;
957957
}
958958

959-
count = scnprintf(buf, PAGE_SIZE, "%u\n", entry->wdata.combine);
959+
count = sysfs_emit(buf, "%u\n", entry->wdata.combine);
960960
return count;
961961
}
962962

@@ -1009,7 +1009,7 @@ static ssize_t lg4ff_range_show(struct device *dev, struct device_attribute *att
10091009
return 0;
10101010
}
10111011

1012-
count = scnprintf(buf, PAGE_SIZE, "%u\n", entry->wdata.range);
1012+
count = sysfs_emit(buf, "%u\n", entry->wdata.range);
10131013
return count;
10141014
}
10151015

@@ -1073,7 +1073,7 @@ static ssize_t lg4ff_real_id_show(struct device *dev, struct device_attribute *a
10731073
return 0;
10741074
}
10751075

1076-
count = scnprintf(buf, PAGE_SIZE, "%s: %s\n", entry->wdata.real_tag, entry->wdata.real_name);
1076+
count = sysfs_emit(buf, "%s: %s\n", entry->wdata.real_tag, entry->wdata.real_name);
10771077
return count;
10781078
}
10791079

include/linux/hid.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,11 @@ static inline void hid_hw_wait(struct hid_device *hdev)
12161216
/**
12171217
* hid_report_len - calculate the report length
12181218
*
1219-
* @report: the report we want to know the length
1219+
* @report: the report whose length we want to know
1220+
*
1221+
* The length counts the report ID byte, but only if the ID is nonzero
1222+
* and therefore is included in the report. Reports whose ID is zero
1223+
* never include an ID byte.
12201224
*/
12211225
static inline u32 hid_report_len(struct hid_report *report)
12221226
{
@@ -1239,6 +1243,8 @@ void hid_quirks_exit(__u16 bus);
12391243
dev_notice(&(hid)->dev, fmt, ##__VA_ARGS__)
12401244
#define hid_warn(hid, fmt, ...) \
12411245
dev_warn(&(hid)->dev, fmt, ##__VA_ARGS__)
1246+
#define hid_warn_ratelimited(hid, fmt, ...) \
1247+
dev_warn_ratelimited(&(hid)->dev, fmt, ##__VA_ARGS__)
12421248
#define hid_info(hid, fmt, ...) \
12431249
dev_info(&(hid)->dev, fmt, ##__VA_ARGS__)
12441250
#define hid_dbg(hid, fmt, ...) \

0 commit comments

Comments
 (0)