Generic Linux architectural discussions
 help / color / mirror / Atom feed
* [PATCH] rwonce: fix crash by removing READ_ONCE() for unaligned read
@ 2025-03-26 21:04 Jann Horn
  2025-03-26 21:23 ` Arnd Bergmann
  0 siblings, 1 reply; 7+ messages in thread
From: Jann Horn @ 2025-03-26 21:04 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Marco Elver, Nathan Chancellor, linux-arch, linux-kernel,
	Jann Horn

When arm64 is built with LTO, it upgrades READ_ONCE() to ldar / ldapr
(load-acquire) to avoid issues that can be caused by the compiler
optimizing away implicit address dependencies.

Unlike plain loads, these load-acquire instructions actually require an
aligned address.

For now, fix it by removing the READ_ONCE() that the buggy commit
introduced.

Fixes: ece69af2ede1 ("rwonce: handle KCSAN like KASAN in read_word_at_a_time()")
Reported-by: Nathan Chancellor <nathan@kernel.org>
Closes: https://lore.kernel.org/r/20250326203926.GA10484@ax162
Signed-off-by: Jann Horn <jannh@google.com>
---
 include/asm-generic/rwonce.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/asm-generic/rwonce.h b/include/asm-generic/rwonce.h
index e9f2b84d2338..52b969c7cef9 100644
--- a/include/asm-generic/rwonce.h
+++ b/include/asm-generic/rwonce.h
@@ -86,7 +86,12 @@ unsigned long read_word_at_a_time(const void *addr)
 	kasan_check_read(addr, 1);
 	kcsan_check_read(addr, 1);
 
-	return READ_ONCE(*(unsigned long *)addr);
+	/*
+	 * This load can race with concurrent stores to out-of-bounds memory,
+	 * but READ_ONCE() can't be used because it requires higher alignment
+	 * than plain loads in arm64 builds with LTO.
+	 */
+	return *(unsigned long *)addr;
 }
 
 #endif /* __ASSEMBLY__ */

---
base-commit: ece69af2ede103e190ffdfccd9f9ec850606ab5e
change-id: 20250326-rwaat-fix-63d7557b3d88

-- 
Jann Horn <jannh@google.com>


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-03-27 10:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-26 21:04 [PATCH] rwonce: fix crash by removing READ_ONCE() for unaligned read Jann Horn
2025-03-26 21:23 ` Arnd Bergmann
2025-03-26 22:41   ` Linus Torvalds
2025-03-26 22:50     ` Jann Horn
2025-03-26 22:54     ` Nathan Chancellor
2025-03-27  0:49       ` Linus Torvalds
2025-03-27 10:58         ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox