* [PATCH kcsan 0/3] KCSAN updates for v6.2
@ 2022-10-19 23:03 Paul E. McKenney
2022-10-19 23:04 ` [PATCH kcsan 1/3] kcsan: Instrument memcpy/memset/memmove with newer Clang Paul E. McKenney
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Paul E. McKenney @ 2022-10-19 23:03 UTC (permalink / raw)
To: linux-kernel, kasan-dev, kernel-team, mingo
Cc: elver, andreyknvl, glider, dvyukov, cai, boqun.feng
Hello!
This series provides KCSAN updates:
1. Instrument memcpy/memset/memmove with newer Clang, courtesy of
Marco Elver.
2. objtool, kcsan: Add volatile read/write instrumentation to
whitelist, courtesy of Marco Elver.
3. Fix trivial typo in Kconfig help comments, courtesy of Ryosuke
Yasuoka.
Thanx, Paul
------------------------------------------------------------------------
kernel/kcsan/core.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
lib/Kconfig.kcsan | 6 +++---
tools/objtool/check.c | 10 ++++++++++
3 files changed, 63 insertions(+), 3 deletions(-)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH kcsan 1/3] kcsan: Instrument memcpy/memset/memmove with newer Clang
2022-10-19 23:03 [PATCH kcsan 0/3] KCSAN updates for v6.2 Paul E. McKenney
@ 2022-10-19 23:04 ` Paul E. McKenney
2022-10-19 23:04 ` [PATCH kcsan 2/3] objtool, kcsan: Add volatile read/write instrumentation to whitelist Paul E. McKenney
2022-10-19 23:04 ` [PATCH kcsan 3/3] kcsan: Fix trivial typo in Kconfig help comments Paul E. McKenney
2 siblings, 0 replies; 4+ messages in thread
From: Paul E. McKenney @ 2022-10-19 23:04 UTC (permalink / raw)
To: linux-kernel, kasan-dev, kernel-team, mingo
Cc: elver, andreyknvl, glider, dvyukov, cai, boqun.feng, stable,
Paul E . McKenney
From: Marco Elver <elver@google.com>
With Clang version 16+, -fsanitize=thread will turn
memcpy/memset/memmove calls in instrumented functions into
__tsan_memcpy/__tsan_memset/__tsan_memmove calls respectively.
Add these functions to the core KCSAN runtime, so that we (a) catch data
races with mem* functions, and (b) won't run into linker errors with
such newer compilers.
Cc: stable@vger.kernel.org # v5.10+
Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
kernel/kcsan/core.c | 50 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/kernel/kcsan/core.c b/kernel/kcsan/core.c
index fe12dfe254ecf..54d077e1a2dc7 100644
--- a/kernel/kcsan/core.c
+++ b/kernel/kcsan/core.c
@@ -14,10 +14,12 @@
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/list.h>
+#include <linux/minmax.h>
#include <linux/moduleparam.h>
#include <linux/percpu.h>
#include <linux/preempt.h>
#include <linux/sched.h>
+#include <linux/string.h>
#include <linux/uaccess.h>
#include "encoding.h"
@@ -1308,3 +1310,51 @@ noinline void __tsan_atomic_signal_fence(int memorder)
}
}
EXPORT_SYMBOL(__tsan_atomic_signal_fence);
+
+#ifdef __HAVE_ARCH_MEMSET
+void *__tsan_memset(void *s, int c, size_t count);
+noinline void *__tsan_memset(void *s, int c, size_t count)
+{
+ /*
+ * Instead of not setting up watchpoints where accessed size is greater
+ * than MAX_ENCODABLE_SIZE, truncate checked size to MAX_ENCODABLE_SIZE.
+ */
+ size_t check_len = min_t(size_t, count, MAX_ENCODABLE_SIZE);
+
+ check_access(s, check_len, KCSAN_ACCESS_WRITE, _RET_IP_);
+ return memset(s, c, count);
+}
+#else
+void *__tsan_memset(void *s, int c, size_t count) __alias(memset);
+#endif
+EXPORT_SYMBOL(__tsan_memset);
+
+#ifdef __HAVE_ARCH_MEMMOVE
+void *__tsan_memmove(void *dst, const void *src, size_t len);
+noinline void *__tsan_memmove(void *dst, const void *src, size_t len)
+{
+ size_t check_len = min_t(size_t, len, MAX_ENCODABLE_SIZE);
+
+ check_access(dst, check_len, KCSAN_ACCESS_WRITE, _RET_IP_);
+ check_access(src, check_len, 0, _RET_IP_);
+ return memmove(dst, src, len);
+}
+#else
+void *__tsan_memmove(void *dst, const void *src, size_t len) __alias(memmove);
+#endif
+EXPORT_SYMBOL(__tsan_memmove);
+
+#ifdef __HAVE_ARCH_MEMCPY
+void *__tsan_memcpy(void *dst, const void *src, size_t len);
+noinline void *__tsan_memcpy(void *dst, const void *src, size_t len)
+{
+ size_t check_len = min_t(size_t, len, MAX_ENCODABLE_SIZE);
+
+ check_access(dst, check_len, KCSAN_ACCESS_WRITE, _RET_IP_);
+ check_access(src, check_len, 0, _RET_IP_);
+ return memcpy(dst, src, len);
+}
+#else
+void *__tsan_memcpy(void *dst, const void *src, size_t len) __alias(memcpy);
+#endif
+EXPORT_SYMBOL(__tsan_memcpy);
--
2.31.1.189.g2e36527f23
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH kcsan 2/3] objtool, kcsan: Add volatile read/write instrumentation to whitelist
2022-10-19 23:03 [PATCH kcsan 0/3] KCSAN updates for v6.2 Paul E. McKenney
2022-10-19 23:04 ` [PATCH kcsan 1/3] kcsan: Instrument memcpy/memset/memmove with newer Clang Paul E. McKenney
@ 2022-10-19 23:04 ` Paul E. McKenney
2022-10-19 23:04 ` [PATCH kcsan 3/3] kcsan: Fix trivial typo in Kconfig help comments Paul E. McKenney
2 siblings, 0 replies; 4+ messages in thread
From: Paul E. McKenney @ 2022-10-19 23:04 UTC (permalink / raw)
To: linux-kernel, kasan-dev, kernel-team, mingo
Cc: elver, andreyknvl, glider, dvyukov, cai, boqun.feng, Paul E . McKenney
From: Marco Elver <elver@google.com>
Adds KCSAN's volatile instrumentation to objtool's uaccess whitelist.
Recent kernel change have shown that this was missing from the uaccess
whitelist (since the first upstreamed version of KCSAN):
mm/gup.o: warning: objtool: fault_in_readable+0x101: call to __tsan_volatile_write1() with UACCESS enabled
Fixes: 75d75b7a4d54 ("kcsan: Support distinguishing volatile accesses")
Signed-off-by: Marco Elver <elver@google.com>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
tools/objtool/check.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 43ec14c29a60c..a7f1e6c8bb0a7 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -999,6 +999,16 @@ static const char *uaccess_safe_builtin[] = {
"__tsan_read_write4",
"__tsan_read_write8",
"__tsan_read_write16",
+ "__tsan_volatile_read1",
+ "__tsan_volatile_read2",
+ "__tsan_volatile_read4",
+ "__tsan_volatile_read8",
+ "__tsan_volatile_read16",
+ "__tsan_volatile_write1",
+ "__tsan_volatile_write2",
+ "__tsan_volatile_write4",
+ "__tsan_volatile_write8",
+ "__tsan_volatile_write16",
"__tsan_atomic8_load",
"__tsan_atomic16_load",
"__tsan_atomic32_load",
--
2.31.1.189.g2e36527f23
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH kcsan 3/3] kcsan: Fix trivial typo in Kconfig help comments
2022-10-19 23:03 [PATCH kcsan 0/3] KCSAN updates for v6.2 Paul E. McKenney
2022-10-19 23:04 ` [PATCH kcsan 1/3] kcsan: Instrument memcpy/memset/memmove with newer Clang Paul E. McKenney
2022-10-19 23:04 ` [PATCH kcsan 2/3] objtool, kcsan: Add volatile read/write instrumentation to whitelist Paul E. McKenney
@ 2022-10-19 23:04 ` Paul E. McKenney
2 siblings, 0 replies; 4+ messages in thread
From: Paul E. McKenney @ 2022-10-19 23:04 UTC (permalink / raw)
To: linux-kernel, kasan-dev, kernel-team, mingo
Cc: elver, andreyknvl, glider, dvyukov, cai, boqun.feng,
Ryosuke Yasuoka, Paul E . McKenney
From: Ryosuke Yasuoka <ryasuoka@redhat.com>
Fix trivial typo in Kconfig help comments in KCSAN_SKIP_WATCH and
KCSAN_SKIP_WATCH_RANDOMIZE
Signed-off-by: Ryosuke Yasuoka <ryasuoka@redhat.com>
Reviewed-by: Marco Elver <elver@google.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
lib/Kconfig.kcsan | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/Kconfig.kcsan b/lib/Kconfig.kcsan
index 47a693c458642..375575a5a0e3c 100644
--- a/lib/Kconfig.kcsan
+++ b/lib/Kconfig.kcsan
@@ -125,7 +125,7 @@ config KCSAN_SKIP_WATCH
default 4000
help
The number of per-CPU memory operations to skip, before another
- watchpoint is set up, i.e. one in KCSAN_WATCH_SKIP per-CPU
+ watchpoint is set up, i.e. one in KCSAN_SKIP_WATCH per-CPU
memory operations are used to set up a watchpoint. A smaller value
results in more aggressive race detection, whereas a larger value
improves system performance at the cost of missing some races.
@@ -135,8 +135,8 @@ config KCSAN_SKIP_WATCH_RANDOMIZE
default y
help
If instruction skip count should be randomized, where the maximum is
- KCSAN_WATCH_SKIP. If false, the chosen value is always
- KCSAN_WATCH_SKIP.
+ KCSAN_SKIP_WATCH. If false, the chosen value is always
+ KCSAN_SKIP_WATCH.
config KCSAN_INTERRUPT_WATCHER
bool "Interruptible watchers" if !KCSAN_STRICT
--
2.31.1.189.g2e36527f23
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-10-19 23:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-19 23:03 [PATCH kcsan 0/3] KCSAN updates for v6.2 Paul E. McKenney
2022-10-19 23:04 ` [PATCH kcsan 1/3] kcsan: Instrument memcpy/memset/memmove with newer Clang Paul E. McKenney
2022-10-19 23:04 ` [PATCH kcsan 2/3] objtool, kcsan: Add volatile read/write instrumentation to whitelist Paul E. McKenney
2022-10-19 23:04 ` [PATCH kcsan 3/3] kcsan: Fix trivial typo in Kconfig help comments Paul E. McKenney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®