Skip to content

Commit

Permalink
x86/pvm: Disable some unsupported syscalls and features
Browse files Browse the repository at this point in the history
n the PVM guest, the LDT won't be loaded into hardware, rendering it
ineffective. Consequently, the modify_ldt() syscall should be disabled.
Additionally, the VSYSCALL address is not within the allowed address
range, making full emulation of the vsyscall page unsupported in the PVM
guest. It is recommended to use XONLY mode instead. Furthermore,
SYSENTER (Intel) and SYSCALL32 (AMD) are not supported by the
hypervisor, so they should not be used in VDSO.

Suggested-by: Lai Jiangshan <[email protected]>
Signed-off-by: Hou Wenlong <[email protected]>
  • Loading branch information
bysui committed Feb 26, 2024
1 parent 34c183d commit ebec6f6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions arch/x86/entry/vsyscall/vsyscall_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ void __init map_vsyscall(void)
extern char __vsyscall_page;
unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);

/* Full emulation is not supported in PVM guest, use XONLY instead. */
if (vsyscall_mode == EMULATE && boot_cpu_has(X86_FEATURE_KVM_PVM_GUEST))
vsyscall_mode = XONLY;

/*
* For full emulation, the page needs to exist for real. In
* execute-only mode, there is no PTE at all backing the vsyscall
Expand Down
3 changes: 3 additions & 0 deletions arch/x86/kernel/ldt.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,9 @@ SYSCALL_DEFINE3(modify_ldt, int , func , void __user * , ptr ,
{
int ret = -ENOSYS;

if (cpu_feature_enabled(X86_FEATURE_KVM_PVM_GUEST))
return (unsigned int)ret;

switch (func) {
case 0:
ret = read_ldt(ptr, bytecount);
Expand Down
4 changes: 4 additions & 0 deletions arch/x86/kernel/pvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ void __init pvm_early_setup(void)
setup_force_cpu_cap(X86_FEATURE_KVM_PVM_GUEST);
setup_force_cpu_cap(X86_FEATURE_PV_GUEST);

/* Don't use SYSENTER (Intel) and SYSCALL32 (AMD) in vdso. */
setup_clear_cpu_cap(X86_FEATURE_SYSENTER32);
setup_clear_cpu_cap(X86_FEATURE_SYSCALL32);

/* PVM takes care of %gs when switching to usermode for us */
pv_ops.cpu.load_gs_index = pvm_load_gs_index;
pv_ops.cpu.cpuid = pvm_cpuid;
Expand Down

0 comments on commit ebec6f6

Please sign in to comment.