kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Interaction between host-side mprotect() and KVM MMU
@ 2019-05-21  7:24 Martin Lucina
  2019-05-21  8:14 ` Martin Lucina
  2019-05-21 14:02 ` Sean Christopherson
  0 siblings, 2 replies; 8+ messages in thread
From: Martin Lucina @ 2019-05-21  7:24 UTC (permalink / raw)
  To: kvm

Hi all,

as part of an effort to enforce W^X for the KVM backend of Solo5 [1], I'm
trying to understand how host-side mprotect() interacts with the KVM MMU.

Take a KVM guest on x86_64, where the guest runs exclusively in long mode,
in virtual ring 0, using 1:1 2MB pages in the guest, and all guest page
tables are RWX, i.e. no memory protection is enforced inside the guest
itself. EPT is enabled on the host.

Instead, our ELF loader applies a host-side mprotect(PROT_...) based on the
protection bits in the guest application (unikernel) ELF PHDRs.

The observed behaviour I see, from tests run inside the guest:

1. Attempting to WRITE to .text which has had mprotect(PROT_READ |
PROT_EXEC) applied on the host side results in a EFAULT from KVM_RUN in the
userspace tender (our equivalent of a VMM).

2. Attempting to EXECUTE code in .data which has had mprotect(PROT_READ |
PROT_WRITE) applied on the host side succeeds.

Questions:

a. Is this the intended behaviour, and can it be relied on? Note that
KVM/aarch64 behaves the same for me.

b. Why does case (1) fail but case (2) succeed? I spent a day reading
through the KVM MMU code, but failed to understand how this is implemented.

c. In order to enforce W^X both ways I'd like to have case (2) also fail
with EFAULT, is this possible?

Martin

[1] https://github.com/Solo5/solo5

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-06-06 11:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-21  7:24 Interaction between host-side mprotect() and KVM MMU Martin Lucina
2019-05-21  8:14 ` Martin Lucina
2019-05-21 14:02 ` Sean Christopherson
2019-05-23  9:27   ` Martin Lucina
2019-05-23 14:53     ` Sean Christopherson
2019-05-24 12:03       ` Martin Lucina
2019-05-24 19:26     ` Sean Christopherson
2019-06-06 11:52       ` Martin Lucina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).