kasan: fix more unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled
Subsystems (3)
PATCH 1/1 kasan: fix more unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled
This is a followup to commit f649dc0e0d7b ("kasan: fix unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled") that fixes tests that fail as a result of __alloc_size annotations being added to the kernel allocator functions.
--- lib/test_kasan.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
lib/test_kasan.c +6 -3
@@ -177,7 +177,8 @@ static void kmalloc_node_oob_right(struct kunit *test)*/ static void kmalloc_pagealloc_oob_right (struct kunit *test) { -char *ptr; +/* See comment in kasan_global_oob_right. */ +char *volatile ptr;size_t size =KMALLOC_MAX_CACHE_SIZE +10 ;KASAN_TEST_NEEDS_CONFIG_ON (test,CONFIG_SLUB );
@@ -272,7 +273,8 @@ static void kmalloc_large_oob_right(struct kunit *test)static void krealloc_more_oob_helper (struct kunit *test,size_t size1,size_t size2) { -char *ptr1, *ptr2; +/* See comment in kasan_global_oob_right. */ +char *ptr1, *volatile ptr2;size_t middle;KUNIT_ASSERT_LT (test, size1, size2);
@@ -304,7 +306,8 @@ static void krealloc_more_oob_helper(struct kunit *test,static void krealloc_less_oob_helper (struct kunit *test,size_t size1,size_t size2) { -char *ptr1, *ptr2; +/* See comment in kasan_global_oob_right. */ +char *ptr1, *volatile ptr2;size_t middle;KUNIT_ASSERT_LT (test, size2, size1);
Signature · 1 line
2.35.1.473.g83b2b277ed-goog
Quoted 19 lines · Peter Collingbourne
This is a followup to commit
f649dc0e0d7b("kasan: fix unit tests withCONFIG_UBSAN_LOCAL_BOUNDSenabled") that fixes tests that fail as a result of__alloc_sizeannotations being added to the kernel allocator functions.Signed-off-by Peter Collingbourne <[email protected]>Cc <[email protected]> # 5.16.xFixes c37495d6254c ("slab: add __alloc_size attributes for better bounds checking")--- lib/test_kasan.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)lib/test_kasan.c +0
-0
lib/test_kasan.c static void kmalloc_node_oob_right(struct kunit *test) · line 182
Quoted 7 lines
lib/test_kasan.c +2
-1@@ -177,7 +177,8 @@ static void kmalloc_node_oob_right(struct kunit *test)*/ static void kmalloc_pagealloc_oob_right (struct kunit *test) { -char *ptr; +/* See comment in kasan_global_oob_right. */ +char *volatile ptr;size_t size =KMALLOC_MAX_CACHE_SIZE +10 ;
I think more recently we've been using OPTIMIZER_HIDE_VAR() to hide things from the compiler. Does OPTIMIZER_HIDE_VAR(ptr) right before the access also work in this case?
I leave it to you which you think is cleaner - I'm guessing that we might want to avoid volatile if we can.
Quoted 24 lines
lib/test_kasan.c +4
-3KASAN_TEST_NEEDS_CONFIG_ON (test,CONFIG_SLUB );@@ -272,7 +273,8 @@ static void kmalloc_large_oob_right(struct kunit *test)static void krealloc_more_oob_helper (struct kunit *test,size_t size1,size_t size2) { -char *ptr1, *ptr2; +/* See comment in kasan_global_oob_right. */ +char *ptr1, *volatile ptr2;size_t middle;KUNIT_ASSERT_LT (test, size1, size2);@@ -304,7 +306,8 @@ static void krealloc_more_oob_helper(struct kunit *test,static void krealloc_less_oob_helper (struct kunit *test,size_t size1,size_t size2) { -char *ptr1, *ptr2; +/* See comment in kasan_global_oob_right. */ +char *ptr1, *volatile ptr2;size_t middle;KUNIT_ASSERT_LT (test, size2, size1); --2.35.1.473.g83b2b277ed-goog
Quoted 33 lines · Marco Elver
Quoted 19 lines · Peter Collingbourne
This is a followup to commit
f649dc0e0d7b("kasan: fix unit tests withCONFIG_UBSAN_LOCAL_BOUNDSenabled") that fixes tests that fail as a result of__alloc_sizeannotations being added to the kernel allocator functions.Signed-off-by Peter Collingbourne <[email protected]>Cc <[email protected]> # 5.16.xFixes c37495d6254c ("slab: add __alloc_size attributes for better bounds checking")--- lib/test_kasan.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)lib/test_kasan.c +0
-0lib/test_kasan.c static void kmalloc_node_oob_right(struct kunit *test) · line 182
Quoted 7 lines
lib/test_kasan.c +2
-1@@ -177,7 +177,8 @@ static void kmalloc_node_oob_right(struct kunit *test)*/ static void kmalloc_pagealloc_oob_right (struct kunit *test) { -char *ptr; +/* See comment in kasan_global_oob_right. */ +char *volatile ptr;size_t size =KMALLOC_MAX_CACHE_SIZE +10 ;I think more recently we've been using
OPTIMIZER_HIDE_VAR()to hide things from the compiler. DoesOPTIMIZER_HIDE_VAR(ptr)right before the access also work in this case?
Quoted 2 lines
I leave it to you which you think is cleaner - I'm guessing that we might want to avoid volatile if we can.
Okay, sent v2 which uses OPTIMIZER_HIDE_VAR.
Peter