Commit a27e2e2d authored by Florent Revest's avatar Florent Revest Committed by Andrew Morton

kselftest: vm: fix mdwe's mmap_FIXED test case

I checked with the original author, the mmap_FIXED test case wasn't
properly tested and fails.  Currently, it maps two consecutive (non
overlapping) pages and expects the second mapping to be denied by MDWE but
these two pages have nothing to do with each other so MDWE is actually out
of the picture here.

What the test actually intended to do was to remap a virtual address using
MAP_FIXED.  However, this operation unmaps the existing mapping and
creates a new one so the va is backed by a new page and MDWE is again out
of the picture, all remappings should succeed.

This patch keeps the test case to make it clear that this situation is
expected to work: MDWE shouldn't block a MAP_FIXED replacement.

Link: https://lkml.kernel.org/r/20230828150858.393570-3-revest@chromium.org
Fixes: 4cf1fe34 ("kselftest: vm: add tests for memory-deny-write-execute")
Signed-off-by: default avatarFlorent Revest <revest@chromium.org>
Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Reviewed-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
Reviewed-by: default avatarRyan Roberts <ryan.roberts@arm.com>
Tested-by: default avatarRyan Roberts <ryan.roberts@arm.com>
Tested-by: default avatarAyush Jain <ayush.jain3@amd.com>
Cc: Alexey Izbyshev <izbyshev@ispras.ru>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Joey Gouly <joey.gouly@arm.com>
Cc: KP Singh <kpsingh@kernel.org>
Cc: Mark Brown <broonie@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Szabolcs Nagy <Szabolcs.Nagy@arm.com>
Cc: Topi Miettinen <toiwoton@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 29d68b21
...@@ -168,13 +168,10 @@ TEST_F(mdwe, mmap_FIXED) ...@@ -168,13 +168,10 @@ TEST_F(mdwe, mmap_FIXED)
self->p = mmap(NULL, self->size, PROT_READ, self->flags, 0, 0); self->p = mmap(NULL, self->size, PROT_READ, self->flags, 0, 0);
ASSERT_NE(self->p, MAP_FAILED); ASSERT_NE(self->p, MAP_FAILED);
p = mmap(self->p + self->size, self->size, PROT_READ | PROT_EXEC, /* MAP_FIXED unmaps the existing page before mapping which is allowed */
p = mmap(self->p, self->size, PROT_READ | PROT_EXEC,
self->flags | MAP_FIXED, 0, 0); self->flags | MAP_FIXED, 0, 0);
if (variant->enabled) { EXPECT_EQ(p, self->p);
EXPECT_EQ(p, MAP_FAILED);
} else {
EXPECT_EQ(p, self->p);
}
} }
TEST_F(mdwe, arm64_BTI) TEST_F(mdwe, arm64_BTI)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment