x86/pat: Fix W^X violation false-positives when running as Xen PV guest
authorJuergen Gross <jgross@suse.com>
Fri, 12 Apr 2024 15:12:58 +0000 (17:12 +0200)
committerIngo Molnar <mingo@kernel.org>
Sun, 14 Apr 2024 20:16:30 +0000 (22:16 +0200)
commit5bc8b0f5dac04cd4ebe47f8090a5942f2f2647ef
tree6c835aad11695962260a271f03a9979cab3201cf
parent02eac06b820c3eae73e5736ae62f986d37fed991
x86/pat: Fix W^X violation false-positives when running as Xen PV guest

When running as Xen PV guest in some cases W^X violation WARN()s have
been observed. Those WARN()s are produced by verify_rwx(), which looks
into the PTE to verify that writable kernel pages have the NX bit set
in order to avoid code modifications of the kernel by rogue code.

As the NX bits of all levels of translation entries are or-ed and the
RW bits of all levels are and-ed, looking just into the PTE isn't enough
for the decision that a writable page is executable, too.

When running as a Xen PV guest, the direct map PMDs and kernel high
map PMDs share the same set of PTEs. Xen kernel initialization will set
the NX bit in the direct map PMD entries, and not the shared PTEs.

Fixes: 652c5bf380ad ("x86/mm: Refuse W^X violations")
Reported-by: Jason Andryuk <jandryuk@gmail.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20240412151258.9171-5-jgross@suse.com
arch/x86/mm/pat/set_memory.c