From nobody Fri Jul 24 22:17:34 2026 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A434D3D6CD7 for ; Wed, 22 Jul 2026 21:27:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784755630; cv=none; b=g0Bdt33EsPxjISmE7+JL/7Ba/qOtj7VSqzR2RXRAjcoCrFnM5nZ0K2hmJJToYcj7Ifz80W/FMS/trg3S4uTN9tVyIEWwZ7Bkvnv2XERiAOjOGFoe2W/9FmVz98JKt7o7cR3aX0P3IqljIbjvtG2rgM2b6ZBjqWSt8SAPWURbT44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784755630; c=relaxed/simple; bh=3F4iW0k2VXrkgFjj2yRWt86TaMMZ+DXr+Ch6WYbL8yY=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=Vw2Z3PK7B2H55UY6VzSOLb1PaDaVfTJ5gBSgvqs/KjKC5DmqNChSu0opKfCGgWWA1lEd//ZWmm0bW0L+f7Q3iwo3TocQf8MNwh4rBmNJj0kifrc6u68bshOiqzjzJbx2DJX34MCPCLIOoUHvBryDZpTugjJJlexVRI4jcazn1N0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--elver.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=KY8vdQPq; arc=none smtp.client-ip=209.85.128.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--elver.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KY8vdQPq" Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-49544a639e9so39908045e9.1 for ; Wed, 22 Jul 2026 14:27:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784755627; x=1785360427; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Db33ILqeoaxfmuoSDLNSlbmPthnjWgAt7l+eA2Te79Q=; b=KY8vdQPqx/OCPNzrXxgqFECFBG+LjSK0Clat9bAR5DpTodUpVN6l3uih+nhpGm293O TOh3WpQ43pbENzcxoXBkoi3SMEO6Fn9iXVW3sZw0uYW2YUcMjAQvvUFADJz8fqKdXMT8 ixPzqjAJG6AGlDXLlRjSDQuiAjzELMD6wk6bAS9/wPNm7oWf2nCo2GFa5g/tw+H8BBdy kr5fQzUMaQXRbE42ZVcZaGcGbh5uYdzR3bfYXr32daA5edPmYoLOCcsyuo0rg6/19Qp/ 7kLNb4toX5cUsYUB1PL9aZLsO5fTPDvhR5JOVIcVvvxfUrBxZSh9m6wrPbPxy9prZDvQ kqNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784755627; x=1785360427; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Db33ILqeoaxfmuoSDLNSlbmPthnjWgAt7l+eA2Te79Q=; b=jGCDCigQanKeN3BtJv5zMhnIijLYgRrVbbqU6gNt3gF0uTUpawWQqt2+8ebmn+5rpu 3ok8QB7zlQxeLrhZOFfGIpdsh9Xwn3RnauoW3H9VwjpUyK6WhlV+wc5swLTp10rjqQVp gmPySE42YtoLkFCeQ/F1AJUVOIxwYi0wmy1GjCfLUn3ZwGkt2vYuj0LtoOfjLTu3NYRs eyuTbcfHlOaaLRLYGZRP9D9YHa49J5WSqmyCEe668RaMSFHKD2WuKTuj935cDXo736Af JqNOLZvqLLQOlDmhlyT/ER1TyGObXqpiGMUCDXuNrlOEzwFcS/MAptIPKIxRyhQYS7t8 iTwA== X-Forwarded-Encrypted: i=1; AHgh+Rp09a0F4x482zBmdiB6pfOW50kCfvbDG8DvlvnOkI+CD08iIbHADS7VMoIumngqGnLWZLlXpJicEgdWtWQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yxg8Ah/ARNNi0FSWtziAFhOjoWCQ4GYdCUOGFOA9fkoi7UC4h6e uwjCzNNrtXUEtg4XJMhy40u2GE8spyNwheafH2T2rwJrwiMsP/jeak6Bacx9S2ej6nrd8hU3gAC /CQ== X-Received: from wmrk14.prod.google.com ([2002:a05:600c:b4e:b0:495:59ae:3d1f]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:2211:b0:495:6b78:6f4 with SMTP id 5b1f17b1804b1-49573cc2102mr2523355e9.8.1784755626768; Wed, 22 Jul 2026 14:27:06 -0700 (PDT) Date: Wed, 22 Jul 2026 23:26:25 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog Message-ID: <20260722212700.828037-1-elver@google.com> Subject: [PATCH] kcsan: avoid unintended access checking in NMIs From: Marco Elver To: elver@google.com Cc: "Paul E. McKenney" , Boqun Feng , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, Dmitry Vyukov Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 m= odeling") Signed-off-by: Marco Elver --- kernel/kcsan/core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kernel/kcsan/core.c b/kernel/kcsan/core.c index 8a7baf4e332e..2db82661cd60 100644 --- a/kernel/kcsan/core.c +++ b/kernel/kcsan/core.c @@ -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++; + } =20 watchpoint =3D insert_watchpoint((unsigned long)ptr, size, is_write); if (watchpoint =3D=3D NULL) { @@ -699,8 +705,10 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_= t size, int type, unsigned atomic_long_dec(&kcsan_counters[KCSAN_COUNTER_USED_WATCHPOINTS]); =20 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--; =20 --=20 2.55.0.229.g6434b31f56-goog