Commit f98f966c authored by Marco Elver's avatar Marco Elver Committed by Linus Torvalds

kasan: test: add test case for double-kmem_cache_destroy()

Add a test case for double-kmem_cache_destroy() detection.

Link: https://lkml.kernel.org/r/20211119142219.1519617-2-elver@google.comSigned-off-by: default avatarMarco Elver <elver@google.com>
Reviewed-by: default avatarAndrey Konovalov <andreyknvl@gmail.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent bed0a9b5
...@@ -866,6 +866,16 @@ static void kmem_cache_invalid_free(struct kunit *test) ...@@ -866,6 +866,16 @@ static void kmem_cache_invalid_free(struct kunit *test)
kmem_cache_destroy(cache); kmem_cache_destroy(cache);
} }
static void kmem_cache_double_destroy(struct kunit *test)
{
struct kmem_cache *cache;
cache = kmem_cache_create("test_cache", 200, 0, 0, NULL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache);
kmem_cache_destroy(cache);
KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_destroy(cache));
}
static void kasan_memchr(struct kunit *test) static void kasan_memchr(struct kunit *test)
{ {
char *ptr; char *ptr;
...@@ -1185,6 +1195,7 @@ static struct kunit_case kasan_kunit_test_cases[] = { ...@@ -1185,6 +1195,7 @@ static struct kunit_case kasan_kunit_test_cases[] = {
KUNIT_CASE(ksize_uaf), KUNIT_CASE(ksize_uaf),
KUNIT_CASE(kmem_cache_double_free), KUNIT_CASE(kmem_cache_double_free),
KUNIT_CASE(kmem_cache_invalid_free), KUNIT_CASE(kmem_cache_invalid_free),
KUNIT_CASE(kmem_cache_double_destroy),
KUNIT_CASE(kasan_memchr), KUNIT_CASE(kasan_memchr),
KUNIT_CASE(kasan_memcmp), KUNIT_CASE(kasan_memcmp),
KUNIT_CASE(kasan_strings), KUNIT_CASE(kasan_strings),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment