From: Ryan Roberts <ryan.roberts@arm.com>
To: Alexander Potapenko <glider@google.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, elver@google.com,
dvyukov@google.com, kasan-dev@googlegroups.com
Subject: Re: [PATCH v1] mm: kmsan: add tests for high-order page freeing
Date: Mon, 12 Jan 2026 15:18:00 +0000 [thread overview]
Message-ID: <aa38c43c-0907-4b49-8e76-a2ade35089cd@arm.com> (raw)
In-Reply-To: <20260112145150.3259084-1-glider@google.com>
On 12/01/2026 14:51, Alexander Potapenko wrote:
> Add regression tests to verify that KMSAN correctly poisons the full memory
> range when freeing pages.
>
> Specifically, verify that accessing the tail pages of a high-order
> non-compound allocation triggers a use-after-free report. This ensures
> that the fix "mm: kmsan: Fix poisoning of high-order non-compound pages"
> is working as expected.
>
> Also add a test for standard order-0 pages for completeness.
>
> Link: https://lore.kernel.org/all/20260104134348.3544298-1-ryan.roberts@arm.com/
> Signed-off-by: Alexander Potapenko <glider@google.com>
> ---
> mm/kmsan/kmsan_test.c | 48 ++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 47 insertions(+), 1 deletion(-)
>
> diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c
> index 902ec48b1e3e6..25cfba0db2cfb 100644
> --- a/mm/kmsan/kmsan_test.c
> +++ b/mm/kmsan/kmsan_test.c
> @@ -361,7 +361,7 @@ static void test_init_vmalloc(struct kunit *test)
> KUNIT_EXPECT_TRUE(test, report_matches(&expect));
> }
>
> -/* Test case: ensure that use-after-free reporting works. */
> +/* Test case: ensure that use-after-free reporting works for kmalloc. */
> static void test_uaf(struct kunit *test)
> {
> EXPECTATION_USE_AFTER_FREE(expect);
> @@ -378,6 +378,50 @@ static void test_uaf(struct kunit *test)
> KUNIT_EXPECT_TRUE(test, report_matches(&expect));
> }
>
> +/* Test case: ensure that use-after-free reporting works for freed pages. */
> +static void test_uaf_pages(struct kunit *test)
> +{
> + EXPECTATION_USE_AFTER_FREE(expect);
> + const int order = 0;
> + volatile char value;
> + struct page *page;
> + volatile char *var;
> +
> + kunit_info(test, "use-after-free on a freed page (UMR report)\n");
> +
> + /* Memory is initialized up until __free_pages() thanks to __GFP_ZERO. */
> + page = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
> + var = page_address(page);
> + __free_pages(page, order);
> +
> + /* Copy the invalid value before checking it. */
> + value = var[3];
> + USE(value);
> + KUNIT_EXPECT_TRUE(test, report_matches(&expect));
> +}
> +
> +/* Test case: ensure that use-after-free reporting works for alloc_pages. */
> +static void test_uaf_high_order_pages(struct kunit *test)
> +{
> + EXPECTATION_USE_AFTER_FREE(expect);
> + const int order = 1;
> + volatile char value;
> + struct page *page;
> + volatile char *var;
> +
> + kunit_info(test,
> + "use-after-free on a freed high-order page (UMR report)\n");
> +
> + page = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
> + var = page_address(page) + PAGE_SIZE;
> + __free_pages(page, order);
> +
> + /* Copy the invalid value before checking it. */
> + value = var[3];
> + USE(value);
> + KUNIT_EXPECT_TRUE(test, report_matches(&expect));
> +}
test_uaf_pages() and test_uaf_high_order_pages() are the same except for the
value of order. Does it make sense to create a single parameterized helper that
gets called from the 2 tests wrappers?
Functionally looks correct though, so either way, feel free to add:
Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>
> +
> /*
> * Test case: ensure that uninitialized values are propagated through per-CPU
> * memory.
> @@ -683,6 +727,8 @@ static struct kunit_case kmsan_test_cases[] = {
> KUNIT_CASE(test_init_kmsan_vmap_vunmap),
> KUNIT_CASE(test_init_vmalloc),
> KUNIT_CASE(test_uaf),
> + KUNIT_CASE(test_uaf_pages),
> + KUNIT_CASE(test_uaf_high_order_pages),
> KUNIT_CASE(test_percpu_propagate),
> KUNIT_CASE(test_printk),
> KUNIT_CASE(test_init_memcpy),
prev parent reply other threads:[~2026-01-12 15:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-12 14:51 Alexander Potapenko
2026-01-12 15:18 ` Ryan Roberts [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aa38c43c-0907-4b49-8e76-a2ade35089cd@arm.com \
--to=ryan.roberts@arm.com \
--cc=akpm@linux-foundation.org \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®