Lines Matching refs:test

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()
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()
306 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size2] = 'x'); in krealloc_more_oob_helper()
309 KUNIT_EXPECT_KASAN_FAIL(test, in krealloc_more_oob_helper()
315 static void krealloc_less_oob_helper(struct kunit *test, in krealloc_less_oob_helper() argument
321 KUNIT_ASSERT_LT(test, size2, size1); in krealloc_less_oob_helper()
325 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in krealloc_less_oob_helper()
328 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); in krealloc_less_oob_helper()
335 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size2] = 'x'); in krealloc_less_oob_helper()
338 KUNIT_EXPECT_KASAN_FAIL(test, in krealloc_less_oob_helper()
345 KUNIT_EXPECT_LE(test, round_up(size2, KASAN_GRANULE_SIZE), in krealloc_less_oob_helper()
347 KUNIT_EXPECT_LE(test, round_up(middle, KASAN_GRANULE_SIZE), in krealloc_less_oob_helper()
349 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[middle] = 'x'); in krealloc_less_oob_helper()
350 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size1 - 1] = 'x'); in krealloc_less_oob_helper()
351 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size1] = 'x'); in krealloc_less_oob_helper()
356 static void krealloc_more_oob(struct kunit *test) in krealloc_more_oob() argument
358 krealloc_more_oob_helper(test, 201, 235); in krealloc_more_oob()
361 static void krealloc_less_oob(struct kunit *test) in krealloc_less_oob() argument
363 krealloc_less_oob_helper(test, 235, 201); in krealloc_less_oob()
366 static void krealloc_pagealloc_more_oob(struct kunit *test) in krealloc_pagealloc_more_oob() argument
369 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); in krealloc_pagealloc_more_oob()
371 krealloc_more_oob_helper(test, KMALLOC_MAX_CACHE_SIZE + 201, in krealloc_pagealloc_more_oob()
375 static void krealloc_pagealloc_less_oob(struct kunit *test) in krealloc_pagealloc_less_oob() argument
378 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); in krealloc_pagealloc_less_oob()
380 krealloc_less_oob_helper(test, KMALLOC_MAX_CACHE_SIZE + 235, in krealloc_pagealloc_less_oob()
388 static void krealloc_uaf(struct kunit *test) in krealloc_uaf() argument
395 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in krealloc_uaf()
398 KUNIT_EXPECT_KASAN_FAIL(test, ptr2 = krealloc(ptr1, size2, GFP_KERNEL)); in krealloc_uaf()
399 KUNIT_ASSERT_NULL(test, ptr2); in krealloc_uaf()
400 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)ptr1); in krealloc_uaf()
403 static void kmalloc_oob_16(struct kunit *test) in kmalloc_oob_16() argument
410 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kmalloc_oob_16()
413 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in kmalloc_oob_16()
416 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); in kmalloc_oob_16()
420 KUNIT_EXPECT_KASAN_FAIL(test, *ptr1 = *ptr2); in kmalloc_oob_16()
425 static void kmalloc_uaf_16(struct kunit *test) in kmalloc_uaf_16() argument
432 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in kmalloc_uaf_16()
435 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); in kmalloc_uaf_16()
438 KUNIT_EXPECT_KASAN_FAIL(test, *ptr1 = *ptr2); in kmalloc_uaf_16()
448 static void kmalloc_oob_memset_2(struct kunit *test) in kmalloc_oob_memset_2() argument
454 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_memset_2()
457 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + size - 1, 0, 2)); in kmalloc_oob_memset_2()
461 static void kmalloc_oob_memset_4(struct kunit *test) in kmalloc_oob_memset_4() argument
467 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_memset_4()
470 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + size - 3, 0, 4)); in kmalloc_oob_memset_4()
474 static void kmalloc_oob_memset_8(struct kunit *test) in kmalloc_oob_memset_8() argument
480 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_memset_8()
483 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + size - 7, 0, 8)); in kmalloc_oob_memset_8()
487 static void kmalloc_oob_memset_16(struct kunit *test) in kmalloc_oob_memset_16() argument
493 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_memset_16()
496 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + size - 15, 0, 16)); in kmalloc_oob_memset_16()
500 static void kmalloc_oob_in_memset(struct kunit *test) in kmalloc_oob_in_memset() argument
506 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_in_memset()
510 KUNIT_EXPECT_KASAN_FAIL(test, in kmalloc_oob_in_memset()
515 static void kmalloc_memmove_negative_size(struct kunit *test) in kmalloc_memmove_negative_size() argument
526 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_HW_TAGS); in kmalloc_memmove_negative_size()
529 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_memmove_negative_size()
534 KUNIT_EXPECT_KASAN_FAIL(test, in kmalloc_memmove_negative_size()
539 static void kmalloc_memmove_invalid_size(struct kunit *test) in kmalloc_memmove_invalid_size() argument
546 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_memmove_invalid_size()
550 KUNIT_EXPECT_KASAN_FAIL(test, in kmalloc_memmove_invalid_size()
555 static void kmalloc_uaf(struct kunit *test) in kmalloc_uaf() argument
561 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_uaf()
564 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[8]); in kmalloc_uaf()
567 static void kmalloc_uaf_memset(struct kunit *test) in kmalloc_uaf_memset() argument
576 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kmalloc_uaf_memset()
579 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_uaf_memset()
582 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr, 0, size)); in kmalloc_uaf_memset()
585 static void kmalloc_uaf2(struct kunit *test) in kmalloc_uaf2() argument
593 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in kmalloc_uaf2()
598 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); in kmalloc_uaf2()
609 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr1)[40]); in kmalloc_uaf2()
610 KUNIT_EXPECT_PTR_NE(test, ptr1, ptr2); in kmalloc_uaf2()
615 static void kfree_via_page(struct kunit *test) in kfree_via_page() argument
623 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kfree_via_page()
630 static void kfree_via_phys(struct kunit *test) in kfree_via_phys() argument
637 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kfree_via_phys()
643 static void kmem_cache_oob(struct kunit *test) in kmem_cache_oob() argument
650 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_oob()
654 kunit_err(test, "Allocation failed: %s\n", __func__); in kmem_cache_oob()
659 KUNIT_EXPECT_KASAN_FAIL(test, *p = p[size + OOB_TAG_OFF]); in kmem_cache_oob()
665 static void kmem_cache_accounted(struct kunit *test) in kmem_cache_accounted() argument
673 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_accounted()
692 static void kmem_cache_bulk(struct kunit *test) in kmem_cache_bulk() argument
701 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_bulk()
705 kunit_err(test, "Allocation failed: %s\n", __func__); in kmem_cache_bulk()
719 static void kasan_global_oob_right(struct kunit *test) in kasan_global_oob_right() argument
737 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kasan_global_oob_right()
739 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p); in kasan_global_oob_right()
742 static void kasan_global_oob_left(struct kunit *test) in kasan_global_oob_left() argument
751 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_CC_IS_CLANG); in kasan_global_oob_left()
752 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kasan_global_oob_left()
753 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p); in kasan_global_oob_left()
757 static void ksize_unpoisons_memory(struct kunit *test) in ksize_unpoisons_memory() argument
763 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in ksize_unpoisons_memory()
772 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[real_size]); in ksize_unpoisons_memory()
781 static void ksize_uaf(struct kunit *test) in ksize_uaf() argument
787 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in ksize_uaf()
791 KUNIT_EXPECT_KASAN_FAIL(test, ksize(ptr)); in ksize_uaf()
792 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[0]); in ksize_uaf()
793 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[size]); in ksize_uaf()
796 static void kasan_stack_oob(struct kunit *test) in kasan_stack_oob() argument
803 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_STACK); in kasan_stack_oob()
805 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p); in kasan_stack_oob()
808 static void kasan_alloca_oob_left(struct kunit *test) in kasan_alloca_oob_left() argument
817 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kasan_alloca_oob_left()
818 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_STACK); in kasan_alloca_oob_left()
820 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p); in kasan_alloca_oob_left()
823 static void kasan_alloca_oob_right(struct kunit *test) in kasan_alloca_oob_right() argument
832 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kasan_alloca_oob_right()
833 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_STACK); in kasan_alloca_oob_right()
835 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p); in kasan_alloca_oob_right()
838 static void kmem_cache_double_free(struct kunit *test) in kmem_cache_double_free() argument
845 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_double_free()
849 kunit_err(test, "Allocation failed: %s\n", __func__); in kmem_cache_double_free()
855 KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_free(cache, p)); in kmem_cache_double_free()
859 static void kmem_cache_invalid_free(struct kunit *test) in kmem_cache_invalid_free() argument
867 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_invalid_free()
871 kunit_err(test, "Allocation failed: %s\n", __func__); in kmem_cache_invalid_free()
877 KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_free(cache, p + 1)); in kmem_cache_invalid_free()
890 static void kmem_cache_double_destroy(struct kunit *test) in kmem_cache_double_destroy() argument
896 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_double_destroy()
898 KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_destroy(cache)); in kmem_cache_double_destroy()
901 static void kasan_memchr(struct kunit *test) in kasan_memchr() argument
910 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_AMD_MEM_ENCRYPT); in kasan_memchr()
916 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kasan_memchr()
920 KUNIT_EXPECT_KASAN_FAIL(test, in kasan_memchr()
926 static void kasan_memcmp(struct kunit *test) in kasan_memcmp() argument
936 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_AMD_MEM_ENCRYPT); in kasan_memcmp()
942 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kasan_memcmp()
947 KUNIT_EXPECT_KASAN_FAIL(test, in kasan_memcmp()
952 static void kasan_strings(struct kunit *test) in kasan_strings() argument
961 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_AMD_MEM_ENCRYPT); in kasan_strings()
964 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kasan_strings()
975 KUNIT_EXPECT_KASAN_FAIL(test, kasan_ptr_result = strchr(ptr, '1')); in kasan_strings()
977 KUNIT_EXPECT_KASAN_FAIL(test, kasan_ptr_result = strrchr(ptr, '1')); in kasan_strings()
979 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = strcmp(ptr, "2")); in kasan_strings()
981 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = strncmp(ptr, "2", 1)); in kasan_strings()
983 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = strlen(ptr)); in kasan_strings()
985 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = strnlen(ptr, 1)); in kasan_strings()
988 static void kasan_bitops_modify(struct kunit *test, int nr, void *addr) in kasan_bitops_modify() argument
990 KUNIT_EXPECT_KASAN_FAIL(test, set_bit(nr, addr)); in kasan_bitops_modify()
991 KUNIT_EXPECT_KASAN_FAIL(test, __set_bit(nr, addr)); in kasan_bitops_modify()
992 KUNIT_EXPECT_KASAN_FAIL(test, clear_bit(nr, addr)); in kasan_bitops_modify()
993 KUNIT_EXPECT_KASAN_FAIL(test, __clear_bit(nr, addr)); in kasan_bitops_modify()
994 KUNIT_EXPECT_KASAN_FAIL(test, clear_bit_unlock(nr, addr)); in kasan_bitops_modify()
995 KUNIT_EXPECT_KASAN_FAIL(test, __clear_bit_unlock(nr, addr)); in kasan_bitops_modify()
996 KUNIT_EXPECT_KASAN_FAIL(test, change_bit(nr, addr)); in kasan_bitops_modify()
997 KUNIT_EXPECT_KASAN_FAIL(test, __change_bit(nr, addr)); in kasan_bitops_modify()
1000 static void kasan_bitops_test_and_modify(struct kunit *test, int nr, void *addr) in kasan_bitops_test_and_modify() argument
1002 KUNIT_EXPECT_KASAN_FAIL(test, test_and_set_bit(nr, addr)); in kasan_bitops_test_and_modify()
1003 KUNIT_EXPECT_KASAN_FAIL(test, __test_and_set_bit(nr, addr)); in kasan_bitops_test_and_modify()
1004 KUNIT_EXPECT_KASAN_FAIL(test, test_and_set_bit_lock(nr, addr)); in kasan_bitops_test_and_modify()
1005 KUNIT_EXPECT_KASAN_FAIL(test, test_and_clear_bit(nr, addr)); in kasan_bitops_test_and_modify()
1006 KUNIT_EXPECT_KASAN_FAIL(test, __test_and_clear_bit(nr, addr)); in kasan_bitops_test_and_modify()
1007 KUNIT_EXPECT_KASAN_FAIL(test, test_and_change_bit(nr, addr)); in kasan_bitops_test_and_modify()
1008 KUNIT_EXPECT_KASAN_FAIL(test, __test_and_change_bit(nr, addr)); in kasan_bitops_test_and_modify()
1009 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = test_bit(nr, addr)); in kasan_bitops_test_and_modify()
1012 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = in kasan_bitops_test_and_modify()
1017 static void kasan_bitops_generic(struct kunit *test) in kasan_bitops_generic() argument
1022 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kasan_bitops_generic()
1029 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bits); in kasan_bitops_generic()
1036 kasan_bitops_modify(test, BITS_PER_LONG, bits); in kasan_bitops_generic()
1041 kasan_bitops_test_and_modify(test, BITS_PER_LONG + BITS_PER_BYTE, bits); in kasan_bitops_generic()
1046 static void kasan_bitops_tags(struct kunit *test) in kasan_bitops_tags() argument
1051 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in kasan_bitops_tags()
1055 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bits); in kasan_bitops_tags()
1058 kasan_bitops_modify(test, BITS_PER_LONG, (void *)bits + 48); in kasan_bitops_tags()
1059 kasan_bitops_test_and_modify(test, BITS_PER_LONG + BITS_PER_BYTE, (void *)bits + 48); in kasan_bitops_tags()
1064 static void kmalloc_double_kzfree(struct kunit *test) in kmalloc_double_kzfree() argument
1070 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_double_kzfree()
1073 KUNIT_EXPECT_KASAN_FAIL(test, kfree_sensitive(ptr)); in kmalloc_double_kzfree()
1076 static void vmalloc_helpers_tags(struct kunit *test) in vmalloc_helpers_tags() argument
1081 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in vmalloc_helpers_tags()
1083 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC); in vmalloc_helpers_tags()
1086 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in vmalloc_helpers_tags()
1089 KUNIT_EXPECT_GE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_MIN); in vmalloc_helpers_tags()
1090 KUNIT_EXPECT_LT(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL); in vmalloc_helpers_tags()
1093 KUNIT_ASSERT_TRUE(test, is_vmalloc_addr(ptr)); in vmalloc_helpers_tags()
1094 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, vmalloc_to_page(ptr)); in vmalloc_helpers_tags()
1102 KUNIT_ASSERT_GE(test, rv, 0); in vmalloc_helpers_tags()
1104 KUNIT_ASSERT_GE(test, rv, 0); in vmalloc_helpers_tags()
1111 static void vmalloc_oob(struct kunit *test) in vmalloc_oob() argument
1117 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC); in vmalloc_oob()
1120 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_ptr); in vmalloc_oob()
1138 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)v_ptr)[size]); in vmalloc_oob()
1141 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)v_ptr)[size + 5]); in vmalloc_oob()
1145 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, page); in vmalloc_oob()
1147 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_ptr); in vmalloc_oob()
1159 static void vmap_tags(struct kunit *test) in vmap_tags() argument
1168 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_SW_TAGS); in vmap_tags()
1170 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC); in vmap_tags()
1173 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_page); in vmap_tags()
1175 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_ptr); in vmap_tags()
1178 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_ptr); in vmap_tags()
1186 KUNIT_EXPECT_GE(test, (u8)get_tag(v_ptr), (u8)KASAN_TAG_MIN); in vmap_tags()
1187 KUNIT_EXPECT_LT(test, (u8)get_tag(v_ptr), (u8)KASAN_TAG_KERNEL); in vmap_tags()
1195 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_page); in vmap_tags()
1196 KUNIT_EXPECT_PTR_EQ(test, p_page, v_page); in vmap_tags()
1202 static void vm_map_ram_tags(struct kunit *test) in vm_map_ram_tags() argument
1211 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_SW_TAGS); in vm_map_ram_tags()
1214 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, page); in vm_map_ram_tags()
1216 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_ptr); in vm_map_ram_tags()
1219 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_ptr); in vm_map_ram_tags()
1221 KUNIT_EXPECT_GE(test, (u8)get_tag(v_ptr), (u8)KASAN_TAG_MIN); in vm_map_ram_tags()
1222 KUNIT_EXPECT_LT(test, (u8)get_tag(v_ptr), (u8)KASAN_TAG_KERNEL); in vm_map_ram_tags()
1232 static void vmalloc_percpu(struct kunit *test) in vmalloc_percpu() argument
1241 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_SW_TAGS); in vmalloc_percpu()
1248 KUNIT_EXPECT_GE(test, (u8)get_tag(c_ptr), (u8)KASAN_TAG_MIN); in vmalloc_percpu()
1249 KUNIT_EXPECT_LT(test, (u8)get_tag(c_ptr), (u8)KASAN_TAG_KERNEL); in vmalloc_percpu()
1263 static void match_all_not_assigned(struct kunit *test) in match_all_not_assigned() argument
1269 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in match_all_not_assigned()
1274 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in match_all_not_assigned()
1275 KUNIT_EXPECT_GE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_MIN); in match_all_not_assigned()
1276 KUNIT_EXPECT_LT(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL); in match_all_not_assigned()
1284 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in match_all_not_assigned()
1285 KUNIT_EXPECT_GE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_MIN); in match_all_not_assigned()
1286 KUNIT_EXPECT_LT(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL); in match_all_not_assigned()
1296 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in match_all_not_assigned()
1297 KUNIT_EXPECT_GE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_MIN); in match_all_not_assigned()
1298 KUNIT_EXPECT_LT(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL); in match_all_not_assigned()
1304 static void match_all_ptr_tag(struct kunit *test) in match_all_ptr_tag() argument
1309 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in match_all_ptr_tag()
1312 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in match_all_ptr_tag()
1316 KUNIT_EXPECT_NE(test, tag, (u8)KASAN_TAG_KERNEL); in match_all_ptr_tag()
1330 static void match_all_mem_tag(struct kunit *test) in match_all_mem_tag() argument
1335 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in match_all_mem_tag()
1338 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in match_all_mem_tag()
1339 KUNIT_EXPECT_NE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL); in match_all_mem_tag()
1350 KUNIT_EXPECT_KASAN_FAIL(test, *ptr = 0); in match_all_mem_tag()