From patchwork Mon Nov 6 20:10:25 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: 13447464 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 637E4C001B2 for ; Mon, 6 Nov 2023 20:12:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C4FC76B02A4; Mon, 6 Nov 2023 15:12:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C05106B02A5; Mon, 6 Nov 2023 15:12:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A53A66B02A6; Mon, 6 Nov 2023 15:12:49 -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 9319F6B02A4 for ; Mon, 6 Nov 2023 15:12:49 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 74E77160893 for ; Mon, 6 Nov 2023 20:12:49 +0000 (UTC) X-FDA: 81428627658.08.8AFCA91 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) by imf16.hostedemail.com (Postfix) with ESMTP id 8E08718000F for ; Mon, 6 Nov 2023 20:12:47 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="UlmlCS1/"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf16.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.186 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=1699301567; 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=kJM+A7peUz+3HNFpMd2AaQcsySYXWlMk/hSPbyjpTN8=; b=doj5fc5SlsJWP+mT6cZZAb6e+T+9myaI+aUI9fjzsmuUkYSTvqevH8PJouHpICvaUYQo19 glhwKBdWGuia39ucwI9m7x05g3GYPHvOZalOCN18yh9zQuEsPq11/bFxXiVvPji2CcPJPc J7zzZrySNFqUu9zwis8SHBV4QD6wwzY= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="UlmlCS1/"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf16.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.186 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699301567; a=rsa-sha256; cv=none; b=K7O/EPEmZGI/uBUsOYuA6a6ySh1EQ38ggQ/NdOx+HzNcK3np/yn0CQoI5qmww5KGkb5yYn QuGenfaksXKM+JTxE9/LytQZhZyrdxM1PnYCdIZqA+ZhlwEgeWOYuu0TzM6uQpji44Y+yB YynmdZkl4DRIJQvKZZf7Hve5dm1g/SA= 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=1699301566; 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=kJM+A7peUz+3HNFpMd2AaQcsySYXWlMk/hSPbyjpTN8=; b=UlmlCS1/Z5dNByDcL6mE/0uoH62A1+s+Ul8OA7cSjRv8NsKOsAjlfXrZLnkR3VwZsnhqQm BCWlrEHz9Npwsl36SjkhbQgtrNkJApwPl+NiWrTyhnCPtmdiUaVoCUKg2oM4RE/0RN1Uw9 TCk2g0lBq9wUxkhNuVfEb1cqa6QfF3g= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH RFC 16/20] kasan: rename pagealloc tests Date: Mon, 6 Nov 2023 21:10:25 +0100 Message-Id: <0cf5eb3ea000a76c48554bbc80acb6135ebbb94a.1699297309.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 8E08718000F X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: y66hkzzihbe8uu3q6sf5bup31ixriwcx X-HE-Tag: 1699301567-172295 X-HE-Meta: U2FsdGVkX198RF+jpx2yAsuRx9HiBWDqm98f3fo/WelyvuPzvo0qYtGH5qsNnLW5yN/oeKuke46/x8Gx77Nlq3II1LC83IlYoDnXdm2fAQDsd1y8mFiCm1rY9iti1+qL9j5y7IEvTAudd6KR/hC/g4l2Q8JSqEoK95LQAEMYNj03eascR4//np21q7OU/JaNm+rQ+xmfSpHhBscStpaeBhdwFR8H+hTwfjHcxmiSO6mSA4kpB1PxIo/+rl7oejgfiaV5Zc4xoZwFM3OI6vgt5hQ5E61yCPdgSrBHhmsDmqCc3V/2/hD647je5BMM78QS3SsoA0/aRAM73taNOSmD0N46sdUYfqNXCge4RaRw2eTGfRZsMKOaMT7q1rYN9kcfCsZEIBWwwmN+wrGFUfHkBHNkaNiDSuc3HX5948XKioHkqXXYuothd4Sv0UrqfgfAJ6MfoIcEqyWYJ9kJdDqCiqcS6ARKGA3BRkmkT+OoqmGRVUFrDd4O5tzISsFTp0UqsTZi/swfO+GIidLFc0FyavDxoAe3t6cUFJc73Q5H4ZBe0e7/2Qw/lHCe+9BOAj6XUBtPD+kfTT3RZWTy0myoC5YwQgSx6rofirspIZ2rVa/2uo/sO5FcjtzT8GO9l8KaTnyw9nKpatSsY/mfHdzE+K3SmzHSPZAsAcV6iW/frh07TUeqIfUIZOzLwCdbc5hIAv1/IG5vpRf2+Nd5X6XqX2Lll+Ixou4A94iShf4fnFGRCpWsEAcbz5VohpcS1P0+lIjsCVrY25xfShlh3hBrercxMc/vQpWgukeeABEo6tBFxS4HVqRTIvyxeYbWNEh/KEvDZ67IQFN/qZJBOS4cNgEBEQ719hYcsb1whicKkGu+oXAM7PVrgM7BunkNZGin42GqEXUrH2mkGgp4biBVa9l4oBJRnEP9WVyIX8g57/RCxdZJ6G78SB9Z12+XTuYGp6nra9nFd9N+dbp5Non 88o1GwiJ 0/fokxDhKMzMHStS/mwy00PLU9rJW0VP7WbU5jKxxyV+9goCbfv8rtu9YoIfPrkf/1XsZPsKhoMeaaV9l5Zbde2VPeFOXMFgX25CcqMCIetRyqzwn48OZPoUZOSYeer/Bwc70G6rbrfC3sD8IohqnyZXWsumCaFhzHbW0SQiwuZ2YE14= 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 9adbcd04259b..4ea403653a39 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, @@ -1822,16 +1823,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),