From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4550C2EFD9E for ; Mon, 12 Jan 2026 15:18:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768231086; cv=none; b=FL/EH4lsHVxHXdUfTecM1oHUnrXIcAcNebcSIYisFkikKmfxBkLAK7jjNPnZChC5oL789yqKE4g9vH31ZCm8w3i7RE5wuRGLh6VamOggZPXsgL9PcdYz9aMPwtmuKe4Jdw/x+4v50jjB8HyT+6Z9k2XximN8+JrQ0TGSe5Ov1n8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768231086; c=relaxed/simple; bh=jUwTYKg1JBo5P3phyPgFlvKAlWDcdWMtflc5Swe4Q6E=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=HujU4s77kn8CKAVi871G/Wlgz0LNJjeAHfljiolB9FCLCo4qENlvVinBPKOER22+MlZu8+IT9G7Xs8Eqc/kR12Ao8Kr/SlGK1wVn33knIwDuEVzQ1UNu1rTrtZvZZuAGci15BIkatNlWf0/fl5LeqzZFE9RNg7jiTzOhxZ9yp/8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 877E7497; Mon, 12 Jan 2026 07:17:56 -0800 (PST) Received: from [10.57.95.123] (unknown [10.57.95.123]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2B6053F694; Mon, 12 Jan 2026 07:18:02 -0800 (PST) Message-ID: Date: Mon, 12 Jan 2026 15:18:00 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1] mm: kmsan: add tests for high-order page freeing Content-Language: en-GB To: Alexander Potapenko Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, elver@google.com, dvyukov@google.com, kasan-dev@googlegroups.com References: <20260112145150.3259084-1-glider@google.com> From: Ryan Roberts In-Reply-To: <20260112145150.3259084-1-glider@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 > --- > 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 > + > /* > * 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),