Lines Matching full:test

8 #define pr_fmt(fmt) "kasan: test: " fmt
10 #include <kunit/test.h>
89 static void kasan_test_exit(struct kunit *test) in kasan_test_exit() argument
91 KUNIT_EXPECT_FALSE(test, READ_ONCE(test_status.report_found)); in kasan_test_exit()
96 * KASAN report; causes a KUnit test failure otherwise.
98 * @test: Currently executing KUnit test.
102 * checking is auto-disabled. When this happens, this test handler reenables
116 #define KUNIT_EXPECT_KASAN_FAIL(test, expression) do { \ argument
120 KUNIT_EXPECT_FALSE(test, READ_ONCE(test_status.report_found)); \
127 KUNIT_FAIL(test, KUNIT_SUBTEST_INDENT "KASAN failure " \
142 #define KASAN_TEST_NEEDS_CONFIG_ON(test, config) do { \ argument
144 kunit_skip((test), "Test requires " #config "=y"); \
147 #define KASAN_TEST_NEEDS_CONFIG_OFF(test, config) do { \ argument
149 kunit_skip((test), "Test requires " #config "=n"); \
152 #define KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS(test) do { \ argument
158 kunit_skip((test), "Test requires checked mem*()"); \
161 static void kmalloc_oob_right(struct kunit *test) in kmalloc_oob_right() argument
167 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_right()
175 KUNIT_EXPECT_KASAN_FAIL(test, ptr[size] = 'x'); in kmalloc_oob_right()
181 KUNIT_EXPECT_KASAN_FAIL(test, ptr[size + 5] = 'y'); in kmalloc_oob_right()
184 KUNIT_EXPECT_KASAN_FAIL(test, ptr[0] = in kmalloc_oob_right()
190 static void kmalloc_oob_left(struct kunit *test) in kmalloc_oob_left() argument
196 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_left()
199 KUNIT_EXPECT_KASAN_FAIL(test, *ptr = *(ptr - 1)); in kmalloc_oob_left()
203 static void kmalloc_node_oob_right(struct kunit *test) in kmalloc_node_oob_right() argument
209 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_node_oob_right()
212 KUNIT_EXPECT_KASAN_FAIL(test, ptr[0] = ptr[size]); in kmalloc_node_oob_right()
220 static void kmalloc_big_oob_right(struct kunit *test) in kmalloc_big_oob_right() argument
226 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_big_oob_right()
229 KUNIT_EXPECT_KASAN_FAIL(test, ptr[size] = 0); in kmalloc_big_oob_right()
239 static void kmalloc_large_oob_right(struct kunit *test) in kmalloc_large_oob_right() argument
245 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_large_oob_right()
248 KUNIT_EXPECT_KASAN_FAIL(test, ptr[size + OOB_TAG_OFF] = 0); in kmalloc_large_oob_right()
253 static void kmalloc_large_uaf(struct kunit *test) in kmalloc_large_uaf() argument
259 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_large_uaf()
262 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[0]); in kmalloc_large_uaf()
265 static void kmalloc_large_invalid_free(struct kunit *test) in kmalloc_large_invalid_free() argument
271 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_large_invalid_free()
273 KUNIT_EXPECT_KASAN_FAIL(test, kfree(ptr + 1)); in kmalloc_large_invalid_free()
276 static void page_alloc_oob_right(struct kunit *test) in page_alloc_oob_right() argument
288 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in page_alloc_oob_right()
292 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in page_alloc_oob_right()
294 KUNIT_EXPECT_KASAN_FAIL(test, ptr[0] = ptr[size]); in page_alloc_oob_right()
298 static void page_alloc_uaf(struct kunit *test) in page_alloc_uaf() argument
306 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in page_alloc_uaf()
309 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[0]); in page_alloc_uaf()
312 static void krealloc_more_oob_helper(struct kunit *test, in krealloc_more_oob_helper() argument
318 KUNIT_ASSERT_LT(test, size1, size2); in krealloc_more_oob_helper()
322 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in krealloc_more_oob_helper()
325 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); in krealloc_more_oob_helper()
338 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size2] = 'x'); in krealloc_more_oob_helper()
341 KUNIT_EXPECT_KASAN_FAIL(test, in krealloc_more_oob_helper()
347 static void krealloc_less_oob_helper(struct kunit *test, in krealloc_less_oob_helper() argument
353 KUNIT_ASSERT_LT(test, size2, size1); in krealloc_less_oob_helper()
357 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in krealloc_less_oob_helper()
360 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); in krealloc_less_oob_helper()
370 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size2] = 'x'); in krealloc_less_oob_helper()
373 KUNIT_EXPECT_KASAN_FAIL(test, in krealloc_less_oob_helper()
380 KUNIT_EXPECT_LE(test, round_up(size2, KASAN_GRANULE_SIZE), in krealloc_less_oob_helper()
382 KUNIT_EXPECT_LE(test, round_up(middle, KASAN_GRANULE_SIZE), in krealloc_less_oob_helper()
384 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[middle] = 'x'); in krealloc_less_oob_helper()
385 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size1 - 1] = 'x'); in krealloc_less_oob_helper()
386 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size1] = 'x'); in krealloc_less_oob_helper()
391 static void krealloc_more_oob(struct kunit *test) in krealloc_more_oob() argument
393 krealloc_more_oob_helper(test, 201, 235); in krealloc_more_oob()
396 static void krealloc_less_oob(struct kunit *test) in krealloc_less_oob() argument
398 krealloc_less_oob_helper(test, 235, 201); in krealloc_less_oob()
401 static void krealloc_large_more_oob(struct kunit *test) in krealloc_large_more_oob() argument
403 krealloc_more_oob_helper(test, KMALLOC_MAX_CACHE_SIZE + 201, in krealloc_large_more_oob()
407 static void krealloc_large_less_oob(struct kunit *test) in krealloc_large_less_oob() argument
409 krealloc_less_oob_helper(test, KMALLOC_MAX_CACHE_SIZE + 235, in krealloc_large_less_oob()
417 static void krealloc_uaf(struct kunit *test) in krealloc_uaf() argument
424 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in krealloc_uaf()
427 KUNIT_EXPECT_KASAN_FAIL(test, ptr2 = krealloc(ptr1, size2, GFP_KERNEL)); in krealloc_uaf()
428 KUNIT_ASSERT_NULL(test, ptr2); in krealloc_uaf()
429 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)ptr1); in krealloc_uaf()
432 static void kmalloc_oob_16(struct kunit *test) in kmalloc_oob_16() argument
438 KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS(test); in kmalloc_oob_16()
440 /* This test is specifically crafted for the generic mode. */ in kmalloc_oob_16()
441 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kmalloc_oob_16()
445 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in kmalloc_oob_16()
448 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); in kmalloc_oob_16()
452 KUNIT_EXPECT_KASAN_FAIL(test, *ptr1 = *ptr2); in kmalloc_oob_16()
457 static void kmalloc_uaf_16(struct kunit *test) in kmalloc_uaf_16() argument
463 KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS(test); in kmalloc_uaf_16()
466 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in kmalloc_uaf_16()
469 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); in kmalloc_uaf_16()
472 KUNIT_EXPECT_KASAN_FAIL(test, *ptr1 = *ptr2); in kmalloc_uaf_16()
482 static void kmalloc_oob_memset_2(struct kunit *test) in kmalloc_oob_memset_2() argument
488 KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS(test); in kmalloc_oob_memset_2()
491 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_memset_2()
496 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + size - 1, 0, memset_size)); in kmalloc_oob_memset_2()
500 static void kmalloc_oob_memset_4(struct kunit *test) in kmalloc_oob_memset_4() argument
506 KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS(test); in kmalloc_oob_memset_4()
509 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_memset_4()
514 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + size - 3, 0, memset_size)); in kmalloc_oob_memset_4()
518 static void kmalloc_oob_memset_8(struct kunit *test) in kmalloc_oob_memset_8() argument
524 KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS(test); in kmalloc_oob_memset_8()
527 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_memset_8()
532 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + size - 7, 0, memset_size)); in kmalloc_oob_memset_8()
536 static void kmalloc_oob_memset_16(struct kunit *test) in kmalloc_oob_memset_16() argument
542 KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS(test); in kmalloc_oob_memset_16()
545 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_memset_16()
550 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + size - 15, 0, memset_size)); in kmalloc_oob_memset_16()
554 static void kmalloc_oob_in_memset(struct kunit *test) in kmalloc_oob_in_memset() argument
559 KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS(test); in kmalloc_oob_in_memset()
562 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_oob_in_memset()
566 KUNIT_EXPECT_KASAN_FAIL(test, in kmalloc_oob_in_memset()
571 static void kmalloc_memmove_negative_size(struct kunit *test) in kmalloc_memmove_negative_size() argument
577 KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS(test); in kmalloc_memmove_negative_size()
581 * As a result, this test introduces a side-effect memory corruption, in kmalloc_memmove_negative_size()
584 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_HW_TAGS); in kmalloc_memmove_negative_size()
587 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_memmove_negative_size()
592 KUNIT_EXPECT_KASAN_FAIL(test, in kmalloc_memmove_negative_size()
597 static void kmalloc_memmove_invalid_size(struct kunit *test) in kmalloc_memmove_invalid_size() argument
603 KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS(test); in kmalloc_memmove_invalid_size()
606 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_memmove_invalid_size()
611 KUNIT_EXPECT_KASAN_FAIL(test, in kmalloc_memmove_invalid_size()
616 static void kmalloc_uaf(struct kunit *test) in kmalloc_uaf() argument
622 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_uaf()
625 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[8]); in kmalloc_uaf()
628 static void kmalloc_uaf_memset(struct kunit *test) in kmalloc_uaf_memset() argument
633 KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS(test); in kmalloc_uaf_memset()
637 * kernel memory corruption this test causes. in kmalloc_uaf_memset()
639 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kmalloc_uaf_memset()
642 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_uaf_memset()
645 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr, 0, size)); in kmalloc_uaf_memset()
648 static void kmalloc_uaf2(struct kunit *test) in kmalloc_uaf2() argument
656 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in kmalloc_uaf2()
661 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); in kmalloc_uaf2()
672 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr1)[40]); in kmalloc_uaf2()
673 KUNIT_EXPECT_PTR_NE(test, ptr1, ptr2); in kmalloc_uaf2()
682 static void kmalloc_uaf3(struct kunit *test) in kmalloc_uaf3() argument
687 /* This test is specifically crafted for tag-based modes. */ in kmalloc_uaf3()
688 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in kmalloc_uaf3()
691 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); in kmalloc_uaf3()
695 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2); in kmalloc_uaf3()
698 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr1)[8]); in kmalloc_uaf3()
701 static void kasan_atomics_helper(struct kunit *test, void *unsafe, void *safe) in kasan_atomics_helper() argument
705 KUNIT_EXPECT_KASAN_FAIL(test, READ_ONCE(*i_unsafe)); in kasan_atomics_helper()
706 KUNIT_EXPECT_KASAN_FAIL(test, WRITE_ONCE(*i_unsafe, 42)); in kasan_atomics_helper()
707 KUNIT_EXPECT_KASAN_FAIL(test, smp_load_acquire(i_unsafe)); in kasan_atomics_helper()
708 KUNIT_EXPECT_KASAN_FAIL(test, smp_store_release(i_unsafe, 42)); in kasan_atomics_helper()
710 KUNIT_EXPECT_KASAN_FAIL(test, atomic_read(unsafe)); in kasan_atomics_helper()
711 KUNIT_EXPECT_KASAN_FAIL(test, atomic_set(unsafe, 42)); in kasan_atomics_helper()
712 KUNIT_EXPECT_KASAN_FAIL(test, atomic_add(42, unsafe)); in kasan_atomics_helper()
713 KUNIT_EXPECT_KASAN_FAIL(test, atomic_sub(42, unsafe)); in kasan_atomics_helper()
714 KUNIT_EXPECT_KASAN_FAIL(test, atomic_inc(unsafe)); in kasan_atomics_helper()
715 KUNIT_EXPECT_KASAN_FAIL(test, atomic_dec(unsafe)); in kasan_atomics_helper()
716 KUNIT_EXPECT_KASAN_FAIL(test, atomic_and(42, unsafe)); in kasan_atomics_helper()
717 KUNIT_EXPECT_KASAN_FAIL(test, atomic_andnot(42, unsafe)); in kasan_atomics_helper()
718 KUNIT_EXPECT_KASAN_FAIL(test, atomic_or(42, unsafe)); in kasan_atomics_helper()
719 KUNIT_EXPECT_KASAN_FAIL(test, atomic_xor(42, unsafe)); in kasan_atomics_helper()
720 KUNIT_EXPECT_KASAN_FAIL(test, atomic_xchg(unsafe, 42)); in kasan_atomics_helper()
721 KUNIT_EXPECT_KASAN_FAIL(test, atomic_cmpxchg(unsafe, 21, 42)); in kasan_atomics_helper()
722 KUNIT_EXPECT_KASAN_FAIL(test, atomic_try_cmpxchg(unsafe, safe, 42)); in kasan_atomics_helper()
723 KUNIT_EXPECT_KASAN_FAIL(test, atomic_try_cmpxchg(safe, unsafe, 42)); in kasan_atomics_helper()
724 KUNIT_EXPECT_KASAN_FAIL(test, atomic_sub_and_test(42, unsafe)); in kasan_atomics_helper()
725 KUNIT_EXPECT_KASAN_FAIL(test, atomic_dec_and_test(unsafe)); in kasan_atomics_helper()
726 KUNIT_EXPECT_KASAN_FAIL(test, atomic_inc_and_test(unsafe)); in kasan_atomics_helper()
727 KUNIT_EXPECT_KASAN_FAIL(test, atomic_add_negative(42, unsafe)); in kasan_atomics_helper()
728 KUNIT_EXPECT_KASAN_FAIL(test, atomic_add_unless(unsafe, 21, 42)); in kasan_atomics_helper()
729 KUNIT_EXPECT_KASAN_FAIL(test, atomic_inc_not_zero(unsafe)); in kasan_atomics_helper()
730 KUNIT_EXPECT_KASAN_FAIL(test, atomic_inc_unless_negative(unsafe)); in kasan_atomics_helper()
731 KUNIT_EXPECT_KASAN_FAIL(test, atomic_dec_unless_positive(unsafe)); in kasan_atomics_helper()
732 KUNIT_EXPECT_KASAN_FAIL(test, atomic_dec_if_positive(unsafe)); in kasan_atomics_helper()
734 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_read(unsafe)); in kasan_atomics_helper()
735 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_set(unsafe, 42)); in kasan_atomics_helper()
736 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_add(42, unsafe)); in kasan_atomics_helper()
737 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_sub(42, unsafe)); in kasan_atomics_helper()
738 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_inc(unsafe)); in kasan_atomics_helper()
739 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_dec(unsafe)); in kasan_atomics_helper()
740 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_and(42, unsafe)); in kasan_atomics_helper()
741 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_andnot(42, unsafe)); in kasan_atomics_helper()
742 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_or(42, unsafe)); in kasan_atomics_helper()
743 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_xor(42, unsafe)); in kasan_atomics_helper()
744 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_xchg(unsafe, 42)); in kasan_atomics_helper()
745 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_cmpxchg(unsafe, 21, 42)); in kasan_atomics_helper()
746 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_try_cmpxchg(unsafe, safe, 42)); in kasan_atomics_helper()
747 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_try_cmpxchg(safe, unsafe, 42)); in kasan_atomics_helper()
748 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_sub_and_test(42, unsafe)); in kasan_atomics_helper()
749 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_dec_and_test(unsafe)); in kasan_atomics_helper()
750 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_inc_and_test(unsafe)); in kasan_atomics_helper()
751 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_add_negative(42, unsafe)); in kasan_atomics_helper()
752 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_add_unless(unsafe, 21, 42)); in kasan_atomics_helper()
753 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_inc_not_zero(unsafe)); in kasan_atomics_helper()
754 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_inc_unless_negative(unsafe)); in kasan_atomics_helper()
755 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_dec_unless_positive(unsafe)); in kasan_atomics_helper()
756 KUNIT_EXPECT_KASAN_FAIL(test, atomic_long_dec_if_positive(unsafe)); in kasan_atomics_helper()
759 static void kasan_atomics(struct kunit *test) in kasan_atomics() argument
768 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, a1); in kasan_atomics()
770 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, a2); in kasan_atomics()
773 kasan_atomics_helper(test, a1 + 48, a2); in kasan_atomics()
779 static void kmalloc_double_kzfree(struct kunit *test) in kmalloc_double_kzfree() argument
785 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kmalloc_double_kzfree()
788 KUNIT_EXPECT_KASAN_FAIL(test, kfree_sensitive(ptr)); in kmalloc_double_kzfree()
792 static void ksize_unpoisons_memory(struct kunit *test) in ksize_unpoisons_memory() argument
799 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in ksize_unpoisons_memory()
802 KUNIT_EXPECT_GT(test, real_size, size); in ksize_unpoisons_memory()
812 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[size]); in ksize_unpoisons_memory()
813 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[size + 5]); in ksize_unpoisons_memory()
814 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[real_size - 1]); in ksize_unpoisons_memory()
823 static void ksize_uaf(struct kunit *test) in ksize_uaf() argument
829 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in ksize_uaf()
833 KUNIT_EXPECT_KASAN_FAIL(test, ksize(ptr)); in ksize_uaf()
834 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[0]); in ksize_uaf()
835 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[size]); in ksize_uaf()
860 static void rcu_uaf(struct kunit *test) in rcu_uaf() argument
865 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in rcu_uaf()
870 KUNIT_EXPECT_KASAN_FAIL(test, in rcu_uaf()
880 static void workqueue_uaf(struct kunit *test) in workqueue_uaf() argument
886 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, workqueue); in workqueue_uaf()
889 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, work); in workqueue_uaf()
895 KUNIT_EXPECT_KASAN_FAIL(test, in workqueue_uaf()
899 static void kfree_via_page(struct kunit *test) in kfree_via_page() argument
907 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kfree_via_page()
914 static void kfree_via_phys(struct kunit *test) in kfree_via_phys() argument
921 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kfree_via_phys()
927 static void kmem_cache_oob(struct kunit *test) in kmem_cache_oob() argument
934 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_oob()
938 kunit_err(test, "Allocation failed: %s\n", __func__); in kmem_cache_oob()
943 KUNIT_EXPECT_KASAN_FAIL(test, *p = p[size + OOB_TAG_OFF]); in kmem_cache_oob()
949 static void kmem_cache_double_free(struct kunit *test) in kmem_cache_double_free() argument
956 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_double_free()
960 kunit_err(test, "Allocation failed: %s\n", __func__); in kmem_cache_double_free()
966 KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_free(cache, p)); in kmem_cache_double_free()
970 static void kmem_cache_invalid_free(struct kunit *test) in kmem_cache_invalid_free() argument
978 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_invalid_free()
982 kunit_err(test, "Allocation failed: %s\n", __func__); in kmem_cache_invalid_free()
988 KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_free(cache, p + 1)); in kmem_cache_invalid_free()
999 static void kmem_cache_rcu_uaf(struct kunit *test) in kmem_cache_rcu_uaf() argument
1005 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB_RCU_DEBUG); in kmem_cache_rcu_uaf()
1009 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_rcu_uaf()
1013 kunit_err(test, "Allocation failed: %s\n", __func__); in kmem_cache_rcu_uaf()
1039 KUNIT_EXPECT_KASAN_FAIL(test, READ_ONCE(*p)); in kmem_cache_rcu_uaf()
1046 static void kmem_cache_double_destroy(struct kunit *test) in kmem_cache_double_destroy() argument
1052 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_double_destroy()
1054 KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_destroy(cache)); in kmem_cache_double_destroy()
1057 static void kmem_cache_accounted(struct kunit *test) in kmem_cache_accounted() argument
1065 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_accounted()
1084 static void kmem_cache_bulk(struct kunit *test) in kmem_cache_bulk() argument
1093 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in kmem_cache_bulk()
1097 kunit_err(test, "Allocation failed: %s\n", __func__); in kmem_cache_bulk()
1109 static void *mempool_prepare_kmalloc(struct kunit *test, mempool_t *pool, size_t size) in mempool_prepare_kmalloc() argument
1117 KUNIT_ASSERT_EQ(test, ret, 0); in mempool_prepare_kmalloc()
1126 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, elem); in mempool_prepare_kmalloc()
1131 static struct kmem_cache *mempool_prepare_slab(struct kunit *test, mempool_t *pool, size_t size) in mempool_prepare_slab() argument
1138 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache); in mempool_prepare_slab()
1142 KUNIT_ASSERT_EQ(test, ret, 0); in mempool_prepare_slab()
1152 static void *mempool_prepare_page(struct kunit *test, mempool_t *pool, int order) in mempool_prepare_page() argument
1160 KUNIT_ASSERT_EQ(test, ret, 0); in mempool_prepare_page()
1163 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, elem); in mempool_prepare_page()
1168 static void mempool_oob_right_helper(struct kunit *test, mempool_t *pool, size_t size) in mempool_oob_right_helper() argument
1173 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, elem); in mempool_oob_right_helper()
1178 KUNIT_EXPECT_KASAN_FAIL(test, in mempool_oob_right_helper()
1181 KUNIT_EXPECT_KASAN_FAIL(test, in mempool_oob_right_helper()
1187 static void mempool_kmalloc_oob_right(struct kunit *test) in mempool_kmalloc_oob_right() argument
1193 extra_elem = mempool_prepare_kmalloc(test, &pool, size); in mempool_kmalloc_oob_right()
1195 mempool_oob_right_helper(test, &pool, size); in mempool_kmalloc_oob_right()
1201 static void mempool_kmalloc_large_oob_right(struct kunit *test) in mempool_kmalloc_large_oob_right() argument
1207 extra_elem = mempool_prepare_kmalloc(test, &pool, size); in mempool_kmalloc_large_oob_right()
1209 mempool_oob_right_helper(test, &pool, size); in mempool_kmalloc_large_oob_right()
1215 static void mempool_slab_oob_right(struct kunit *test) in mempool_slab_oob_right() argument
1221 cache = mempool_prepare_slab(test, &pool, size); in mempool_slab_oob_right()
1223 mempool_oob_right_helper(test, &pool, size); in mempool_slab_oob_right()
1230 * Skip the out-of-bounds test for page mempool. With Generic KASAN, page
1237 static void mempool_uaf_helper(struct kunit *test, mempool_t *pool, bool page) in mempool_uaf_helper() argument
1242 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, elem); in mempool_uaf_helper()
1247 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[0]); in mempool_uaf_helper()
1250 static void mempool_kmalloc_uaf(struct kunit *test) in mempool_kmalloc_uaf() argument
1256 extra_elem = mempool_prepare_kmalloc(test, &pool, size); in mempool_kmalloc_uaf()
1258 mempool_uaf_helper(test, &pool, false); in mempool_kmalloc_uaf()
1264 static void mempool_kmalloc_large_uaf(struct kunit *test) in mempool_kmalloc_large_uaf() argument
1270 extra_elem = mempool_prepare_kmalloc(test, &pool, size); in mempool_kmalloc_large_uaf()
1272 mempool_uaf_helper(test, &pool, false); in mempool_kmalloc_large_uaf()
1278 static void mempool_slab_uaf(struct kunit *test) in mempool_slab_uaf() argument
1284 cache = mempool_prepare_slab(test, &pool, size); in mempool_slab_uaf()
1286 mempool_uaf_helper(test, &pool, false); in mempool_slab_uaf()
1292 static void mempool_page_alloc_uaf(struct kunit *test) in mempool_page_alloc_uaf() argument
1298 extra_elem = mempool_prepare_page(test, &pool, order); in mempool_page_alloc_uaf()
1300 mempool_uaf_helper(test, &pool, true); in mempool_page_alloc_uaf()
1306 static void mempool_double_free_helper(struct kunit *test, mempool_t *pool) in mempool_double_free_helper() argument
1311 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, elem); in mempool_double_free_helper()
1315 KUNIT_EXPECT_KASAN_FAIL(test, mempool_free(elem, pool)); in mempool_double_free_helper()
1318 static void mempool_kmalloc_double_free(struct kunit *test) in mempool_kmalloc_double_free() argument
1324 extra_elem = mempool_prepare_kmalloc(test, &pool, size); in mempool_kmalloc_double_free()
1326 mempool_double_free_helper(test, &pool); in mempool_kmalloc_double_free()
1332 static void mempool_kmalloc_large_double_free(struct kunit *test) in mempool_kmalloc_large_double_free() argument
1338 extra_elem = mempool_prepare_kmalloc(test, &pool, size); in mempool_kmalloc_large_double_free()
1340 mempool_double_free_helper(test, &pool); in mempool_kmalloc_large_double_free()
1346 static void mempool_page_alloc_double_free(struct kunit *test) in mempool_page_alloc_double_free() argument
1352 extra_elem = mempool_prepare_page(test, &pool, order); in mempool_page_alloc_double_free()
1354 mempool_double_free_helper(test, &pool); in mempool_page_alloc_double_free()
1360 static void mempool_kmalloc_invalid_free_helper(struct kunit *test, mempool_t *pool) in mempool_kmalloc_invalid_free_helper() argument
1365 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, elem); in mempool_kmalloc_invalid_free_helper()
1367 KUNIT_EXPECT_KASAN_FAIL(test, mempool_free(elem + 1, pool)); in mempool_kmalloc_invalid_free_helper()
1372 static void mempool_kmalloc_invalid_free(struct kunit *test) in mempool_kmalloc_invalid_free() argument
1378 extra_elem = mempool_prepare_kmalloc(test, &pool, size); in mempool_kmalloc_invalid_free()
1380 mempool_kmalloc_invalid_free_helper(test, &pool); in mempool_kmalloc_invalid_free()
1386 static void mempool_kmalloc_large_invalid_free(struct kunit *test) in mempool_kmalloc_large_invalid_free() argument
1392 extra_elem = mempool_prepare_kmalloc(test, &pool, size); in mempool_kmalloc_large_invalid_free()
1394 mempool_kmalloc_invalid_free_helper(test, &pool); in mempool_kmalloc_large_invalid_free()
1401 * Skip the invalid-free test for page mempool. The invalid-free detection only
1408 static void kasan_global_oob_right(struct kunit *test) in kasan_global_oob_right() argument
1426 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kasan_global_oob_right()
1428 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p); in kasan_global_oob_right()
1431 static void kasan_global_oob_left(struct kunit *test) in kasan_global_oob_left() argument
1437 * GCC is known to fail this test, skip it. in kasan_global_oob_left()
1440 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_CC_IS_CLANG); in kasan_global_oob_left()
1441 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kasan_global_oob_left()
1442 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p); in kasan_global_oob_left()
1445 static void kasan_stack_oob(struct kunit *test) in kasan_stack_oob() argument
1452 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_STACK); in kasan_stack_oob()
1454 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p); in kasan_stack_oob()
1457 static void kasan_alloca_oob_left(struct kunit *test) in kasan_alloca_oob_left() argument
1466 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kasan_alloca_oob_left()
1467 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_STACK); in kasan_alloca_oob_left()
1469 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p); in kasan_alloca_oob_left()
1472 static void kasan_alloca_oob_right(struct kunit *test) in kasan_alloca_oob_right() argument
1481 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kasan_alloca_oob_right()
1482 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_STACK); in kasan_alloca_oob_right()
1484 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p); in kasan_alloca_oob_right()
1487 static void kasan_memchr(struct kunit *test) in kasan_memchr() argument
1496 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_AMD_MEM_ENCRYPT); in kasan_memchr()
1502 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kasan_memchr()
1506 KUNIT_EXPECT_KASAN_FAIL(test, in kasan_memchr()
1512 static void kasan_memcmp(struct kunit *test) in kasan_memcmp() argument
1522 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_AMD_MEM_ENCRYPT); in kasan_memcmp()
1528 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kasan_memcmp()
1533 KUNIT_EXPECT_KASAN_FAIL(test, in kasan_memcmp()
1538 static void kasan_strings(struct kunit *test) in kasan_strings() argument
1547 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_AMD_MEM_ENCRYPT); in kasan_strings()
1550 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in kasan_strings()
1561 KUNIT_EXPECT_KASAN_FAIL(test, kasan_ptr_result = strchr(ptr, '1')); in kasan_strings()
1563 KUNIT_EXPECT_KASAN_FAIL(test, kasan_ptr_result = strrchr(ptr, '1')); in kasan_strings()
1565 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = strcmp(ptr, "2")); in kasan_strings()
1567 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = strncmp(ptr, "2", 1)); in kasan_strings()
1569 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = strlen(ptr)); in kasan_strings()
1571 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = strnlen(ptr, 1)); in kasan_strings()
1574 static void kasan_bitops_modify(struct kunit *test, int nr, void *addr) in kasan_bitops_modify() argument
1576 KUNIT_EXPECT_KASAN_FAIL(test, set_bit(nr, addr)); in kasan_bitops_modify()
1577 KUNIT_EXPECT_KASAN_FAIL(test, __set_bit(nr, addr)); in kasan_bitops_modify()
1578 KUNIT_EXPECT_KASAN_FAIL(test, clear_bit(nr, addr)); in kasan_bitops_modify()
1579 KUNIT_EXPECT_KASAN_FAIL(test, __clear_bit(nr, addr)); in kasan_bitops_modify()
1580 KUNIT_EXPECT_KASAN_FAIL(test, clear_bit_unlock(nr, addr)); in kasan_bitops_modify()
1581 KUNIT_EXPECT_KASAN_FAIL(test, __clear_bit_unlock(nr, addr)); in kasan_bitops_modify()
1582 KUNIT_EXPECT_KASAN_FAIL(test, change_bit(nr, addr)); in kasan_bitops_modify()
1583 KUNIT_EXPECT_KASAN_FAIL(test, __change_bit(nr, addr)); in kasan_bitops_modify()
1586 static void kasan_bitops_test_and_modify(struct kunit *test, int nr, void *addr) in kasan_bitops_test_and_modify() argument
1588 KUNIT_EXPECT_KASAN_FAIL(test, test_and_set_bit(nr, addr)); in kasan_bitops_test_and_modify()
1589 KUNIT_EXPECT_KASAN_FAIL(test, __test_and_set_bit(nr, addr)); in kasan_bitops_test_and_modify()
1590 KUNIT_EXPECT_KASAN_FAIL(test, test_and_set_bit_lock(nr, addr)); in kasan_bitops_test_and_modify()
1591 KUNIT_EXPECT_KASAN_FAIL(test, test_and_clear_bit(nr, addr)); in kasan_bitops_test_and_modify()
1592 KUNIT_EXPECT_KASAN_FAIL(test, __test_and_clear_bit(nr, addr)); in kasan_bitops_test_and_modify()
1593 KUNIT_EXPECT_KASAN_FAIL(test, test_and_change_bit(nr, addr)); in kasan_bitops_test_and_modify()
1594 KUNIT_EXPECT_KASAN_FAIL(test, __test_and_change_bit(nr, addr)); in kasan_bitops_test_and_modify()
1595 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = test_bit(nr, addr)); in kasan_bitops_test_and_modify()
1597 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = in kasan_bitops_test_and_modify()
1601 static void kasan_bitops_generic(struct kunit *test) in kasan_bitops_generic() argument
1605 /* This test is specifically crafted for the generic mode. */ in kasan_bitops_generic()
1606 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); in kasan_bitops_generic()
1613 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bits); in kasan_bitops_generic()
1620 kasan_bitops_modify(test, BITS_PER_LONG, bits); in kasan_bitops_generic()
1625 kasan_bitops_test_and_modify(test, BITS_PER_LONG + BITS_PER_BYTE, bits); in kasan_bitops_generic()
1630 static void kasan_bitops_tags(struct kunit *test) in kasan_bitops_tags() argument
1634 /* This test is specifically crafted for tag-based modes. */ in kasan_bitops_tags()
1635 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in kasan_bitops_tags()
1639 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bits); in kasan_bitops_tags()
1642 kasan_bitops_modify(test, BITS_PER_LONG, (void *)bits + 48); in kasan_bitops_tags()
1643 kasan_bitops_test_and_modify(test, BITS_PER_LONG + BITS_PER_BYTE, (void *)bits + 48); in kasan_bitops_tags()
1648 static void vmalloc_helpers_tags(struct kunit *test) in vmalloc_helpers_tags() argument
1652 /* This test is intended for tag-based modes. */ in vmalloc_helpers_tags()
1653 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in vmalloc_helpers_tags()
1655 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC); in vmalloc_helpers_tags()
1658 kunit_skip(test, "Test requires kasan.vmalloc=on"); in vmalloc_helpers_tags()
1661 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in vmalloc_helpers_tags()
1664 KUNIT_EXPECT_GE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_MIN); in vmalloc_helpers_tags()
1665 KUNIT_EXPECT_LT(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL); in vmalloc_helpers_tags()
1668 KUNIT_ASSERT_TRUE(test, is_vmalloc_addr(ptr)); in vmalloc_helpers_tags()
1669 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, vmalloc_to_page(ptr)); in vmalloc_helpers_tags()
1677 KUNIT_ASSERT_GE(test, rv, 0); in vmalloc_helpers_tags()
1679 KUNIT_ASSERT_GE(test, rv, 0); in vmalloc_helpers_tags()
1686 static void vmalloc_oob(struct kunit *test) in vmalloc_oob() argument
1692 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC); in vmalloc_oob()
1695 kunit_skip(test, "Test requires kasan.vmalloc=on"); in vmalloc_oob()
1698 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_ptr); in vmalloc_oob()
1716 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)v_ptr)[size]); in vmalloc_oob()
1719 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)v_ptr)[size + 5]); in vmalloc_oob()
1723 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, page); in vmalloc_oob()
1725 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_ptr); in vmalloc_oob()
1737 static void vmap_tags(struct kunit *test) in vmap_tags() argument
1743 * This test is specifically crafted for the software tag-based mode, in vmap_tags()
1746 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_SW_TAGS); in vmap_tags()
1748 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC); in vmap_tags()
1751 kunit_skip(test, "Test requires kasan.vmalloc=on"); in vmap_tags()
1754 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_page); in vmap_tags()
1756 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_ptr); in vmap_tags()
1759 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_ptr); in vmap_tags()
1767 KUNIT_EXPECT_GE(test, (u8)get_tag(v_ptr), (u8)KASAN_TAG_MIN); in vmap_tags()
1768 KUNIT_EXPECT_LT(test, (u8)get_tag(v_ptr), (u8)KASAN_TAG_KERNEL); in vmap_tags()
1776 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_page); in vmap_tags()
1777 KUNIT_EXPECT_PTR_EQ(test, p_page, v_page); in vmap_tags()
1783 static void vm_map_ram_tags(struct kunit *test) in vm_map_ram_tags() argument
1789 * This test is specifically crafted for the software tag-based mode, in vm_map_ram_tags()
1792 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_SW_TAGS); in vm_map_ram_tags()
1795 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, page); in vm_map_ram_tags()
1797 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_ptr); in vm_map_ram_tags()
1800 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_ptr); in vm_map_ram_tags()
1802 KUNIT_EXPECT_GE(test, (u8)get_tag(v_ptr), (u8)KASAN_TAG_MIN); in vm_map_ram_tags()
1803 KUNIT_EXPECT_LT(test, (u8)get_tag(v_ptr), (u8)KASAN_TAG_KERNEL); in vm_map_ram_tags()
1818 static void match_all_not_assigned(struct kunit *test) in match_all_not_assigned() argument
1824 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in match_all_not_assigned()
1829 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in match_all_not_assigned()
1830 KUNIT_EXPECT_GE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_MIN); in match_all_not_assigned()
1831 KUNIT_EXPECT_LT(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL); in match_all_not_assigned()
1839 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in match_all_not_assigned()
1840 KUNIT_EXPECT_GE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_MIN); in match_all_not_assigned()
1841 KUNIT_EXPECT_LT(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL); in match_all_not_assigned()
1851 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in match_all_not_assigned()
1852 KUNIT_EXPECT_GE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_MIN); in match_all_not_assigned()
1853 KUNIT_EXPECT_LT(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL); in match_all_not_assigned()
1859 static void match_all_ptr_tag(struct kunit *test) in match_all_ptr_tag() argument
1864 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in match_all_ptr_tag()
1867 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in match_all_ptr_tag()
1871 KUNIT_EXPECT_NE(test, tag, (u8)KASAN_TAG_KERNEL); in match_all_ptr_tag()
1885 static void match_all_mem_tag(struct kunit *test) in match_all_mem_tag() argument
1890 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC); in match_all_mem_tag()
1893 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); in match_all_mem_tag()
1894 KUNIT_EXPECT_NE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL); in match_all_mem_tag()
1900 * values to avoid the test printing too many reports. in match_all_mem_tag()
1913 KUNIT_EXPECT_KASAN_FAIL(test, *ptr = 0); in match_all_mem_tag()
1923 * This is a smoke test to make sure that Rust is being sanitized properly.
1925 static void rust_uaf(struct kunit *test) in rust_uaf() argument
1927 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_RUST); in rust_uaf()
1928 KUNIT_EXPECT_KASAN_FAIL(test, kasan_test_rust_uaf()); in rust_uaf()