Skip to content

Commit 4051ead

Browse files
FirstLoveLifeJiri Kosina
authored andcommitted
HID: rate-limit hid_warn to prevent log flooding
Syzkaller can create many uhid devices that trigger repeated warnings like: "hid-generic xxxx: unknown main item tag 0x0" These messages can flood the system log, especially if a crash occurs (e.g., with a slow UART console, leading to soft lockups). To mitigate this, convert `hid_warn()` to use `dev_warn_ratelimited()`. This helps reduce log noise and improves system stability under fuzzing or faulty device scenarios. Signed-off-by: Li Chen <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 37a9acb commit 4051ead

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

drivers/hid/hid-core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,9 @@ static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
659659
default:
660660
if (item->tag >= HID_MAIN_ITEM_TAG_RESERVED_MIN &&
661661
item->tag <= HID_MAIN_ITEM_TAG_RESERVED_MAX)
662-
hid_warn(parser->device, "reserved main item tag 0x%x\n", item->tag);
662+
hid_warn_ratelimited(parser->device, "reserved main item tag 0x%x\n", item->tag);
663663
else
664-
hid_warn(parser->device, "unknown main item tag 0x%x\n", item->tag);
664+
hid_warn_ratelimited(parser->device, "unknown main item tag 0x%x\n", item->tag);
665665
ret = 0;
666666
}
667667

include/linux/hid.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,8 @@ void hid_quirks_exit(__u16 bus);
12391239
dev_notice(&(hid)->dev, fmt, ##__VA_ARGS__)
12401240
#define hid_warn(hid, fmt, ...) \
12411241
dev_warn(&(hid)->dev, fmt, ##__VA_ARGS__)
1242+
#define hid_warn_ratelimited(hid, fmt, ...) \
1243+
dev_warn_ratelimited(&(hid)->dev, fmt, ##__VA_ARGS__)
12421244
#define hid_info(hid, fmt, ...) \
12431245
dev_info(&(hid)->dev, fmt, ##__VA_ARGS__)
12441246
#define hid_dbg(hid, fmt, ...) \

0 commit comments

Comments
 (0)