From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (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 4886036C0DA for ; Tue, 13 Jan 2026 09:12:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768295529; cv=none; b=gPOHXJk0uPDuoPYUjw+VKI/wFi3O9wx8G9vCXKmQBa9CgsGaHnOD70jdDUanlVW4EndTmdYaqn6z6Hder7FAztWQepULVsSX4uuaV9F4SCxFkmnQnAGmPzMxOJBcSNcnbduuuJ4Dk+LRA04FbVhWtoSHLiVQErfoiTiYz0UnFQo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768295529; c=relaxed/simple; bh=V9dypjtTawzOiIEUUDWF8Y9PkMpz+BKdC2mr+eik/0E=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=gP0mSUda54yapBMxSLOGoT9JNaxU6mztUUeWHNIjj+h7WJr/GiFmUNHRCj9XmEO4Lv2uwRBO7KRyEwpl1UqNjBxDEjgtYbZfVpViqCWJFAcDQVkrQkhFMKyXq/Gb4zezCK4lWuJMgYRZ85Z7w+TGeO0cxyB+dz69swPSzbSop0g= 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=i9lTcpWw; arc=none smtp.client-ip=209.85.221.74 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="i9lTcpWw" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-430ffa9fccaso5956366f8f.1 for ; Tue, 13 Jan 2026 01:12:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1768295521; x=1768900321; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=F46n0Clt9F/caqPQqDQW8qBOZa0FnmposgAtMZSYCf8=; b=i9lTcpWwxDytEZpaqrsU6q+bpyv8wEcCM4hDFbvQf+e0cvLGWW9zKv+Bo0MjATQJzL UrHZmXH8YNIzQsvYOwW4vSZzidD8D3QmVbjfzpF/zMBYAdBz5uA4LGrsX3WLRaWoFrOY FJI30fVmWJPHmw7OVeoTg2sogxtGJAdtnXYpPdYgsG+yTYGu1uJE/3PDDZxfeoBS3MrC WBzGejc/DRszgy1/3Ddo5tDZ9oAfNgPdSTgB2t3gIdgjkGkKCKc3NGmcrPazwZ+tngW9 CNOSq8hTlisJxaEs8dBTLz20HdVigkl/vaUFIKcBVBR8ek6cnariLTd4z+3z8GM4ngLI 7HKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768295521; x=1768900321; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=F46n0Clt9F/caqPQqDQW8qBOZa0FnmposgAtMZSYCf8=; b=LIqDeICSMLCbQrrh0YbB6nwdYFqzr2KitTGu2HRTg4zZSNlXQJv7XTeuEmnwyrqL92 ij12Jwm/4BlhVdfB15fAAeUYWZKqoQX346DiZTW7rNMyX3TVnyTBg9tBW/VQ3v/FYlos kGdfp1Va3L/uUa/nY3H5mbSkZ/PBU6gcB2zPn5paXucNpH5yga0nRb5mZNsA0Jf2c4tc pF5ohRdoWMKorSO/wIsIYaHet3aP1kZyPyiQwCeYRwOHO42VRPBq2d+7XQVi7rVI8p3T HV0dAmR2R2Snc6TCm0/+jV4A9O3xqtslh3hO3dqdzL0SVVvowTibq7AqTHIy2QbQ1UXx GXRQ== X-Forwarded-Encrypted: i=1; AJvYcCVMjbVAbEF5i/8ctJtvspbMxxm4EA1Jt/4HRemPJvNidjM8ZjtyShjsmgTYCnyoNryAfcpM5cjL1XC+uhw=@vger.kernel.org X-Gm-Message-State: AOJu0YxmAnS2S89hDCHMJ+5VZbeQW4lqLVkY/aLQWnKpdgluqHmTygmi Ehj3qOq26LCo0F789woujjNOuFKQwIfQ5wSg3uanuQFkwb1pRYxjtm/hyDTN2z+LNd/TfNmShRH ecBricw== X-Google-Smtp-Source: AGHT+IFvJvCQKlv/UjRYK3bRQMAojNzCZKDToTZHIs7CJTLzk396cU8VuHyU5F6Z4b3YJWtodTjzmRl+JJs= X-Received: from wrbgk6.prod.google.com ([2002:a05:6000:3106:b0:42f:c9b0:e5f4]) (user=glider job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:24c2:b0:431:c73:48a8 with SMTP id ffacd0b85a97d-432c37c8796mr25385140f8f.29.1768295520722; Tue, 13 Jan 2026 01:12:00 -0800 (PST) Date: Tue, 13 Jan 2026 10:11: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: <20260113091151.4035013-1-glider@google.com> Subject: [PATCH v2 1/2] 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-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 --- v2: factored out the common part of the two tests --- mm/kmsan/kmsan_test.c | 49 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c index 902ec48b1e3e6..ba44bf2072bbe 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,51 @@ static void test_uaf(struct kunit *test) KUNIT_EXPECT_TRUE(test, report_matches(&expect)); } +static volatile char *test_uaf_pages_helper(int order, int offset) +{ + struct page *page; + volatile char *var; + + /* Memory is initialized up until __free_pages() thanks to __GFP_ZERO. */ + page = alloc_pages(GFP_KERNEL | __GFP_ZERO, order); + var = page_address(page) + offset; + __free_pages(page, order); + + return var; +} + +/* Test case: ensure that use-after-free reporting works for a freed page. */ +static void test_uaf_pages(struct kunit *test) +{ + EXPECTATION_USE_AFTER_FREE(expect); + volatile char value; + + kunit_info(test, "use-after-free on a freed page (UMR report)\n"); + /* Allocate a single page, free it, then try to access it. */ + value = *test_uaf_pages_helper(0, 3); + USE(value); + + KUNIT_EXPECT_TRUE(test, report_matches(&expect)); +} + +/* Test case: ensure that UAF reporting works for high order pages. */ +static void test_uaf_high_order_pages(struct kunit *test) +{ + EXPECTATION_USE_AFTER_FREE(expect); + volatile char value; + + kunit_info(test, + "use-after-free on a freed high-order page (UMR report)\n"); + /* + * Create a high-order non-compound page, free it, then try to access + * its tail page. + */ + value = *test_uaf_pages_helper(1, PAGE_SIZE + 3); + USE(value); + + KUNIT_EXPECT_TRUE(test, report_matches(&expect)); +} + /* * Test case: ensure that uninitialized values are propagated through per-CPU * memory. @@ -683,6 +728,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), -- 2.52.0.457.g6b5491de43-goog