mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] HID: rate-limit hid_warn to prevent log flooding
@ 2025-06-20 12:02 Li Chen
  2025-06-20 13:35 ` Jiri Kosina
  0 siblings, 1 reply; 2+ messages in thread
From: Li Chen @ 2025-06-20 12:02 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel

From: Li Chen <chenl311@chinatelecom.cn>

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 <chenl311@chinatelecom.cn>
---
Changelog:

v2: Introduce hid_warn_ratelimited to rate-limit the specified log.
v3: also ratelimit "reserved main item tag ..."

 drivers/hid/hid-core.c | 4 ++--
 include/linux/hid.h    | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index b348d0464314c..7d6750f05324f 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -659,9 +659,9 @@ static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
 	default:
 		if (item->tag >= HID_MAIN_ITEM_TAG_RESERVED_MIN &&
 			item->tag <= HID_MAIN_ITEM_TAG_RESERVED_MAX)
-			hid_warn(parser->device, "reserved main item tag 0x%x\n", item->tag);
+			hid_warn_ratelimited(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;
 	}
 
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 568a9d8c749bc..7f260e0e20498 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -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, ...)				\
-- 
2.49.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] HID: rate-limit hid_warn to prevent log flooding
  2025-06-20 12:02 [PATCH v3] HID: rate-limit hid_warn to prevent log flooding Li Chen
@ 2025-06-20 13:35 ` Jiri Kosina
  0 siblings, 0 replies; 2+ messages in thread
From: Jiri Kosina @ 2025-06-20 13:35 UTC (permalink / raw)
  To: Li Chen; +Cc: Benjamin Tissoires, linux-input, linux-kernel

On Fri, 20 Jun 2025, Li Chen wrote:

> From: Li Chen <chenl311@chinatelecom.cn>
> 
> 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 <chenl311@chinatelecom.cn>
> ---
> Changelog:
> 
> v2: Introduce hid_warn_ratelimited to rate-limit the specified log.
> v3: also ratelimit "reserved main item tag ..."

Applied, thanks.

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-20 13:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-20 12:02 [PATCH v3] HID: rate-limit hid_warn to prevent log flooding Li Chen
2025-06-20 13:35 ` Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®