From nobody Sat Feb 7 11:05:07 2026 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3580E18A6D4 for ; Mon, 12 Jan 2026 14:51:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768229517; cv=none; b=eeZoPib0GOfdfPt/2WVJJIdq/VxOvqu0UlxeKAoS3mbWFzJ3bivw1zs7FenLBV1pgMLcBeg4X3BA4kWPRXP+mgrCq1DiTXRruWM87ncSsO5NITBGhzkm38E0ReLmpzKth3O3LuzncuCGOqiqPxx+qd9DRDRMbxonwjGue4LStug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768229517; c=relaxed/simple; bh=hokOZKNZUu/7RS2tBC85vVjfjYIvNoe9pJu352hGIA4=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=VqDRtvrYGuFc2skjX53i4i3SUZ2hf4hUiU2v6xRQcm8DHayq3traUJKhNSYQqAHPrw2IOEIJUKRuIFbl+nbXDHfTU27IBtVFs1FpSkS7R/2Bpla5uqYP/bcqm2GJSIbWPDJLbmrbQL9z35EMkT3iJBDi98+dCchrcVW+hpag2mA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--glider.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YBgcNJps; arc=none smtp.client-ip=209.85.208.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--glider.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YBgcNJps" Received: by mail-ed1-f73.google.com with SMTP id 4fb4d7f45d1cf-6509ad48ac8so8787328a12.3 for ; Mon, 12 Jan 2026 06:51:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1768229514; x=1768834314; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=zb8lxCUKflLPJGxewVRt/oFLWki5YH9LqEd9Zx/sLAc=; b=YBgcNJpswHEoUaHeO4owWUdcdTV4V38+XYj3S0npObpdvuI+JtXgzIV9xucqU+IMp7 Cijm42RINLV5Q4+TfoiEDG/uuqv3g3GdtibPZaZaBc4xkSKorsL7Zb1W8t2DnMzaQQSl G1DK/rIRsaKWDYYrMdBRHQwpY99C7/B+qX8bIXPII22N4Go1KOCbCbwbVcGoRZ/etMzu 9pDZWaRABshgNX9a1prd69aS1rYWArCcwlU9+NHSGxM2w5BVphSkxkEtEvxbYLZXqwhf Q5yJe92vxWt4UtvDW6XuQK9XZCsWM6xTnIuffcNWpHuBIrQ2GqlNXiTfNp3ohBIUUk5s H9Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768229514; x=1768834314; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=zb8lxCUKflLPJGxewVRt/oFLWki5YH9LqEd9Zx/sLAc=; b=OS4kMtAgggojAE6Xe/zo8PikqWDFyaTJ8HJ8qqZwZEbuOo6i0b1A/ILPfi4y5swGuf dRaU7wDHh825dmGlfHxdcdgtcotzmC8oSkqHFzJUF9fzJo+II+gBtRsgsYFOu+k2FZmM CKYYpa6sx3PPO6MjXanzTpRK+XFjAhnM0GW1Kl8lhGZUILOWhdYwSlwUFwmerqLCsm1w mt+Fr+7HXeii6w1CYNODvxf9YZfozgWHmB6ZFQCj+uaPUVr1bx+gA9pLNx+bzW4ouLGN 8zy4bVQxrlekX9/Nayfd5vcHRG55rkZvx0Uya/T5Op0Z8BSIgilQii7hT+fh1swvtCPx rcCg== X-Forwarded-Encrypted: i=1; AJvYcCX0f/BY5yklL8O1erC8GIou6HZDBToFVG3sL5Cdp7FNXTAkkWMReT8old/zcYl5C0DDEwxiQjQjD/RglWs=@vger.kernel.org X-Gm-Message-State: AOJu0YwDu8Z8TF/o9XUwdN9SX2TYpe7kunIiqI1c04Cxh7KCEtryun3w 8tCcV+0K0TtoF52Ng0+MWFw3S21QARvKHHtKbGZhr5YqTfQWPIHGHcSxnAb9JYtacJR6wGfSAfQ gU1AfbA== X-Google-Smtp-Source: AGHT+IGvtmybmEn6Uoh/uHwnBdalPGDJ6a15O2TO1I8WItVDFvaFD3uns5oSaCtlbSDdK8/QzTt42R3jc2w= X-Received: from edbbq21.prod.google.com ([2002:a05:6402:2155:b0:641:6f6c:f930]) (user=glider job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:3fa3:b0:b87:253a:dd39 with SMTP id a640c23a62f3a-b87253ae4a3mr232543166b.26.1768229514739; Mon, 12 Jan 2026 06:51:54 -0800 (PST) Date: Mon, 12 Jan 2026 15:51:50 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260112145150.3259084-1-glider@google.com> Subject: [PATCH v1] mm: kmsan: add tests for high-order page freeing From: Alexander Potapenko To: glider@google.com Cc: akpm@linux-foundation.org, ryan.roberts@arm.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, elver@google.com, dvyukov@google.com, kasan-dev@googlegroups.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Ryan Roberts --- 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)); } =20 -/* 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)); } =20 +/* 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 =3D 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 =3D alloc_pages(GFP_KERNEL | __GFP_ZERO, order); + var =3D page_address(page); + __free_pages(page, order); + + /* Copy the invalid value before checking it. */ + value =3D 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 =3D 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 =3D alloc_pages(GFP_KERNEL | __GFP_ZERO, order); + var =3D page_address(page) + PAGE_SIZE; + __free_pages(page, order); + + /* Copy the invalid value before checking it. */ + value =3D var[3]; + USE(value); + KUNIT_EXPECT_TRUE(test, report_matches(&expect)); +} + /* * Test case: ensure that uninitialized values are propagated through per-= CPU * memory. @@ -683,6 +727,8 @@ static struct kunit_case kmsan_test_cases[] =3D { 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), --=20 2.52.0.457.g6b5491de43-goog