Interaction between host-side mprotect() and KVM MMU

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux