watchdog: pretimeout: Add "dump" pretimeout governor
PATCH v2 1/1 watchdog: pretimeout: Add "dump" pretimeout governor
Add a new "dump" pretimeout governor that triggers a backtrace of all CPUs (via trigger_all_cpu_backtrace()) to the kernel log buffer. This provides diagnostic information right before the hardware watchdog fires.
In addition, update the WATCHDOG_PRETIMEOUT_GOV_SEL Kconfig logic to fall back to the "panic" governor only when both "noop" and "dump" governors are disabled.
---
Alternatives considered:
We can also introduce some options and put trigger_all_cpu_backtrace() into the existing "noop" governor.
---
v2:
- Change "tristate" -> "bool" for WATCHDOG_PRETIMEOUT_GOV_DUMP.
v1: https://lore.kernel.org/all/[email protected]
--- drivers/watchdog/Kconfig | 19 ++++++++++- drivers/watchdog/Makefile | 1 + drivers/watchdog/pretimeout_dump.c | 45 ++++++++++++++++++++++++++ drivers/watchdog/watchdog_pretimeout.h | 4 ++- 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 drivers/watchdog/pretimeout_dump.c
drivers/watchdog/Kconfig +18 -1
@@ -93,10 +93,19 @@ config WATCHDOG_PRETIMEOUT_GOV_SEL tristate depends on WATCHDOG_PRETIMEOUT_GOV default m - select WATCHDOG_PRETIMEOUT_GOV_PANIC if WATCHDOG_PRETIMEOUT_GOV_NOOP=n + select WATCHDOG_PRETIMEOUT_GOV_PANIC if \ + WATCHDOG_PRETIMEOUT_GOV_NOOP=n && WATCHDOG_PRETIMEOUT_GOV_DUMP=n if WATCHDOG_PRETIMEOUT_GOV +config WATCHDOG_PRETIMEOUT_GOV_DUMP + bool "Dump watchdog pretimeout governor" + depends on WATCHDOG_CORE=y + default WATCHDOG_CORE + help + Dump watchdog pretimeout governor, all cpu backtrace is + added to kernel log buffer. + config WATCHDOG_PRETIMEOUT_GOV_NOOP tristate "Noop watchdog pretimeout governor" depends on WATCHDOG_CORE
@@ -121,6 +130,14 @@ choice The governor takes its action, if a watchdog is capable to report a pretimeout event. +config WATCHDOG_PRETIMEOUT_DEFAULT_GOV_DUMP + bool "dump" + depends on WATCHDOG_PRETIMEOUT_GOV_DUMP + help + Use dump watchdog pretimeout governor by default. If dump + governor is selected by a user, dump all cpu backtrace to + the kernel log buffer and don't do any system changes. + config WATCHDOG_PRETIMEOUT_DEFAULT_GOV_NOOP bool "noop" depends on WATCHDOG_PRETIMEOUT_GOV_NOOP
drivers/watchdog/Makefile +1 -0
@@ -11,6 +11,7 @@ watchdog-objs += watchdog_core.o watchdog_dev.o watchdog-$(CONFIG_WATCHDOG_PRETIMEOUT_GOV) += watchdog_pretimeout.o watchdog-$(CONFIG_WATCHDOG_HRTIMER_PRETIMEOUT) += watchdog_hrtimer_pretimeout.o +obj-$(CONFIG_WATCHDOG_PRETIMEOUT_GOV_DUMP) += pretimeout_dump.o obj-$(CONFIG_WATCHDOG_PRETIMEOUT_GOV_NOOP) += pretimeout_noop.o obj-$(CONFIG_WATCHDOG_PRETIMEOUT_GOV_PANIC) += pretimeout_panic.o
drivers/watchdog/pretimeout_dump.c new file +45 -0
45 lines not on this page · raw message
drivers/watchdog/watchdog_pretimeout.h +3 -1
@@ -24,7 +24,9 @@ int watchdog_pretimeout_governor_get(struct watchdog_device *wdd, char *buf);int watchdog_pretimeout_governor_set (struct watchdog_device *wdd,const char *buf); -#if IS_ENABLED (CONFIG_WATCHDOG_PRETIMEOUT_DEFAULT_GOV_NOOP ) +#if IS_ENABLED (CONFIG_WATCHDOG_PRETIMEOUT_DEFAULT_GOV_DUMP ) +#define WATCHDOG_PRETIMEOUT_DEFAULT_GOV "dump" +#elif IS_ENABLED (CONFIG_WATCHDOG_PRETIMEOUT_DEFAULT_GOV_NOOP )#define WATCHDOG_PRETIMEOUT_DEFAULT_GOV "noop"#elif IS_ENABLED (CONFIG_WATCHDOG_PRETIMEOUT_DEFAULT_GOV_PANIC )#define WATCHDOG_PRETIMEOUT_DEFAULT_GOV "panic"
Signature · 1 line
2.55.0.rc2.803.g1fd1e6609c-goog
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Unregistering the default watchdog pretimeout governor leaves dangling pointers in default_gov and active watchdogs, leading to a Use-After-Free. --
--- Patch [1]: [PATCH v2] watchdog: pretimeout: Add "dump" pretimeout governor --- commit fdc83bdc7fe1e2cb54902870250cd46dee161270
Author: Tzung-Bi Shih <[email protected]>
watchdog: pretimeout: Add "dump" pretimeout governor
This patch adds a new "dump" pretimeout governor that triggers an all-CPU backtrace on watchdog pretimeout. It also updates the Kconfig logic to ensure the "panic" governor is selected as a fallback when others are disabled.
Quoted 5 lines
drivers/watchdog/pretimeout_dump.c new file +0
-0
[ ... ]
drivers/watchdog/pretimeout_dump.c line 39
Quoted 4 lines
drivers/watchdog/pretimeout_dump.c new file +4
-0+static void __exit watchdog_gov_dump_unregister(void) +{ +watchdog_unregister_governor (&watchdog_gov_dump); +}
[Severity: High]
This is a pre-existing issue, but does unregistering a default governor leave dangling pointers in watchdog devices?
Looking at watchdog_unregister_governor() indrivers/watchdog/watchdog_pretimeout.c:
void watchdog_unregister_governor(struct watchdog_governor *gov)
{
...
list_for_each_entry(p, &pretimeout_list, entry)
if (p->wdd->gov == gov)
p->wdd->gov = default_gov;
...
}If the governor being unregistered happens to be the current default governor, default_gov is not cleared and still points to the governor being removed. The fallback assignment reassigns the same dangling pointer back to the watchdog device.
Could this lead to a use-after-free on the next pretimeout event if the governor's memory is freed after unregistration?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 10 lines · Tzung-Bi Shih
Add a new "dump" pretimeout governor that triggers a backtrace of all CPUs (via
trigger_all_cpu_backtrace()) to the kernel log buffer. This provides diagnostic information right before the hardware watchdog fires.In addition, update the
WATCHDOG_PRETIMEOUT_GOV_SELKconfiglogic to fall back to the "panic" governor only when both "noop" and "dump" governors are disabled.Signed-off-by Tzung-Bi Shih <[email protected]>
Applied.
Thanks,
Guenter