History

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.

Marco Elver committed 3 months ago

Commit a8488ec1 parent 1590cf01 file · +10 −2Browse files

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/kcsan/core.c+10−2
@@ -585,8 +585,14 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type, unsigned · 584 unmodified lines
585585 * information is lost if dirtied by KCSAN.
586586 */
587587 kcsan_save_irqtrace(current);
588− if (!interrupt_watcher)
588+ if (!interrupt_watcher) {
589589 local_irq_save(irq_flags);
590+ /*
591+ * NMIs can still fire, disable checking for all interrupt
592+ * contexts.
593+ */
594+ raw_cpu_ptr(&kcsan_cpu_ctx)->disable_count++;
595+ }
590596
591597 watchpoint = insert_watchpoint((unsigned long)ptr, size, is_write);
592598 if (watchpoint == NULL) {
@@ -699,8 +705,10 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type, unsigned · 106 unmodified lines
699705 atomic_long_dec(&kcsan_counters[KCSAN_COUNTER_USED_WATCHPOINTS]);
700706
701707 out_unlock:
702− if (!interrupt_watcher)
708+ if (!interrupt_watcher) {
709+ raw_cpu_ptr(&kcsan_cpu_ctx)->disable_count--;
703710 local_irq_restore(irq_flags);
711+ }
704712 kcsan_restore_irqtrace(current);
705713 ctx->disable_scoped--;
706714

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t