kcsan: selftest: Ensure that address is at least PAGE_SIZE
Marco Elver
maintainerPATCH v2 1/2 kcsan: selftest: Ensure that address is at least PAGE_SIZE
In preparation of supporting only addresses not within the NULL page, change the selftest to never use addresses that are less than PAGE_SIZE.
---
v2:
* Introduce patch to series.
--- kernel/kcsan/selftest.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/kcsan/selftest.c +3 -0
@@ -33,6 +33,9 @@ static bool test_encode_decode(void)unsigned long addr;prandom_bytes (&addr,sizeof (addr)); +if (addr <PAGE_SIZE ) + addr =PAGE_SIZE ; +if (WARN_ON (!check_encodable (addr, size)))return false;
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
Marco Elver
maintainerPATCH v2 2/2 kcsan: Never set up watchpoints on NULL pointers
Avoid setting up watchpoints on NULL pointers, as otherwise we would crash inside the KCSAN runtime (when checking for value changes) instead of the instrumented code.
Because that may be confusing, skip any address less than PAGE_SIZE.
--- kernel/kcsan/encoding.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/kcsan/encoding.h +5 -1
@@ -48,7 +48,11 @@static inline bool check_encodable (unsigned long addr,size_t size) { -return size <=MAX_ENCODABLE_SIZE ; +/* +* While we can encode addrs<PAGE_SIZE, avoid crashing with a NULL +* pointer deref inside KCSAN. +*/ +return addr >=PAGE_SIZE && size <=MAX_ENCODABLE_SIZE ; } static inline long
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
Re: [PATCH v2 2/2] kcsan: Never set up watchpoints on NULL pointers
Quoted 8 lines · Marco Elver
Avoid setting up watchpoints on NULL pointers, as otherwise we would crash inside the KCSAN runtime (when checking for value changes) instead of the instrumented code.
Because that may be confusing, skip any address less than
PAGE_SIZE.Signed-off-by Marco Elver <[email protected]>
Quoted 24 lines
--- kernel/kcsan/encoding.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)kernel/kcsan/encoding.h +5
-2@@ -48,7 +48,11 @@static inline bool check_encodable (unsigned long addr,size_t size) { -return size <=MAX_ENCODABLE_SIZE ; +/* +* While we can encode addrs<PAGE_SIZE, avoid crashing with a NULL +* pointer deref inside KCSAN. +*/ +return addr >=PAGE_SIZE && size <=MAX_ENCODABLE_SIZE ; } static inline long --2.29.0.rc1.297.gfa9743e501-goog
Quoted 5 lines · Marco Elver
In preparation of supporting only addresses not within the NULL page, change the selftest to never use addresses that are less than
PAGE_SIZE.Signed-off-by Marco Elver <[email protected]>
Quoted 24 lines
---
v2:
* Introduce patch to series.--- kernel/kcsan/selftest.c | 3 +++ 1 file changed, 3 insertions(+)kernel/kcsan/selftest.c +3
-1@@ -33,6 +33,9 @@ static bool test_encode_decode(void)unsigned long addr;prandom_bytes (&addr,sizeof (addr)); +if (addr <PAGE_SIZE ) + addr =PAGE_SIZE ; +if (WARN_ON (!check_encodable (addr, size)))return false; --2.29.0.rc1.297.gfa9743e501-goog