Skip to content

Commit

Permalink
kselftest: vm: fix mdwe's mmap_FIXED test case
Browse files Browse the repository at this point in the history
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/[email protected]
Fixes: 4cf1fe3 ("kselftest: vm: add tests for memory-deny-write-execute")
Signed-off-by: Florent Revest <[email protected]>
Reviewed-by: David Hildenbrand <[email protected]>
Reviewed-by: Kees Cook <[email protected]>
Reviewed-by: Catalin Marinas <[email protected]>
Reviewed-by: Ryan Roberts <[email protected]>
Tested-by: Ryan Roberts <[email protected]>
Tested-by: Ayush Jain <[email protected]>
Cc: Alexey Izbyshev <[email protected]>
Cc: Anshuman Khandual <[email protected]>
Cc: Greg Thelen <[email protected]>
Cc: Joey Gouly <[email protected]>
Cc: KP Singh <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Peter Xu <[email protected]>
Cc: Szabolcs Nagy <[email protected]>
Cc: Topi Miettinen <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
FlorentRevest authored and akpm00 committed Oct 6, 2023
1 parent 29d68b2 commit a27e2e2
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions tools/testing/selftests/mm/mdwe_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,10 @@ TEST_F(mdwe, mmap_FIXED)
self->p = mmap(NULL, self->size, PROT_READ, self->flags, 0, 0);
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);
if (variant->enabled) {
EXPECT_EQ(p, MAP_FAILED);
} else {
EXPECT_EQ(p, self->p);
}
EXPECT_EQ(p, self->p);
}

TEST_F(mdwe, arm64_BTI)
Expand Down

0 comments on commit a27e2e2

Please sign in to comment.