From: Nathan Chancellor <nathan@kernel.org>
To: Jann Horn <jannh@google.com>, Arnd Bergmann <arnd@arndb.de>
Cc: Marco Elver <elver@google.com>,
Dmitry Vyukov <dvyukov@google.com>,
kasan-dev@googlegroups.com, linux-arch@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rwonce: handle KCSAN like KASAN in read_word_at_a_time()
Date: Wed, 26 Mar 2025 13:39:26 -0700 [thread overview]
Message-ID: <20250326203926.GA10484@ax162> (raw)
In-Reply-To: <20250325-kcsan-rwonce-v1-1-36b3833a66ae@google.com>
Hi Jann,
On Tue, Mar 25, 2025 at 05:01:34PM +0100, Jann Horn wrote:
> Also, since this read can be racy by design, we should technically do
> READ_ONCE(), so add that.
>
> Fixes: dfd402a4c4ba ("kcsan: Add Kernel Concurrency Sanitizer infrastructure")
> Signed-off-by: Jann Horn <jannh@google.com>
...
> diff --git a/include/asm-generic/rwonce.h b/include/asm-generic/rwonce.h
> index 8d0a6280e982..e9f2b84d2338 100644
> --- a/include/asm-generic/rwonce.h
> +++ b/include/asm-generic/rwonce.h
> @@ -79,11 +79,14 @@ unsigned long __read_once_word_nocheck(const void *addr)
> (typeof(x))__read_once_word_nocheck(&(x)); \
> })
>
> -static __no_kasan_or_inline
> +static __no_sanitize_or_inline
> unsigned long read_word_at_a_time(const void *addr)
> {
> + /* open-coded instrument_read(addr, 1) */
> kasan_check_read(addr, 1);
> - return *(unsigned long *)addr;
> + kcsan_check_read(addr, 1);
> +
> + return READ_ONCE(*(unsigned long *)addr);
I bisected a boot hang that I see on arm64 with LTO enabled to this
change as commit ece69af2ede1 ("rwonce: handle KCSAN like KASAN in
read_word_at_a_time()") in -next. With LTO, READ_ONCE() gets upgraded to
ldar / ldapr, which requires an aligned address to access, but
read_word_at_a_time() can be called with an unaligned address. I
confirmed this should be the root cause by removing the READ_ONCE()
added above or removing the selects of DCACHE_WORD_ACCESS and
HAVE_EFFICIENT_UNALIGNED_ACCESS in arch/arm64/Kconfig, which avoids
the crash.
Cheers,
Nathan
next prev parent reply other threads:[~2025-03-26 20:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-25 16:01 [PATCH] rwonce: handle KCSAN like KASAN in read_word_at_a_time() Jann Horn
2025-03-25 16:05 ` Arnd Bergmann
2025-03-25 16:31 ` Marco Elver
2025-03-25 16:36 ` Jann Horn
2025-03-25 16:59 ` Arnd Bergmann
2025-03-26 20:39 ` Nathan Chancellor [this message]
2025-03-26 20:44 ` Jann Horn
2025-03-26 21:21 ` Jann Horn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250326203926.GA10484@ax162 \
--to=nathan@kernel.org \
--cc=arnd@arndb.de \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=jannh@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox