@@ -523,6 +523,54 @@ static noinline void __init kasan_alloca_oob_right(void)
523
523
* (volatile char * )p ;
524
524
}
525
525
526
+ static noinline void __init kmem_cache_double_free (void )
527
+ {
528
+ char * p ;
529
+ size_t size = 200 ;
530
+ struct kmem_cache * cache ;
531
+
532
+ cache = kmem_cache_create ("test_cache" , size , 0 , 0 , NULL );
533
+ if (!cache ) {
534
+ pr_err ("Cache allocation failed\n" );
535
+ return ;
536
+ }
537
+ pr_info ("double-free on heap object\n" );
538
+ p = kmem_cache_alloc (cache , GFP_KERNEL );
539
+ if (!p ) {
540
+ pr_err ("Allocation failed\n" );
541
+ kmem_cache_destroy (cache );
542
+ return ;
543
+ }
544
+
545
+ kmem_cache_free (cache , p );
546
+ kmem_cache_free (cache , p );
547
+ kmem_cache_destroy (cache );
548
+ }
549
+
550
+ static noinline void __init kmem_cache_invalid_free (void )
551
+ {
552
+ char * p ;
553
+ size_t size = 200 ;
554
+ struct kmem_cache * cache ;
555
+
556
+ cache = kmem_cache_create ("test_cache" , size , 0 , SLAB_TYPESAFE_BY_RCU ,
557
+ NULL );
558
+ if (!cache ) {
559
+ pr_err ("Cache allocation failed\n" );
560
+ return ;
561
+ }
562
+ pr_info ("invalid-free of heap object\n" );
563
+ p = kmem_cache_alloc (cache , GFP_KERNEL );
564
+ if (!p ) {
565
+ pr_err ("Allocation failed\n" );
566
+ kmem_cache_destroy (cache );
567
+ return ;
568
+ }
569
+
570
+ kmem_cache_free (cache , p + 1 );
571
+ kmem_cache_destroy (cache );
572
+ }
573
+
526
574
static int __init kmalloc_tests_init (void )
527
575
{
528
576
/*
@@ -560,6 +608,8 @@ static int __init kmalloc_tests_init(void)
560
608
ksize_unpoisons_memory ();
561
609
copy_user_test ();
562
610
use_after_scope_test ();
611
+ kmem_cache_double_free ();
612
+ kmem_cache_invalid_free ();
563
613
564
614
kasan_restore_multi_shot (multishot );
565
615
0 commit comments