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

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
585 * information is lost if dirtied by KCSAN.585 * information is lost if dirtied by KCSAN.
586 */586 */
587 kcsan_save_irqtrace(current);587 kcsan_save_irqtrace(current);
588 if (!interrupt_watcher)588 if (!interrupt_watcher) {
589 local_irq_save(irq_flags);589 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 }
590 596
591 watchpoint = insert_watchpoint((unsigned long)ptr, size, is_write);597 watchpoint = insert_watchpoint((unsigned long)ptr, size, is_write);
592 if (watchpoint == NULL) {598 if (watchpoint == NULL) {
@@ -699,8 +705,10 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type, unsigned · 106 unmodified lines
699 atomic_long_dec(&kcsan_counters[KCSAN_COUNTER_USED_WATCHPOINTS]);705 atomic_long_dec(&kcsan_counters[KCSAN_COUNTER_USED_WATCHPOINTS]);
700 706
701out_unlock:707out_unlock:
702 if (!interrupt_watcher)708 if (!interrupt_watcher) {
709 raw_cpu_ptr(&kcsan_cpu_ctx)->disable_count--;
703 local_irq_restore(irq_flags);710 local_irq_restore(irq_flags);
711 }
704 kcsan_restore_irqtrace(current);712 kcsan_restore_irqtrace(current);
705 ctx->disable_scoped--;713 ctx->disable_scoped--;
706 714

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