Lines Matching full:test
26 #include <kunit/test.h>
47 * test, see the comment for KUNIT_EXPECT_KASAN_FAIL().
49 static int kasan_test_init(struct kunit *test) in kasan_test_init() argument
52 kunit_err(test, "can't run KASAN tests with KASAN disabled"); in kasan_test_init()
59 kunit_add_named_resource(test, NULL, NULL, &resource, in kasan_test_init()
64 static void kasan_test_exit(struct kunit *test) in kasan_test_exit() argument
67 KUNIT_EXPECT_FALSE(test, test_status.report_found); in kasan_test_exit()
72 * KASAN report; causes a test failure otherwise. This relies on a KUnit
77 * checking is auto-disabled. When this happens, this test handler reenables
91 #define KUNIT_EXPECT_KASAN_FAIL(test, expression) do { \ argument
95 KUNIT_EXPECT_FALSE(test, READ_ONCE(test_status.report_found)); \
102 KUNIT_FAIL(test, KUNIT_SUBTEST_INDENT "KASAN failure " \
116 #define KASAN_TEST_NEEDS_CONFIG_ON(test, config) do { \ argument
118 kunit_skip((test), "Test requires " #config "=y"); \
121 #define KASAN_TEST_NEEDS_CONFIG_OFF(test, config) do { \ argument
123 kunit_skip((test), "Test requires " #config "=n"); \
126 static void kmalloc_oob_right(struct kunit *test) in kmalloc_oob_right() argument
132 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_right()
140 KUNIT_EXPECT_KASAN_FAIL(test, ptr[size] = 'x'); in kmalloc_oob_right()
146 KUNIT_EXPECT_KASAN_FAIL(test, ptr[size + 5] = 'y'); in kmalloc_oob_right()
149 KUNIT_EXPECT_KASAN_FAIL(test, ptr[0] = in kmalloc_oob_right()
155 static void kmalloc_oob_left(struct kunit *test) in kmalloc_oob_left() argument
161 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_left()
164 KUNIT_EXPECT_KASAN_FAIL(test, *ptr = *(ptr - 1)); in kmalloc_oob_left()
168 static void kmalloc_node_oob_right(struct kunit *test) in kmalloc_node_oob_right() argument
174 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_node_oob_right()
177 KUNIT_EXPECT_KASAN_FAIL(test, ptr[0] = ptr[size]); in kmalloc_node_oob_right()
187 static void kmalloc_pagealloc_oob_right(struct kunit *test) in kmalloc_pagealloc_oob_right() argument
192 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); in kmalloc_pagealloc_oob_right()
195 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_pagealloc_oob_right()
198 KUNIT_EXPECT_KASAN_FAIL(test, ptr[size + OOB_TAG_OFF] = 0); in kmalloc_pagealloc_oob_right()
203 static void kmalloc_pagealloc_uaf(struct kunit *test) in kmalloc_pagealloc_uaf() argument
208 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); in kmalloc_pagealloc_uaf()
211 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_pagealloc_uaf()
214 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[0]); in kmalloc_pagealloc_uaf()
217 static void kmalloc_pagealloc_invalid_free(struct kunit *test) in kmalloc_pagealloc_invalid_free() argument
222 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); in kmalloc_pagealloc_invalid_free()
225 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_pagealloc_invalid_free()
227 KUNIT_EXPECT_KASAN_FAIL(test, kfree(ptr + 1)); in kmalloc_pagealloc_invalid_free()
230 static void pagealloc_oob_right(struct kunit *test) in pagealloc_oob_right() argument
242 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in pagealloc_oob_right()
246 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in pagealloc_oob_right()
248 KUNIT_EXPECT_KASAN_FAIL(test, ptr[0] = ptr[size]); in pagealloc_oob_right()
252 static void pagealloc_uaf(struct kunit *test) in pagealloc_uaf() argument
260 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in pagealloc_uaf()
263 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[0]); in pagealloc_uaf()
266 static void kmalloc_large_oob_right(struct kunit *test) in kmalloc_large_oob_right() argument
276 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_large_oob_right()
279 KUNIT_EXPECT_KASAN_FAIL(test, ptr[size] = 0); in kmalloc_large_oob_right()
283 static void krealloc_more_oob_helper(struct kunit *test, in krealloc_more_oob_helper() argument
289 KUNIT_ASSERT_LT(test, size1, size2); in krealloc_more_oob_helper()
293 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in krealloc_more_oob_helper()
296 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); in krealloc_more_oob_helper()
309 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size2] = 'x'); in krealloc_more_oob_helper()
312 KUNIT_EXPECT_KASAN_FAIL(test, in krealloc_more_oob_helper()
318 static void krealloc_less_oob_helper(struct kunit *test, in krealloc_less_oob_helper() argument
324 KUNIT_ASSERT_LT(test, size2, size1); in krealloc_less_oob_helper()
328 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in krealloc_less_oob_helper()
331 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); in krealloc_less_oob_helper()
341 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size2] = 'x'); in krealloc_less_oob_helper()
344 KUNIT_EXPECT_KASAN_FAIL(test, in krealloc_less_oob_helper()
351 KUNIT_EXPECT_LE(test, round_up(size2, KASAN_GRANULE_SIZE), in krealloc_less_oob_helper()
353 KUNIT_EXPECT_LE(test, round_up(middle, KASAN_GRANULE_SIZE), in krealloc_less_oob_helper()
355 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[middle] = 'x'); in krealloc_less_oob_helper()
356 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size1 - 1] = 'x'); in krealloc_less_oob_helper()
357 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size1] = 'x'); in krealloc_less_oob_helper()
362 static void krealloc_more_oob(struct kunit *test) in krealloc_more_oob() argument
364 krealloc_more_oob_helper(test, 201, 235); in krealloc_more_oob()
367 static void krealloc_less_oob(struct kunit *test) in krealloc_less_oob() argument
369 krealloc_less_oob_helper(test, 235, 201); in krealloc_less_oob()
372 static void krealloc_pagealloc_more_oob(struct kunit *test) in krealloc_pagealloc_more_oob() argument
375 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); in krealloc_pagealloc_more_oob()
377 krealloc_more_oob_helper(test, KMALLOC_MAX_CACHE_SIZE + 201, in krealloc_pagealloc_more_oob()
381 static void krealloc_pagealloc_less_oob(struct kunit *test) in krealloc_pagealloc_less_oob() argument
384 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); in krealloc_pagealloc_less_oob()
386 krealloc_less_oob_helper(test, KMALLOC_MAX_CACHE_SIZE + 235, in krealloc_pagealloc_less_oob()
394 static void krealloc_uaf(struct kunit *test) in krealloc_uaf() argument
401 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in krealloc_uaf()
404 KUNIT_EXPECT_KASAN_FAIL(test, ptr2 = krealloc(ptr1, size2, GFP_KERNEL)); in krealloc_uaf()
405 KUNIT_ASSERT_NULL(test, ptr2); in krealloc_uaf()
406 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)ptr1); in krealloc_uaf()
409 static void kmalloc_oob_16(struct kunit *test) in kmalloc_oob_16() argument
415 /* This test is specifically crafted for the generic mode. */ in kmalloc_oob_16()
416 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kmalloc_oob_16()
419 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in kmalloc_oob_16()
422 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); in kmalloc_oob_16()
426 KUNIT_EXPECT_KASAN_FAIL(test, *ptr1 = *ptr2); in kmalloc_oob_16()
431 static void kmalloc_uaf_16(struct kunit *test) in kmalloc_uaf_16() argument
438 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in kmalloc_uaf_16()
441 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); in kmalloc_uaf_16()
444 KUNIT_EXPECT_KASAN_FAIL(test, *ptr1 = *ptr2); in kmalloc_uaf_16()
454 static void kmalloc_oob_memset_2(struct kunit *test) in kmalloc_oob_memset_2() argument
460 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_memset_2()
463 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + size - 1, 0, 2)); in kmalloc_oob_memset_2()
467 static void kmalloc_oob_memset_4(struct kunit *test) in kmalloc_oob_memset_4() argument
473 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_memset_4()
476 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + size - 3, 0, 4)); in kmalloc_oob_memset_4()
480 static void kmalloc_oob_memset_8(struct kunit *test) in kmalloc_oob_memset_8() argument
486 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_memset_8()
489 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + size - 7, 0, 8)); in kmalloc_oob_memset_8()
493 static void kmalloc_oob_memset_16(struct kunit *test) in kmalloc_oob_memset_16() argument
499 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_memset_16()
502 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + size - 15, 0, 16)); in kmalloc_oob_memset_16()
506 static void kmalloc_oob_in_memset(struct kunit *test) in kmalloc_oob_in_memset() argument
512 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_in_memset()
516 KUNIT_EXPECT_KASAN_FAIL(test, in kmalloc_oob_in_memset()
521 static void kmalloc_memmove_negative_size(struct kunit *test) in kmalloc_memmove_negative_size() argument
529 * As a result, this test introduces a side-effect memory corruption, in kmalloc_memmove_negative_size()
532 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_HW_TAGS); in kmalloc_memmove_negative_size()
535 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_memmove_negative_size()
540 KUNIT_EXPECT_KASAN_FAIL(test, in kmalloc_memmove_negative_size()
545 static void kmalloc_memmove_invalid_size(struct kunit *test) in kmalloc_memmove_invalid_size() argument
552 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_memmove_invalid_size()
557 KUNIT_EXPECT_KASAN_FAIL(test, in kmalloc_memmove_invalid_size()
562 static void kmalloc_uaf(struct kunit *test) in kmalloc_uaf() argument
568 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_uaf()
571 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[8]); in kmalloc_uaf()
574 static void kmalloc_uaf_memset(struct kunit *test) in kmalloc_uaf_memset() argument
581 * kernel memory corruption this test causes. in kmalloc_uaf_memset()
583 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kmalloc_uaf_memset()
586 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_uaf_memset()
589 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr, 0, size)); in kmalloc_uaf_memset()
592 static void kmalloc_uaf2(struct kunit *test) in kmalloc_uaf2() argument
600 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in kmalloc_uaf2()
605 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); in kmalloc_uaf2()
616 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr1)[40]); in kmalloc_uaf2()
617 KUNIT_EXPECT_PTR_NE(test, ptr1, ptr2); in kmalloc_uaf2()
626 static void kmalloc_uaf3(struct kunit *test) in kmalloc_uaf3() argument
631 /* This test is specifically crafted for tag-based modes. */ in kmalloc_uaf3()
632 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in kmalloc_uaf3()
635 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in kmalloc_uaf3()
639 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); in kmalloc_uaf3()
642 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr1)[8]); in kmalloc_uaf3()
645 static void kfree_via_page(struct kunit *test) in kfree_via_page() argument
653 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kfree_via_page()
660 static void kfree_via_phys(struct kunit *test) in kfree_via_phys() argument
667 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kfree_via_phys()
673 static void kmem_cache_oob(struct kunit *test) in kmem_cache_oob() argument
680 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_oob()
684 kunit_err(test, "Allocation failed: %s\n", __func__); in kmem_cache_oob()
689 KUNIT_EXPECT_KASAN_FAIL(test, *p = p[size + OOB_TAG_OFF]); in kmem_cache_oob()
695 static void kmem_cache_accounted(struct kunit *test) in kmem_cache_accounted() argument
703 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_accounted()
722 static void kmem_cache_bulk(struct kunit *test) in kmem_cache_bulk() argument
731 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_bulk()
735 kunit_err(test, "Allocation failed: %s\n", __func__); in kmem_cache_bulk()
749 static void kasan_global_oob_right(struct kunit *test) in kasan_global_oob_right() argument
767 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kasan_global_oob_right()
769 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p); in kasan_global_oob_right()
772 static void kasan_global_oob_left(struct kunit *test) in kasan_global_oob_left() argument
778 * GCC is known to fail this test, skip it. in kasan_global_oob_left()
781 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_CC_IS_CLANG); in kasan_global_oob_left()
782 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kasan_global_oob_left()
783 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p); in kasan_global_oob_left()
787 static void ksize_unpoisons_memory(struct kunit *test) in ksize_unpoisons_memory() argument
793 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in ksize_unpoisons_memory()
802 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[real_size]); in ksize_unpoisons_memory()
811 static void ksize_uaf(struct kunit *test) in ksize_uaf() argument
817 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in ksize_uaf()
821 KUNIT_EXPECT_KASAN_FAIL(test, ksize(ptr)); in ksize_uaf()
822 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[0]); in ksize_uaf()
823 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[size]); in ksize_uaf()
826 static void kasan_stack_oob(struct kunit *test) in kasan_stack_oob() argument
833 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_STACK); in kasan_stack_oob()
835 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p); in kasan_stack_oob()
838 static void kasan_alloca_oob_left(struct kunit *test) in kasan_alloca_oob_left() argument
847 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kasan_alloca_oob_left()
848 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_STACK); in kasan_alloca_oob_left()
850 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p); in kasan_alloca_oob_left()
853 static void kasan_alloca_oob_right(struct kunit *test) in kasan_alloca_oob_right() argument
862 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kasan_alloca_oob_right()
863 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_STACK); in kasan_alloca_oob_right()
865 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p); in kasan_alloca_oob_right()
868 static void kmem_cache_double_free(struct kunit *test) in kmem_cache_double_free() argument
875 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_double_free()
879 kunit_err(test, "Allocation failed: %s\n", __func__); in kmem_cache_double_free()
885 KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_free(cache, p)); in kmem_cache_double_free()
889 static void kmem_cache_invalid_free(struct kunit *test) in kmem_cache_invalid_free() argument
897 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_invalid_free()
901 kunit_err(test, "Allocation failed: %s\n", __func__); in kmem_cache_invalid_free()
907 KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_free(cache, p + 1)); in kmem_cache_invalid_free()
920 static void kmem_cache_double_destroy(struct kunit *test) in kmem_cache_double_destroy() argument
926 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_double_destroy()
928 KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_destroy(cache)); in kmem_cache_double_destroy()
931 static void kasan_memchr(struct kunit *test) in kasan_memchr() argument
940 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_AMD_MEM_ENCRYPT); in kasan_memchr()
946 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kasan_memchr()
950 KUNIT_EXPECT_KASAN_FAIL(test, in kasan_memchr()
956 static void kasan_memcmp(struct kunit *test) in kasan_memcmp() argument
966 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_AMD_MEM_ENCRYPT); in kasan_memcmp()
972 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kasan_memcmp()
977 KUNIT_EXPECT_KASAN_FAIL(test, in kasan_memcmp()
982 static void kasan_strings(struct kunit *test) in kasan_strings() argument
991 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_AMD_MEM_ENCRYPT); in kasan_strings()
994 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kasan_strings()
1005 KUNIT_EXPECT_KASAN_FAIL(test, kasan_ptr_result = strchr(ptr, '1')); in kasan_strings()
1007 KUNIT_EXPECT_KASAN_FAIL(test, kasan_ptr_result = strrchr(ptr, '1')); in kasan_strings()
1009 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = strcmp(ptr, "2")); in kasan_strings()
1011 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = strncmp(ptr, "2", 1)); in kasan_strings()
1013 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = strlen(ptr)); in kasan_strings()
1015 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = strnlen(ptr, 1)); in kasan_strings()
1018 static void kasan_bitops_modify(struct kunit *test, int nr, void *addr) in kasan_bitops_modify() argument
1020 KUNIT_EXPECT_KASAN_FAIL(test, set_bit(nr, addr)); in kasan_bitops_modify()
1021 KUNIT_EXPECT_KASAN_FAIL(test, __set_bit(nr, addr)); in kasan_bitops_modify()
1022 KUNIT_EXPECT_KASAN_FAIL(test, clear_bit(nr, addr)); in kasan_bitops_modify()
1023 KUNIT_EXPECT_KASAN_FAIL(test, __clear_bit(nr, addr)); in kasan_bitops_modify()
1024 KUNIT_EXPECT_KASAN_FAIL(test, clear_bit_unlock(nr, addr)); in kasan_bitops_modify()
1025 KUNIT_EXPECT_KASAN_FAIL(test, __clear_bit_unlock(nr, addr)); in kasan_bitops_modify()
1026 KUNIT_EXPECT_KASAN_FAIL(test, change_bit(nr, addr)); in kasan_bitops_modify()
1027 KUNIT_EXPECT_KASAN_FAIL(test, __change_bit(nr, addr)); in kasan_bitops_modify()
1030 static void kasan_bitops_test_and_modify(struct kunit *test, int nr, void *addr) in kasan_bitops_test_and_modify() argument
1032 KUNIT_EXPECT_KASAN_FAIL(test, test_and_set_bit(nr, addr)); in kasan_bitops_test_and_modify()
1033 KUNIT_EXPECT_KASAN_FAIL(test, __test_and_set_bit(nr, addr)); in kasan_bitops_test_and_modify()
1034 KUNIT_EXPECT_KASAN_FAIL(test, test_and_set_bit_lock(nr, addr)); in kasan_bitops_test_and_modify()
1035 KUNIT_EXPECT_KASAN_FAIL(test, test_and_clear_bit(nr, addr)); in kasan_bitops_test_and_modify()
1036 KUNIT_EXPECT_KASAN_FAIL(test, __test_and_clear_bit(nr, addr)); in kasan_bitops_test_and_modify()
1037 KUNIT_EXPECT_KASAN_FAIL(test, test_and_change_bit(nr, addr)); in kasan_bitops_test_and_modify()
1038 KUNIT_EXPECT_KASAN_FAIL(test, __test_and_change_bit(nr, addr)); in kasan_bitops_test_and_modify()
1039 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = test_bit(nr, addr)); in kasan_bitops_test_and_modify()
1042 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = in kasan_bitops_test_and_modify()
1047 static void kasan_bitops_generic(struct kunit *test) in kasan_bitops_generic() argument
1051 /* This test is specifically crafted for the generic mode. */ in kasan_bitops_generic()
1052 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kasan_bitops_generic()
1059 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bits); in kasan_bitops_generic()
1066 kasan_bitops_modify(test, BITS_PER_LONG, bits); in kasan_bitops_generic()
1071 kasan_bitops_test_and_modify(test, BITS_PER_LONG + BITS_PER_BYTE, bits); in kasan_bitops_generic()
1076 static void kasan_bitops_tags(struct kunit *test) in kasan_bitops_tags() argument
1080 /* This test is specifically crafted for tag-based modes. */ in kasan_bitops_tags()
1081 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in kasan_bitops_tags()
1085 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bits); in kasan_bitops_tags()
1088 kasan_bitops_modify(test, BITS_PER_LONG, (void *)bits + 48); in kasan_bitops_tags()
1089 kasan_bitops_test_and_modify(test, BITS_PER_LONG + BITS_PER_BYTE, (void *)bits + 48); in kasan_bitops_tags()
1094 static void kmalloc_double_kzfree(struct kunit *test) in kmalloc_double_kzfree() argument
1100 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_double_kzfree()
1103 KUNIT_EXPECT_KASAN_FAIL(test, kfree_sensitive(ptr)); in kmalloc_double_kzfree()
1106 static void vmalloc_helpers_tags(struct kunit *test) in vmalloc_helpers_tags() argument
1110 /* This test is intended for tag-based modes. */ in vmalloc_helpers_tags()
1111 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in vmalloc_helpers_tags()
1113 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC); in vmalloc_helpers_tags()
1116 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in vmalloc_helpers_tags()
1119 KUNIT_EXPECT_GE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_MIN); in vmalloc_helpers_tags()
1120 KUNIT_EXPECT_LT(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL); in vmalloc_helpers_tags()
1123 KUNIT_ASSERT_TRUE(test, is_vmalloc_addr(ptr)); in vmalloc_helpers_tags()
1124 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, vmalloc_to_page(ptr)); in vmalloc_helpers_tags()
1132 KUNIT_ASSERT_GE(test, rv, 0); in vmalloc_helpers_tags()
1134 KUNIT_ASSERT_GE(test, rv, 0); in vmalloc_helpers_tags()
1141 static void vmalloc_oob(struct kunit *test) in vmalloc_oob() argument
1147 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC); in vmalloc_oob()
1150 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_ptr); in vmalloc_oob()
1168 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)v_ptr)[size]); in vmalloc_oob()
1171 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)v_ptr)[size + 5]); in vmalloc_oob()
1175 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, page); in vmalloc_oob()
1177 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_ptr); in vmalloc_oob()
1189 static void vmap_tags(struct kunit *test) in vmap_tags() argument
1195 * This test is specifically crafted for the software tag-based mode, in vmap_tags()
1198 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_SW_TAGS); in vmap_tags()
1200 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC); in vmap_tags()
1203 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_page); in vmap_tags()
1205 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_ptr); in vmap_tags()
1208 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_ptr); in vmap_tags()
1216 KUNIT_EXPECT_GE(test, (u8)get_tag(v_ptr), (u8)KASAN_TAG_MIN); in vmap_tags()
1217 KUNIT_EXPECT_LT(test, (u8)get_tag(v_ptr), (u8)KASAN_TAG_KERNEL); in vmap_tags()
1225 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_page); in vmap_tags()
1226 KUNIT_EXPECT_PTR_EQ(test, p_page, v_page); in vmap_tags()
1232 static void vm_map_ram_tags(struct kunit *test) in vm_map_ram_tags() argument
1238 * This test is specifically crafted for the software tag-based mode, in vm_map_ram_tags()
1241 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_SW_TAGS); in vm_map_ram_tags()
1244 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, page); in vm_map_ram_tags()
1246 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_ptr); in vm_map_ram_tags()
1249 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_ptr); in vm_map_ram_tags()
1251 KUNIT_EXPECT_GE(test, (u8)get_tag(v_ptr), (u8)KASAN_TAG_MIN); in vm_map_ram_tags()
1252 KUNIT_EXPECT_LT(test, (u8)get_tag(v_ptr), (u8)KASAN_TAG_KERNEL); in vm_map_ram_tags()
1262 static void vmalloc_percpu(struct kunit *test) in vmalloc_percpu() argument
1268 * This test is specifically crafted for the software tag-based mode, in vmalloc_percpu()
1271 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_SW_TAGS); in vmalloc_percpu()
1278 KUNIT_EXPECT_GE(test, (u8)get_tag(c_ptr), (u8)KASAN_TAG_MIN); in vmalloc_percpu()
1279 KUNIT_EXPECT_LT(test, (u8)get_tag(c_ptr), (u8)KASAN_TAG_KERNEL); in vmalloc_percpu()
1293 static void match_all_not_assigned(struct kunit *test) in match_all_not_assigned() argument
1299 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in match_all_not_assigned()
1304 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in match_all_not_assigned()
1305 KUNIT_EXPECT_GE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_MIN); in match_all_not_assigned()
1306 KUNIT_EXPECT_LT(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL); in match_all_not_assigned()
1314 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in match_all_not_assigned()
1315 KUNIT_EXPECT_GE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_MIN); in match_all_not_assigned()
1316 KUNIT_EXPECT_LT(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL); in match_all_not_assigned()
1326 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in match_all_not_assigned()
1327 KUNIT_EXPECT_GE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_MIN); in match_all_not_assigned()
1328 KUNIT_EXPECT_LT(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL); in match_all_not_assigned()
1334 static void match_all_ptr_tag(struct kunit *test) in match_all_ptr_tag() argument
1339 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in match_all_ptr_tag()
1342 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in match_all_ptr_tag()
1346 KUNIT_EXPECT_NE(test, tag, (u8)KASAN_TAG_KERNEL); in match_all_ptr_tag()
1360 static void match_all_mem_tag(struct kunit *test) in match_all_mem_tag() argument
1365 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in match_all_mem_tag()
1368 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in match_all_mem_tag()
1369 KUNIT_EXPECT_NE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL); in match_all_mem_tag()
1380 KUNIT_EXPECT_KASAN_FAIL(test, *ptr = 0); in match_all_mem_tag()