kcsan: avoid unintended access checking in NMIs
Marco Elver
maintainerPATCH 1/1 kcsan: avoid unintended access checking in NMIs
If a watcher deliberately disables interrupts (either by user choice, or because we're dealing with a scoped reordered access) to avoid detecting any data races in interrupts, NMIs are still able to fire.
When we set up a watchpoint on a scoped reordered access, we disabled interrupts because the same CPU cannot observe reordering of its own accesses. To ensure we observe no false positives from NMIs, disable access checking for interrupt contexts as well.
Fixes 69562e4983d9 ("kcsan: Add core support for a subset of weak memory modeling")
Signed-off-by Marco Elver <[email protected]>
--- kernel/kcsan/core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
kernel/kcsan/core.c +10 -2
@@ -585,8 +585,14 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type, unsigned* information is lost if dirtied by KCSAN. */ kcsan_save_irqtrace (current); -if (!interrupt_watcher) +if (!interrupt_watcher) {local_irq_save (irq_flags); +/* +* NMIs can still fire, disable checking for all interrupt +* contexts. +*/ +raw_cpu_ptr (&kcsan_cpu_ctx)->disable_count++; + } watchpoint =insert_watchpoint ((unsigned long )ptr, size, is_write);if (watchpoint ==NULL ) {
@@ -699,8 +705,10 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type, unsignedatomic_long_dec (&kcsan_counters[KCSAN_COUNTER_USED_WATCHPOINTS ]); out_unlock: -if (!interrupt_watcher) +if (!interrupt_watcher) { +raw_cpu_ptr (&kcsan_cpu_ctx)->disable_count--;local_irq_restore (irq_flags); + }kcsan_restore_irqtrace (current); ctx->disable_scoped--;
Signature · 1 line
2.55.0.229.g6434b31f56-goog