Skip to contentSkip to conversation

HID: rate-limit hid_warn to prevent log flooding

PATCH Superseded Li Chen 2 participants 3 messages Jun 20, 2025 HID

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Li Chen

author
#0 lore raw

PATCH v2 1/1 HID: rate-limit hid_warn to prevent log flooding

From: Li Chen <[email protected]>

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.

---
Changelog:

v2: Introduce hid_warn_ratelimited to rate-limit the specified log.

 drivers/hid/hid-core.c | 2 +-
 include/linux/hid.h    | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/hid/hid-core.c +1 -1
index b348d0464314c..aaba7164a8c9a 100644
@@ -661,7 +661,7 @@ static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
 			item->tag <= HID_MAIN_ITEM_TAG_RESERVED_MAX)
 			hid_warn(parser->device, "reserved main item tag 0x%x\n", item->tag);
 		else
-			hid_warn(parser->device, "unknown main item tag 0x%x\n", item->tag);
+			hid_warn_ratelimited(parser->device, "unknown main item tag 0x%x\n", item->tag);
 		ret = 0;
 	}
 
include/linux/hid.h +2 -0
index 568a9d8c749bc..7f260e0e20498 100644
@@ -1239,6 +1239,8 @@ void hid_quirks_exit(__u16 bus);
 	dev_notice(&(hid)->dev, fmt, ##__VA_ARGS__)
 #define hid_warn(hid, fmt, ...)				\
 	dev_warn(&(hid)->dev, fmt, ##__VA_ARGS__)
+#define hid_warn_ratelimited(hid, fmt, ...)				\
+	dev_warn_ratelimited(&(hid)->dev, fmt, ##__VA_ARGS__)
 #define hid_info(hid, fmt, ...)				\
 	dev_info(&(hid)->dev, fmt, ##__VA_ARGS__)
 #define hid_dbg(hid, fmt, ...)				\
Signature · 1 line
2.49.0
maintainer
#1 lore raw
Quoted 29 lines · Li Chen

From: Li Chen <[email protected]>

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.

---
Changelog:

v2: Introduce hid_warn_ratelimited to rate-limit the specified log.

 drivers/hid/hid-core.c | 2 +-
 include/linux/hid.h    | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/hid/hid-core.c +0 -0
index b348d0464314c..aaba7164a8c9a 100644

drivers/hid/hid-core.c static int hid_parser_main(struct hid_parser *parser, struct hid_item *item) · line 665

Quoted 6 lines
drivers/hid/hid-core.c +1 -1
@@ -661,7 +661,7 @@ static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
 			item->tag <= HID_MAIN_ITEM_TAG_RESERVED_MAX)
 			hid_warn(parser->device, "reserved main item tag 0x%x\n", item->tag);
 		else
-			hid_warn(parser->device, "unknown main item tag 0x%x\n", item->tag);
+			hid_warn_ratelimited(parser->device, "unknown main item tag 0x%x\n", item->tag);
 		ret = 0;

While I agree in principle that we shouldn't be flooding dmesg in case the report descriptor is completely bogus, I think we should be more consistent then.

I am pretty sure syzkaller produce report descriptors that will emit flood of "reserved main item tag", but you don't seem to be addresing that case?

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
author
#2 lore raw

Hi Jiri

---- On Fri, 20 Jun 2025 15:09:37 +0800 Jiri Kosina <[email protected]> wrote ---

Quoted 42 lines · Li Chen
Quoted 30 lines

From: Li Chen <[email protected]>

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.

---
Changelog:

v2: Introduce hid_warn_ratelimited to rate-limit the specified log.

 drivers/hid/hid-core.c | 2 +-
 include/linux/hid.h    | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/hid/hid-core.c +0 -0
index b348d0464314c..aaba7164a8c9a 100644

drivers/hid/hid-core.c static int hid_parser_main(struct hid_parser *parser, struct hid_item *item) · line 665

Quoted 6 lines
drivers/hid/hid-core.c +1 -1
@@ -661,7 +661,7 @@ static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
             item->tag <= HID_MAIN_ITEM_TAG_RESERVED_MAX)
             hid_warn(parser->device, "reserved main item tag 0x%x\n", item->tag);
         else
-            hid_warn(parser->device, "unknown main item tag 0x%x\n", item->tag);
+            hid_warn_ratelimited(parser->device, "unknown main item tag 0x%x\n", item->tag);
         ret = 0;

While I agree in principle that we shouldn't be flooding dmesg in case the report descriptor is completely bogus, I think we should be more consistent then.

Quoted 2 lines

I am pretty sure syzkaller produce report descriptors that will emit flood of "reserved main item tag", but you don't seem to be addresing that case?

Thanks for the suggestion. Perhaps the shorter "reserved main item tag" didn't corrupt my system, so I didn't notice. I'll ratelimit it in v3.

Regards,
Li