diff options
Diffstat (limited to 'lib/test_kasan.c')
| -rw-r--r-- | lib/test_kasan.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/test_kasan.c b/lib/test_kasan.c index fbdf87920093..0b1d3140fbb8 100644 --- a/lib/test_kasan.c +++ b/lib/test_kasan.c | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | #define pr_fmt(fmt) "kasan test: %s " fmt, __func__ | 12 | #define pr_fmt(fmt) "kasan test: %s " fmt, __func__ |
| 13 | 13 | ||
| 14 | #include <linux/delay.h> | ||
| 14 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
| 15 | #include <linux/mman.h> | 16 | #include <linux/mman.h> |
| 16 | #include <linux/mm.h> | 17 | #include <linux/mm.h> |
| @@ -331,6 +332,38 @@ static noinline void __init kmem_cache_oob(void) | |||
| 331 | kmem_cache_destroy(cache); | 332 | kmem_cache_destroy(cache); |
| 332 | } | 333 | } |
| 333 | 334 | ||
| 335 | static noinline void __init memcg_accounted_kmem_cache(void) | ||
| 336 | { | ||
| 337 | int i; | ||
| 338 | char *p; | ||
| 339 | size_t size = 200; | ||
| 340 | struct kmem_cache *cache; | ||
| 341 | |||
| 342 | cache = kmem_cache_create("test_cache", size, 0, SLAB_ACCOUNT, NULL); | ||
| 343 | if (!cache) { | ||
| 344 | pr_err("Cache allocation failed\n"); | ||
| 345 | return; | ||
| 346 | } | ||
| 347 | |||
| 348 | pr_info("allocate memcg accounted object\n"); | ||
| 349 | /* | ||
| 350 | * Several allocations with a delay to allow for lazy per memcg kmem | ||
| 351 | * cache creation. | ||
| 352 | */ | ||
| 353 | for (i = 0; i < 5; i++) { | ||
| 354 | p = kmem_cache_alloc(cache, GFP_KERNEL); | ||
| 355 | if (!p) { | ||
| 356 | pr_err("Allocation failed\n"); | ||
| 357 | goto free_cache; | ||
| 358 | } | ||
| 359 | kmem_cache_free(cache, p); | ||
| 360 | msleep(100); | ||
| 361 | } | ||
| 362 | |||
| 363 | free_cache: | ||
| 364 | kmem_cache_destroy(cache); | ||
| 365 | } | ||
| 366 | |||
| 334 | static char global_array[10]; | 367 | static char global_array[10]; |
| 335 | 368 | ||
| 336 | static noinline void __init kasan_global_oob(void) | 369 | static noinline void __init kasan_global_oob(void) |
| @@ -460,6 +493,7 @@ static int __init kmalloc_tests_init(void) | |||
| 460 | kmalloc_uaf_memset(); | 493 | kmalloc_uaf_memset(); |
| 461 | kmalloc_uaf2(); | 494 | kmalloc_uaf2(); |
| 462 | kmem_cache_oob(); | 495 | kmem_cache_oob(); |
| 496 | memcg_accounted_kmem_cache(); | ||
| 463 | kasan_stack_oob(); | 497 | kasan_stack_oob(); |
| 464 | kasan_global_oob(); | 498 | kasan_global_oob(); |
| 465 | ksize_unpoisons_memory(); | 499 | ksize_unpoisons_memory(); |
