@@ -165,6 +165,15 @@ static void kasan_test_exit(struct kunit *test)
165
165
kunit_skip((test), "Test requires " #config "=n"); \
166
166
} while (0)
167
167
168
+ #define KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS (test ) do { \
169
+ if (IS_ENABLED(CONFIG_KASAN_HW_TAGS)) \
170
+ break; /* No compiler instrumentation. */ \
171
+ if (IS_ENABLED (CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX )) \
172
+ break ; /* Should always be instrumented! */ \
173
+ if (IS_ENABLED (CONFIG_GENERIC_ENTRY )) \
174
+ kunit_skip ((test ), "Test requires checked mem*()" ); \
175
+ } while (0 )
176
+
168
177
static void kmalloc_oob_right (struct kunit * test )
169
178
{
170
179
char * ptr ;
@@ -454,6 +463,8 @@ static void kmalloc_oob_16(struct kunit *test)
454
463
u64 words [2 ];
455
464
} * ptr1 , * ptr2 ;
456
465
466
+ KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS (test );
467
+
457
468
/* This test is specifically crafted for the generic mode. */
458
469
KASAN_TEST_NEEDS_CONFIG_ON (test , CONFIG_KASAN_GENERIC );
459
470
@@ -476,6 +487,8 @@ static void kmalloc_uaf_16(struct kunit *test)
476
487
u64 words [2 ];
477
488
} * ptr1 , * ptr2 ;
478
489
490
+ KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS (test );
491
+
479
492
ptr1 = kmalloc (sizeof (* ptr1 ), GFP_KERNEL );
480
493
KUNIT_ASSERT_NOT_ERR_OR_NULL (test , ptr1 );
481
494
@@ -498,6 +511,8 @@ static void kmalloc_oob_memset_2(struct kunit *test)
498
511
char * ptr ;
499
512
size_t size = 128 - KASAN_GRANULE_SIZE ;
500
513
514
+ KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS (test );
515
+
501
516
ptr = kmalloc (size , GFP_KERNEL );
502
517
KUNIT_ASSERT_NOT_ERR_OR_NULL (test , ptr );
503
518
@@ -511,6 +526,8 @@ static void kmalloc_oob_memset_4(struct kunit *test)
511
526
char * ptr ;
512
527
size_t size = 128 - KASAN_GRANULE_SIZE ;
513
528
529
+ KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS (test );
530
+
514
531
ptr = kmalloc (size , GFP_KERNEL );
515
532
KUNIT_ASSERT_NOT_ERR_OR_NULL (test , ptr );
516
533
@@ -524,6 +541,8 @@ static void kmalloc_oob_memset_8(struct kunit *test)
524
541
char * ptr ;
525
542
size_t size = 128 - KASAN_GRANULE_SIZE ;
526
543
544
+ KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS (test );
545
+
527
546
ptr = kmalloc (size , GFP_KERNEL );
528
547
KUNIT_ASSERT_NOT_ERR_OR_NULL (test , ptr );
529
548
@@ -537,6 +556,8 @@ static void kmalloc_oob_memset_16(struct kunit *test)
537
556
char * ptr ;
538
557
size_t size = 128 - KASAN_GRANULE_SIZE ;
539
558
559
+ KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS (test );
560
+
540
561
ptr = kmalloc (size , GFP_KERNEL );
541
562
KUNIT_ASSERT_NOT_ERR_OR_NULL (test , ptr );
542
563
@@ -550,6 +571,8 @@ static void kmalloc_oob_in_memset(struct kunit *test)
550
571
char * ptr ;
551
572
size_t size = 128 - KASAN_GRANULE_SIZE ;
552
573
574
+ KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS (test );
575
+
553
576
ptr = kmalloc (size , GFP_KERNEL );
554
577
KUNIT_ASSERT_NOT_ERR_OR_NULL (test , ptr );
555
578
@@ -566,6 +589,8 @@ static void kmalloc_memmove_negative_size(struct kunit *test)
566
589
size_t size = 64 ;
567
590
size_t invalid_size = -2 ;
568
591
592
+ KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS (test );
593
+
569
594
/*
570
595
* Hardware tag-based mode doesn't check memmove for negative size.
571
596
* As a result, this test introduces a side-effect memory corruption,
@@ -590,6 +615,8 @@ static void kmalloc_memmove_invalid_size(struct kunit *test)
590
615
size_t size = 64 ;
591
616
size_t invalid_size = size ;
592
617
618
+ KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS (test );
619
+
593
620
ptr = kmalloc (size , GFP_KERNEL );
594
621
KUNIT_ASSERT_NOT_ERR_OR_NULL (test , ptr );
595
622
@@ -618,6 +645,8 @@ static void kmalloc_uaf_memset(struct kunit *test)
618
645
char * ptr ;
619
646
size_t size = 33 ;
620
647
648
+ KASAN_TEST_NEEDS_CHECKED_MEMINTRINSICS (test );
649
+
621
650
/*
622
651
* Only generic KASAN uses quarantine, which is required to avoid a
623
652
* kernel memory corruption this test causes.
0 commit comments