From patchwork Tue Dec 19 22:29:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13499311 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 214DFC41535 for ; Tue, 19 Dec 2023 22:31:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27BF98D0014; Tue, 19 Dec 2023 17:31:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 22DDB8D000D; Tue, 19 Dec 2023 17:31:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0A96B8D0014; Tue, 19 Dec 2023 17:31:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DC0968D000D for ; Tue, 19 Dec 2023 17:31:29 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BC995401B1 for ; Tue, 19 Dec 2023 22:31:29 +0000 (UTC) X-FDA: 81585015498.11.39D24A0 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) by imf04.hostedemail.com (Postfix) with ESMTP id E31FE40017 for ; Tue, 19 Dec 2023 22:31:27 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Iwn4kg+j; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf04.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.185 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703025088; a=rsa-sha256; cv=none; b=a2Ixo9mXeCt1gdMNFf8Lid7f1r2ChghbpsSrR11ZEH0mUdlkDpOrliCafdbmGp0tmtXIRQ nDmDSxhvvlJhpMVUwvkb0bj8jjdD0ItzGQ8hiVN/mfasLNTEeSLb3QWuQ92kuEOXFhFZyF 1NqDVcbEcdVCrEQ9tXAeZTce4aEEpgk= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Iwn4kg+j; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf04.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.185 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703025088; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vtcYZCAnAciS7NEDq4A0NBDaIMQC+9FU2xLXkQaUBC0=; b=paLMHCg2x6tP9To10O5Rt9I4Gb4hPItDTSlMZX0ma4A39g1yB5l1lNczLWyQTmpokl3E4g xHw4vSQvo63h64zHbC7VlRB04XJzBl9SxBtukrsCj1+Wjh7XzaFbTVzf4pjkUzktty7uc4 4ErLNIvJMsj7z3AIvbDv9NXkUP2S0is= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1703025086; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vtcYZCAnAciS7NEDq4A0NBDaIMQC+9FU2xLXkQaUBC0=; b=Iwn4kg+js3TZqTZyBEzr5jlkex5ITD9Q+U+eV8TWaTbadaxxhhpExvz32AObLkyzYsWKVo MEGpKSGLfb3aHTx+3wLZBhFQ6hI849in9n+2J9o44vahne4V4yCGCqK7fWLB18LfLjC7TQ S1SacVIxMXkVgZHMVh+q2zV1q3hj0X0= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Evgenii Stepanov , Breno Leitao , Alexander Lobakin , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 17/21] kasan: rename pagealloc tests Date: Tue, 19 Dec 2023 23:29:01 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E31FE40017 X-Stat-Signature: d9ruqiqqdme6hz3ot3uk5yyn5djtc681 X-HE-Tag: 1703025087-558957 X-HE-Meta: U2FsdGVkX18AeEn0U00zRKKb8GxI/UQkWjrd9e72wA2fh2o4j0t7AO9lfaE+9dL9dX/PjYf0zhMAr0ybvkBm+77tKf1+JjKFk9WSVRPzE9hXGAtZnNPGH5ijs23YWZUIaLlfEy3xH5NvWVeeo4KTD7CYnTf3jmNwimB1WBQiFKe4/F8PO2DeKvr554nRkPq7KSlR3FCOufXGGgANowwYyTWYIqlk5bQI9s96oW4uSPuzJk1BmGZiVJKW2nbD39BHgVtJdmckTkVnWc4W/a5Ei1LSeJ4RA1QTMBsCJCGrbThXEJSpnqkCC5aeTRC1wM3TkY8yOdjDr7nNAAj21uRj/Q4FrDfnVZ8ntDM919w4fIpZDiLewt0dB26ZarEVnzcvDhGOVElRELBniP03IqhUk3FQ7l3QSI6HkxJyNZALlfCxiv9FKGWj6LmJqHyEs5IKOwkSz0rrWYbQvX5vqXcj/dXmzbvjoJMXjCP5Qb3b6DP+a2CJjcJ6Z+YbmGeH2sKL6aeMQn8e/9IY+PIv80ymXCU3XRIUXvKu9wEDWo3rgUnIo0PoVsnJhpLD0SD3oLuUGMbMS7M34vAlM7Mtf8uw3MaL/65u0wE7NAAGs0khd/H1t5713DS6J/WsPa/UBMidrYzPJQPNwxNAslsgr4flKqHt9L2VjkOMlN4YBgxhB2CYHNanpqjfAvKs6oZsiMb+yffRHD8hyK3IPa9jI6wqWobIS+CMxG+tRpv5x7CtMnAhZ9cafjU/ZQbKiG6vTiFkoMyqUTpERICyFs2HtaCBHmRYqFc9+wbOnd4esNPWKbHoZT9oyINlClT1Fd6BJPhYcPJlgVp+GCH5AgTTcY5IzTkf3Y7fIlg4gx8ljLg3e0pDZ1IsSG9k5Tack/N73FkNeEsbvlgBVZGUNL4DJWbbGrKCyAsr7+phPCKFysaRU7MuizeAhmtzQxrVWjGRpPCYfFz1IB8EAHxlsoOk6ec ML6cOE+Q Fr8lSmm1UEIP1F0YLS7x2Q0Z07r+f9q0Gn8pees8K1P9dzBJhQWSid6tk9txdnLa8OxUwDEN2+pYqtdQHbeC+WzTe2E3tZ29GttTf65ID+6BgU7HMs7ac6Y6ayi9l8BOAcp6j6X0pTvQ7W6QbKr0VpWUZXX+L4FuKM2i4 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Andrey Konovalov Rename "pagealloc" KASAN tests: 1. Use "kmalloc_large" for tests that use large kmalloc allocations. 2. Use "page_alloc" for tests that use page_alloc. Also clean up the comments. Signed-off-by: Andrey Konovalov --- mm/kasan/kasan_test.c | 51 ++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/mm/kasan/kasan_test.c b/mm/kasan/kasan_test.c index 0ae4e93e9311..230958de7604 100644 --- a/mm/kasan/kasan_test.c +++ b/mm/kasan/kasan_test.c @@ -214,12 +214,13 @@ static void kmalloc_node_oob_right(struct kunit *test) } /* - * These kmalloc_pagealloc_* tests try allocating a memory chunk that doesn't - * fit into a slab cache and therefore is allocated via the page allocator - * fallback. Since this kind of fallback is only implemented for SLUB, these - * tests are limited to that allocator. + * The kmalloc_large_* tests below use kmalloc() to allocate a memory chunk + * that does not fit into the largest slab cache and therefore is allocated via + * the page_alloc fallback for SLUB. SLAB has no such fallback, and thus these + * tests are not supported for it. */ -static void kmalloc_pagealloc_oob_right(struct kunit *test) + +static void kmalloc_large_oob_right(struct kunit *test) { char *ptr; size_t size = KMALLOC_MAX_CACHE_SIZE + 10; @@ -235,7 +236,7 @@ static void kmalloc_pagealloc_oob_right(struct kunit *test) kfree(ptr); } -static void kmalloc_pagealloc_uaf(struct kunit *test) +static void kmalloc_large_uaf(struct kunit *test) { char *ptr; size_t size = KMALLOC_MAX_CACHE_SIZE + 10; @@ -249,7 +250,7 @@ static void kmalloc_pagealloc_uaf(struct kunit *test) KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[0]); } -static void kmalloc_pagealloc_invalid_free(struct kunit *test) +static void kmalloc_large_invalid_free(struct kunit *test) { char *ptr; size_t size = KMALLOC_MAX_CACHE_SIZE + 10; @@ -262,7 +263,7 @@ static void kmalloc_pagealloc_invalid_free(struct kunit *test) KUNIT_EXPECT_KASAN_FAIL(test, kfree(ptr + 1)); } -static void pagealloc_oob_right(struct kunit *test) +static void page_alloc_oob_right(struct kunit *test) { char *ptr; struct page *pages; @@ -284,7 +285,7 @@ static void pagealloc_oob_right(struct kunit *test) free_pages((unsigned long)ptr, order); } -static void pagealloc_uaf(struct kunit *test) +static void page_alloc_uaf(struct kunit *test) { char *ptr; struct page *pages; @@ -298,15 +299,15 @@ static void pagealloc_uaf(struct kunit *test) KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[0]); } -static void kmalloc_large_oob_right(struct kunit *test) +/* + * Check that KASAN detects an out-of-bounds access for a big object allocated + * via kmalloc(). But not as big as to trigger the page_alloc fallback for SLUB. + */ +static void kmalloc_big_oob_right(struct kunit *test) { char *ptr; size_t size = KMALLOC_MAX_CACHE_SIZE - 256; - /* - * Allocate a chunk that is large enough, but still fits into a slab - * and does not trigger the page allocator fallback in SLUB. - */ ptr = kmalloc(size, GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); @@ -404,18 +405,18 @@ static void krealloc_less_oob(struct kunit *test) krealloc_less_oob_helper(test, 235, 201); } -static void krealloc_pagealloc_more_oob(struct kunit *test) +static void krealloc_large_more_oob(struct kunit *test) { - /* page_alloc fallback in only implemented for SLUB. */ + /* page_alloc fallback is only implemented for SLUB. */ KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); krealloc_more_oob_helper(test, KMALLOC_MAX_CACHE_SIZE + 201, KMALLOC_MAX_CACHE_SIZE + 235); } -static void krealloc_pagealloc_less_oob(struct kunit *test) +static void krealloc_large_less_oob(struct kunit *test) { - /* page_alloc fallback in only implemented for SLUB. */ + /* page_alloc fallback is only implemented for SLUB. */ KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); krealloc_less_oob_helper(test, KMALLOC_MAX_CACHE_SIZE + 235, @@ -1816,16 +1817,16 @@ static struct kunit_case kasan_kunit_test_cases[] = { KUNIT_CASE(kmalloc_oob_right), KUNIT_CASE(kmalloc_oob_left), KUNIT_CASE(kmalloc_node_oob_right), - KUNIT_CASE(kmalloc_pagealloc_oob_right), - KUNIT_CASE(kmalloc_pagealloc_uaf), - KUNIT_CASE(kmalloc_pagealloc_invalid_free), - KUNIT_CASE(pagealloc_oob_right), - KUNIT_CASE(pagealloc_uaf), KUNIT_CASE(kmalloc_large_oob_right), + KUNIT_CASE(kmalloc_large_uaf), + KUNIT_CASE(kmalloc_large_invalid_free), + KUNIT_CASE(page_alloc_oob_right), + KUNIT_CASE(page_alloc_uaf), + KUNIT_CASE(kmalloc_big_oob_right), KUNIT_CASE(krealloc_more_oob), KUNIT_CASE(krealloc_less_oob), - KUNIT_CASE(krealloc_pagealloc_more_oob), - KUNIT_CASE(krealloc_pagealloc_less_oob), + KUNIT_CASE(krealloc_large_more_oob), + KUNIT_CASE(krealloc_large_less_oob), KUNIT_CASE(krealloc_uaf), KUNIT_CASE(kmalloc_oob_16), KUNIT_CASE(kmalloc_uaf_16),