Skip to content

Commit 70effdc

Browse files
xairytorvalds
authored andcommitted
kasan: test: prevent cache merging in kmem_cache_double_destroy
With HW_TAGS KASAN and kasan.stacktrace=off, the cache created in the kmem_cache_double_destroy() test might get merged with an existing one. Thus, the first kmem_cache_destroy() call won't actually destroy it but will only decrease the refcount. This causes the test to fail. Provide an empty constructor for the created cache to prevent the cache from getting merged. Link: https://lkml.kernel.org/r/b597bd434c49591d8af00ee3993a42c609dc9a59.1644346040.git.andreyknvl@google.com Fixes: f98f966 ("kasan: test: add test case for double-kmem_cache_destroy()") Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Reviewed-by: Marco Elver <elver@google.com> Cc: Alexander Potapenko <glider@google.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent db110a9 commit 70effdc

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

lib/test_kasan.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,11 +869,14 @@ static void kmem_cache_invalid_free(struct kunit *test)
869869
kmem_cache_destroy(cache);
870870
}
871871

872+
static void empty_cache_ctor(void *object) { }
873+
872874
static void kmem_cache_double_destroy(struct kunit *test)
873875
{
874876
struct kmem_cache *cache;
875877

876-
cache = kmem_cache_create("test_cache", 200, 0, 0, NULL);
878+
/* Provide a constructor to prevent cache merging. */
879+
cache = kmem_cache_create("test_cache", 200, 0, 0, empty_cache_ctor);
877880
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache);
878881
kmem_cache_destroy(cache);
879882
KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_destroy(cache));

0 commit comments

Comments
 (0)