Enable SMEP CPU Feature
Subsystems (2)
v2 cover Enable SMEP CPU Feature
From: Fenghua Yu <[email protected]>
Intel new CPU supports SMEP (Supervisor Mode Execution Protection). SMEP prevents kernel from executing code in application. Updated Intel SDM describes this CPU feature. The document will be published soon.
Note: This patch set doesn't enable the SMEP feature in KVM. If it's needed, another patch will be pushed for enabling the feature in KVM.
Fenghua Yu (4):
x86, cpu: Add CPU flags for SMEP
x86, cpu: Add SMEP CPU feature in CR4
x86, head_32/64.S: Enable SMEP x86/kernel/common.c: Disable SMEP by kernel option nosmep
Documentation/kernel-parameters.txt | 4 ++++ arch/x86/include/asm/cpufeature.h | 1 + arch/x86/include/asm/processor-flags.h | 1 + arch/x86/kernel/cpu/common.c | 22 ++++++++++++++++++++++ arch/x86/kernel/cpu/scattered.c | 1 + arch/x86/kernel/head_32.S | 17 +++++++++++++---- arch/x86/kernel/head_64.S | 13 +++++++++++-- 7 files changed, 53 insertions(+), 6 deletions(-)
Signature · 1 line
1.7.2
PATCH v2 1/4 x86, cpu: Add CPU flags for SMEP
From: Fenghua Yu <[email protected]>
Add support for newly documented SMEP (Supervisor Mode Execution Protection) CPU feature flags.
--- arch/x86/include/asm/cpufeature.h | 1 + arch/x86/kernel/cpu/scattered.c | 1 + 2 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/include/asm/cpufeature.h +1 -0
@@ -174,6 +174,7 @@#define X86_FEATURE_PLN (7*32+ 5)/* Intel Power Limit Notification */ #define X86_FEATURE_PTS (7*32+ 6)/* Intel Package Thermal Status */ #define X86_FEATURE_DTS (7*32+ 7)/* Digital Thermal Sensor */ +#define X86_FEATURE_SMEP (7*32+ 8)/* Supervisor Mode Execution Protection*/ /* Virtualization flags: Linux defined, word 8 */ #define X86_FEATURE_TPR_SHADOW (8*32+ 0)/* Intel TPR Shadow */
arch/x86/kernel/cpu/scattered.c +1 -0
@@ -38,6 +38,7 @@ void __cpuinit init_scattered_cpuid_features(struct cpuinfo_x86 *c) { X86_FEATURE_PTS, CR_EAX, 6, 0x00000006, 0 }, { X86_FEATURE_APERFMPERF, CR_ECX, 0, 0x00000006, 0 }, { X86_FEATURE_EPB, CR_ECX, 3, 0x00000006, 0 }, + { X86_FEATURE_SMEP, CR_EBX, 7, 0x00000007, 0 }, { X86_FEATURE_XSAVEOPT, CR_EAX, 0, 0x0000000d, 1 }, { X86_FEATURE_CPB, CR_EDX, 9, 0x80000007, 0 }, { X86_FEATURE_NPT, CR_EDX, 0, 0x8000000a, 0 },
Signature · 1 line
1.7.2
H. Peter Anvin
reviewerRe: [PATCH v2 1/4] x86, cpu: Add CPU flags for SMEP
Quoted 28 lines · Fenghua Yu
From: Fenghua Yu <[email protected]>
Add support for newly documented SMEP (Supervisor Mode Execution Protection) CPU feature flags.
Signed-off-by Fenghua Yu <[email protected]>--- arch/x86/include/asm/cpufeature.h | 1 + arch/x86/kernel/cpu/scattered.c | 1 + 2 files changed, 2 insertions(+), 0 deletions(-)arch/x86/include/asm/cpufeature.h +1
-0@@ -174,6 +174,7 @@#define X86_FEATURE_PLN (7*32+ 5)/* Intel Power Limit Notification */ #define X86_FEATURE_PTS (7*32+ 6)/* Intel Package Thermal Status */ #define X86_FEATURE_DTS (7*32+ 7)/* Digital Thermal Sensor */ +#define X86_FEATURE_SMEP (7*32+ 8)/* Supervisor Mode Execution Protection*/ /* Virtualization flags: Linux defined, word 8 */ #define X86_FEATURE_TPR_SHADOW (8*32+ 0)/* Intel TPR Shadow */ arch/x86/kernel/cpu/scattered.c +0
-0
arch/x86/kernel/cpu/scattered.c void __cpuinit init_scattered_cpuid_features(struct cpuinfo_x86 *c) · line 44
Quoted 7 lines
arch/x86/kernel/cpu/scattered.c +1
-0@@ -38,6 +38,7 @@ void __cpuinit init_scattered_cpuid_features(struct cpuinfo_x86 *c) { X86_FEATURE_PTS, CR_EAX, 6, 0x00000006, 0 }, { X86_FEATURE_APERFMPERF, CR_ECX, 0, 0x00000006, 0 }, { X86_FEATURE_EPB, CR_ECX, 3, 0x00000006, 0 }, + { X86_FEATURE_SMEP, CR_EBX, 7, 0x00000007, 0 }, { X86_FEATURE_XSAVEOPT, CR_EAX, 0, 0x0000000d, 1 }, { X86_FEATURE_CPB, CR_EDX, 9, 0x80000007, 0 }, { X86_FEATURE_NPT, CR_EDX, 0, 0x8000000a, 0 },
The level 7 flags are not considered "scattered"; they have their own word; please use it.
-hpa
Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.
PATCH v2 2/4 x86, cpu: Add SMEP CPU feature in CR4
In reply to Fenghua YuFrom: Fenghua Yu <[email protected]>
Add support for newly documented SMEP (Supervisor Mode Execution Protection) CPU feature in CR4.
--- arch/x86/include/asm/processor-flags.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/include/asm/processor-flags.h +1 -0
@@ -60,6 +60,7 @@#define X86_CR4_OSXMMEXCPT 0x00000400/* enable unmasked SSE exceptions */ #define X86_CR4_VMXE 0x00002000/* enable VMX virtualization */ #define X86_CR4_OSXSAVE 0x00040000/* enable xsave and xrestore */ +#define X86_CR4_SMEP 0x00100000/* enable SMEP support */ /* * x86-64 Task Priority Register, CR8
Signature · 1 line
1.7.2
PATCH v2 3/4 x86, head_32/64.S: Enable SMEP
In reply to Fenghua YuFrom: Fenghua Yu <[email protected]>
Enable newly documented SMEP (Supervisor Mode Execution Protection) CPU feature in kernel.
SMEP prevents the CPU in kernel-mode to jump to an executable page that does not have the kernel/system flag set in the pte. This prevents the kernel from executing user-space code accidentally or maliciously, so it for example prevents kernel exploits from jumping to specially prepared user-mode shell code. The violation will cause page fault #PF and will have error code identical to XD violation.
CR4.SMEP (bit 20) is 0 at power-on. If the feature is supported by CPU (X86_FEATURE_SMEP), enable SMEP by setting CR4.SMEP. New kernel option nosmep disables the feature even if the feature is supported by CPU.
--- arch/x86/kernel/head_32.S | 17 +++++++++++++---- arch/x86/kernel/head_64.S | 13 +++++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-)
arch/x86/kernel/head_32.S +13 -4
@@ -308,11 +308,20 @@ default_entry: movl cr4_bits,%edx andl %edx,%edx jz 6f - movl %cr4,%eax # Turn on paging options (PSE,PAE,..) - orl %edx,%eax - movl %eax,%cr4 + movl %cr4,%edi # Turn on paging options (PSE,PAE,..) + orl %edx,%edi - testb $X86_CR4_PAE, %al # check if PAE is enabled + /* Check if SMEP is supported by the processor */ + movl $0x7, %eax + movl $0, %ecx + cpuid + btl $7, %ebx + jnc 1f + /* Enable SMEP */ + orl $(X86_CR4_SMEP), %edi +1: movl %edi, %cr4 + + test $X86_CR4_PAE, %di # check if PAE is enabled jz 6f /* Check if extended functions are implemented */
arch/x86/kernel/head_64.S +11 -2
@@ -161,8 +161,17 @@ ENTRY(secondary_startup_64) */ /* Enable PAE mode and PGE */ - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax - movq %rax, %cr4 + movl $(X86_CR4_PAE | X86_CR4_PGE), %edi + + /* Check if SMEP is supported by the processor */ + movl $0x7, %eax + movl $0, %ecx + cpuid + btl $7, %ebx + jnc 1f + /* Enable PAE mode, PGE, and SMEP */ + movl $(X86_CR4_PAE | X86_CR4_PGE | X86_CR4_SMEP), %edi +1: movq %rdi, %cr4 /* Setup early boot stage 4 level pagetables. */ movq $(init_level4_pgt - __START_KERNEL_map), %rax
Signature · 1 line
1.7.2
Re: [PATCH v2 3/4] x86, head_32/64.S: Enable SMEP
Quoted 11 lines · Fenghua Yu
From: Fenghua Yu <[email protected]>
Enable newly documented SMEP (Supervisor Mode Execution Protection) CPU feature in kernel.
SMEP prevents the CPU in kernel-mode to jump to an executable page that does not have the kernel/system flag set in the pte. This prevents the kernel from executing user-space code accidentally or maliciously, so it for example prevents kernel exploits from jumping to specially prepared user-mode shell code. The violation will cause page fault #PF and will have error code identical to XD violation.
Are EFI runtime service pages currently set up appropriately?
Signature · 1 line
Matthew Garrett | [email protected]
RE: [PATCH v2 3/4] x86, head_32/64.S: Enable SMEP
Quoted 21 lines
-----Original Message-----
From: Matthew Garrett [mailto:[email protected]]
Sent: Monday, May 16, 2011 7:10 PM
To: Yu, Fenghua
Cc: Ingo Molnar; Thomas Gleixner; H Peter Anvin; Mallick, Asit K; Linus Torvalds; Avi Kivity; Arjan van de Ven; Andrew Morton; Andi Kleen; linux-kernel
Subject: Re: [PATCH v2 3/4] x86, head_32/64.S: Enable SMEPQuoted 3 lines · Fenghua Yu
From: Fenghua Yu <[email protected]>
Enable newly documented SMEP (Supervisor Mode Execution Protection)
CPU
Quoted 3 lines
feature in kernel.
SMEP prevents the CPU in kernel-mode to jump to an executable page
that does
Quoted 1 line
not have the kernel/system flag set in the pte. This prevents the
kernel
Quoted 1 line
from executing user-space code accidentally or maliciously, so it for
Quoted 8 lines
example
Quoted 1 line
prevents kernel exploits from jumping to specially prepared user-mode
shell
Quoted 1 line
code. The violation will cause page fault #PF and will have error
code
Quoted 1 line
identical to XD violation.
Are EFI runtime service pages currently set up appropriately?
They are not set up yet. efi init is called after this.
But at this time there is no user space code yet. So there is no SMEP violation chance until later when any user space page table is setup.
Thanks.
-Fenghua
H. Peter Anvin
reviewerRe: [PATCH v2 3/4] x86, head_32/64.S: Enable SMEP
Quoted 7 lines · Fenghua
Quoted 2 lines
Are EFI runtime service pages currently set up appropriately?
They are not set up yet. efi init is called after this.
But at this time there is no user space code yet. So there is no SMEP violation chance until later when any user space page table is setup.
Are EFI runtime pages set up with U=0? I would argue it is a bug if they aren't, but we want to make sure that there isn't such a bug.
-hpa
RE: [PATCH v2 3/4] x86, head_32/64.S: Enable SMEP
Quoted 15 lines
-----Original Message-----
From: H. Peter Anvin [mailto:[email protected]]
Sent: Tuesday, May 17, 2011 4:13 PM
To: Yu, Fenghua
Cc: Matthew Garrett; Ingo Molnar; Thomas Gleixner; Mallick, Asit K; Linus Torvalds; Avi Kivity; Arjan van de Ven; Andrew Morton; Andi Kleen; linux-kernel
Subject: Re: [PATCH v2 3/4] x86, head_32/64.S: Enable SMEPQuoted 5 lines · Fenghua
Quoted 2 lines
Are EFI runtime service pages currently set up appropriately?
They are not set up yet. efi init is called after this.
Quoted 8 lines
Quoted 1 line
But at this time there is no user space code yet. So there is no SMEP
violation chance until later when any user space page table is setup.
Quoted 1 line
Are EFI runtime pages set up with U=0? I would argue it is a bug if they aren't, but we want to make sure that there isn't such a bug.
-hpa
The runtime services are ioremapped. So they should be U=0.
Thanks.
-Fenghua
PATCH v2 4/4 x86/kernel/common.c: Disable SMEP by kernel option nosmep
In reply to Fenghua YuFrom: Fenghua Yu <[email protected]>
SMEP is enabled unconditionally on all CPUs that support it, the nosmep boot option would turn it off shortly afterwards.
--- Documentation/kernel-parameters.txt | 4 ++++ arch/x86/kernel/cpu/common.c | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 0 deletions(-)
Documentation/kernel-parameters.txt +4 -0
@@ -1664,6 +1664,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted. noexec=on: enable non-executable mappings (default) noexec=off: disable non-executable mappings + nosmep [X86] + Disable SMEP (Supervisor Mode Execution Protection) + even if it is supported by the processor. + noexec32 [X86-64] This affects only 32-bit executables. noexec32=on: enable non-executable mappings (default)
arch/x86/kernel/cpu/common.c +22 -0
@@ -254,6 +254,27 @@ static inline void squash_the_stupid_serial_number(struct cpuinfo_x86 *c) }#endif +static int disable_smep__initdata ; + +static __init int setup_nosmep (char *arg) +{ + disable_smep =1 ; +return 1 ; +} +__setup ("nosmep" , setup_nosmep); + +/* +* If SMEP is supported by the processor, SMEP has been enabled in CR4 earlier. +* But if kernel option "nosmep" is given, we disable SMEP here. +*/ +static __init void config_smep (struct cpuinfo_x86 *c) +{ +if (cpu_has (c,X86_FEATURE_SMEP ) &&unlikely (disable_smep)) { +setup_clear_cpu_cap (X86_FEATURE_SMEP ); +clear_in_cr4 (X86_CR4_SMEP ); + } +} +/* * Some CPU features depend on higher CPUID levels, which may not always * be available due to CPUID level capping or broken virtualization
@@ -737,6 +758,7 @@ static void __cpuinit generic_identify(struct cpuinfo_x86 *c)get_cpu_vendor (c);get_cpu_cap (c); +config_smep (c);if (c->cpuid_level >=0x00000001 ) { c->initial_apicid = (cpuid_ebx (1 ) >>24 ) &0xFF ;
Signature · 1 line
1.7.2
Re: [PATCH v2 4/4] x86/kernel/common.c: Disable SMEP by kernel option nosmep
arch/x86/kernel/cpu/common.c static inline void squash_the_stupid_serial_number(struct cpuinfo_x86 *c) · line 272
Quoted 7 lines · Fenghua Yu
arch/x86/kernel/cpu/common.c +7
-0+/* +* If SMEP is supported by the processor, SMEP has been enabled in CR4 earlier. +* But if kernel option "nosmep" is given, we disable SMEP here. +*/ +static __init void config_smep (struct cpuinfo_x86 *c) +{ +if (cpu_has (c,X86_FEATURE_SMEP ) &&unlikely (disable_smep)) {
That unlikely() is completely pointless. This is init code and inside of a if() already. Where is the point ?
arch/x86/kernel/cpu/common.c static inline void squash_the_stupid_serial_number(struct cpuinfo_x86 *c) · line 276
Quoted 4 lines
arch/x86/kernel/cpu/common.c +4
-0+setup_clear_cpu_cap (X86_FEATURE_SMEP ); +clear_in_cr4 (X86_CR4_SMEP ); + } +}
Thanks,
tglx
H. Peter Anvin
reviewerQuoted 4 lines · Fenghua Yu
Note: This patch set doesn't enable the SMEP feature in KVM. If it's needed, another patch will be pushed for enabling the feature in KVM.
Hi Avi,
Could you comment on if this needs to be a gating factor?
-hpa
Quoted 9 lines · H. Peter Anvin
Quoted 4 lines · Fenghua Yu
Note: This patch set doesn't enable the SMEP feature in KVM. If it's needed, another patch will be pushed for enabling the feature in KVM.
Hi Avi,
Could you comment on if this needs to be a gating factor?
I think KVM would benefit from the native kernel playing guinea pig whether SMEP is really, truly 100% trouble-free to enable by default (for Linux) ;-)
Some programmable configurability seems necessary on the KVM side, as KVM has no control over how sane the guest kernel is.
Thanks,
Ingo
Quoted 11 lines · Ingo Molnar
Quoted 9 lines · H. Peter Anvin
Quoted 4 lines · Fenghua Yu
Note: This patch set doesn't enable the SMEP feature in KVM. If it's needed, another patch will be pushed for enabling the feature in KVM.
Hi Avi,
Could you comment on if this needs to be a gating factor?
It should certainly not be a gating factor. Note that smep will be disabled when switching to the guest, so there are no compatibility issues.
Quoted 5 lines
I think KVM would benefit from the native kernel playing guinea pig whether SMEP is really, truly 100% trouble-free to enable by default (for Linux) ;-)
Some programmable configurability seems necessary on the KVM side, as KVM has no control over how sane the guest kernel is.
We should simply expose the cpuid bit and cr4.smep. If the guest kernel feels it is up to it, it can enable smep itself.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 5 lines · Avi Kivity
Quoted 2 lines
Some programmable configurability seems necessary on the KVM side, as KVM has no control over how sane the guest kernel is.
We should simply expose the cpuid bit and cr4.smep. If the guest kernel feels it is up to it, it can enable smep itself.
Well, given that there's lots of legacy installations around it would be a neat KVM feature if it was possible to enable SMEP even if the guest kernel does not enable it. As an additional (optional) layer of security.
For example legacy Linux guests will work just fine, even if they do not enable SMEP themselves.
Thanks,
Ingo
Quoted 8 lines · Ingo Molnar
Quoted 5 lines · Avi Kivity
Quoted 2 lines
Some programmable configurability seems necessary on the KVM side, as KVM has no control over how sane the guest kernel is.
We should simply expose the cpuid bit and cr4.smep. If the guest kernel feels it is up to it, it can enable smep itself.
Quoted 6 lines
Well, given that there's lots of legacy installations around it would be a neat KVM feature if it was possible to enable SMEP even if the guest kernel does not enable it. As an additional (optional) layer of security.
For example legacy Linux guests will work just fine, even if they do not enable SMEP themselves.
It's certainly possible (set CR4.SMEP transparently and hide it from the guest). But there's no way to tell if it doesn't break something wierd. The host might not even know if the guest is Linux or something else.
We could support it as a non-default feature, but that reduces its utility.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 13 lines · Avi Kivity
Quoted 12 lines · Ingo Molnar
Quoted 5 lines · Avi Kivity
Quoted 2 lines
Some programmable configurability seems necessary on the KVM side, as KVM has no control over how sane the guest kernel is.
We should simply expose the cpuid bit and cr4.smep. If the guest kernel feels it is up to it, it can enable smep itself.
Well, given that there's lots of legacy installations around it would be a neat KVM feature if it was possible to enable SMEP even if the guest kernel does not enable it. As an additional (optional) layer of security.
Quoted 8 lines
Quoted 2 lines
For example legacy Linux guests will work just fine, even if they do not enable SMEP themselves.
It's certainly possible (set CR4.SMEP transparently and hide it from the guest). But there's no way to tell if it doesn't break something wierd. The host might not even know if the guest is Linux or something else.
We could support it as a non-default feature, but that reduces its utility.
It would be a nice touch for tools/kvm/: we would use KVM_GET_SREGS and KVM_GET_SREGS to twiddle CR4.SMEP, even without the guest explicitly doing it.
A quick glance suggests that it could be done straight away in tools/kvm/kvm-cpu.c::kvm_cpu__setup_sregs() during vcpu setup, and hopefully that cr4 value survives boot and ends up in the guest kernel's mmu_cr4_features mask shadow register.
Thanks,
Ingo
Quoted 10 lines · Ingo Molnar
Quoted 2 lines
We could support it as a non-default feature, but that reduces its utility.
It would be a nice touch for
tools/kvm/: we would useKVM_GET_SREGSandKVM_GET_SREGSto twiddle CR4.SMEP, even without the guest explicitly doing it.A quick glance suggests that it could be done straight away in tools/kvm/kvm-cpu.c::kvm_cpu__setup_sregs() during vcpu setup, and hopefully that cr4 value survives boot and ends up in the guest kernel's
mmu_cr4_featuresmask shadow register.
Depends if the guest uses a read-modify-write pattern or not. We could do it transparently in kvm.ko, since the real cr4 need not corresponds to the guest notion (for example, we often set cr0.wp or cr0.ts even though the guest wants them clear).
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 12 lines · Avi Kivity
Quoted 10 lines · Ingo Molnar
Quoted 2 lines
We could support it as a non-default feature, but that reduces its utility.
It would be a nice touch for
tools/kvm/: we would useKVM_GET_SREGSandKVM_GET_SREGSto twiddle CR4.SMEP, even without the guest explicitly doing it.A quick glance suggests that it could be done straight away in tools/kvm/kvm-cpu.c::kvm_cpu__setup_sregs() during vcpu setup, and hopefully that cr4 value survives boot and ends up in the guest kernel's
mmu_cr4_featuresmask shadow register.
Quoted 4 lines
Depends if the guest uses a read-modify-write pattern or not. We could do it transparently in kvm.ko, since the real cr4 need not corresponds to the guest notion (for example, we often set cr0.wp or cr0.ts even though the guest wants them clear).
Oh, being transparent is a nice touch when it comes to security measures (catching attackers who think there's no SMEP and such) - but that would need KVM support and a new ioctl to configure it, right?
Thanks,
Ingo
Quoted 9 lines · Ingo Molnar
Quoted 5 lines
Depends if the guest uses a read-modify-write pattern or not. We could do it transparently in kvm.ko, since the real cr4 need not corresponds to the guest notion (for example, we often set cr0.wp or cr0.ts even though the guest wants them clear).
Oh, being transparent is a nice touch when it comes to security measures (catching attackers who think there's no SMEP and such) - but that would need KVM support and a new ioctl to configure it, right?
Yes.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 7 lines · Avi Kivity
Quoted 6 lines · Ingo Molnar
Quoted 2 lines
Depends if the guest uses a read-modify-write pattern or not. We
could do it
Quoted 1 line
transparently in kvm.ko, since the real cr4 need not corresponds
to the guest
Quoted 1 line
notion (for example, we often set cr0.wp or cr0.ts even though the
Quoted 9 lines
Quoted 6 lines
guest
Quoted 1 line
wants them clear).
Oh, being transparent is a nice touch when it comes to security measures (catching attackers who think there's no SMEP and such) - but that would need KVM support and a new ioctl to configure it, right?
Yes.
btw, KVM support is required anyway, you can't set random bits in cr4 (from either the guest or host userspace) - kvm needs to understand them.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 18 lines · Avi Kivity
Quoted 17 lines · Avi Kivity
Quoted 14 lines · Ingo Molnar
Quoted 9 lines
Depends if the guest uses a read-modify-write pattern or not. We could do it
transparently in kvm.ko, since the real cr4 need not corresponds to the guest
notion (for example, we often set cr0.wp or cr0.ts even though the guest
wants them clear).Oh, being transparent is a nice touch when it comes to security measures (catching attackers who think there's no SMEP and such) - but that would need
KVM support and a new ioctl to configure it, right?
Quoted 5 lines
Quoted 2 lines
Yes.
btw, KVM support is required anyway, you can't set random bits in cr4 (from either the guest or host userspace) - kvm needs to understand them.
Yeah, I was wondering how the CR4 hack would actually enable something. :-) Please CC me if you do add such an ioctl() and we'll make the native KVM tool use it by default.
Pekka
Quoted 16 lines · Avi Kivity
Quoted 15 lines · Avi Kivity
Quoted 13 lines · Ingo Molnar
Quoted 2 lines
Depends if the guest uses a read-modify-write pattern or not.
We could do it
Quoted 1 line
transparently in kvm.ko, since the real cr4 need not
corresponds to the guest
Quoted 1 line
notion (for example, we often set cr0.wp or cr0.ts even
though the guest
Quoted 1 line
wants them clear).
Oh, being transparent is a nice touch when it comes to security measures (catching attackers who think there's no SMEP and such) - but that would need
KVM support and a new ioctl to configure it, right?
Quoted 6 lines
Quoted 2 lines
Yes.
btw, KVM support is required anyway, you can't set random bits in cr4 (from either the guest or host userspace) - kvm needs to understand them.
Sure, that is the whole premise of this discussion.
I meant to say:
"but that would need KVM ABI support via a new ioctl to configure it, right?"
Thanks,
Ingo
Quoted 16 lines
From: Avi Kivity
Sent: Tuesday, May 17, 2011 7:34 PMQuoted 5 lines · Ingo Molnar
Quoted 2 lines
We could support it as a non-default feature, but that reduces its utility.
It would be a nice touch for
tools/kvm/: we would useKVM_GET_SREGSandKVM_GET_SREGSto twiddle CR4.SMEP, even without the guest explicitlydoing it.
Quoted 5 lines
A quick glance suggests that it could be done straight away in tools/kvm/kvm-cpu.c::kvm_cpu__setup_sregs() during vcpu setup, and hopefully that cr4 value survives boot and ends up in the guest kernel's
mmu_cr4_featuresmask shadow register.
Quoted 5 lines
Depends if the guest uses a read-modify-write pattern or not. We could do it transparently in kvm.ko, since the real cr4 need not corresponds to the guest notion (for example, we often set cr0.wp or cr0.ts even though the guest wants them clear).
We have a patch in hand now to enable SMEP for kvm guest, which is under test and cleanup and will be sent out soon. Basically it contains the basic idea by exposing CR4.smep and cpuid leaf. Above idea is nice and we'll try that in a following work.
Thanks
Kevin
After this basic enabling work, we could work out a patch to address Ingo's idea, which will mandatorily turn on SMEP for guests.
Shan Haitao
-----Original Message-----
From: Tian, Kevin
Sent: Thursday, May 19, 2011 2:11 PM
To: Avi Kivity; Ingo Molnar
Cc: H. Peter Anvin; Yu, Fenghua; Thomas Gleixner; Mallick, Asit K; Linus Torvalds; Arjan van de Ven; Andrew Morton; Andi Kleen; linux-kernel; Pekka Enberg; Shan, Haitao
Subject: RE: [PATCH v2 0/4] Enable SMEP CPU Feature
Quoted 17 lines
From: Avi Kivity
Sent: Tuesday, May 17, 2011 7:34 PMQuoted 6 lines · Ingo Molnar
Quoted 2 lines
We could support it as a non-default feature, but that reduces its utility.
It would be a nice touch for
tools/kvm/: we would useKVM_GET_SREGSandKVM_GET_SREGSto twiddle CR4.SMEP, even without the guest explicitlydoing it.
Quoted 5 lines
A quick glance suggests that it could be done straight away in tools/kvm/kvm-cpu.c::kvm_cpu__setup_sregs() during vcpu setup, and hopefully that cr4 value survives boot and ends up in the guest kernel's
mmu_cr4_featuresmask shadow register.
Quoted 5 lines
Depends if the guest uses a read-modify-write pattern or not. We could do it transparently in kvm.ko, since the real cr4 need not corresponds to the guest notion (for example, we often set cr0.wp or cr0.ts even though the guest wants them clear).
We have a patch in hand now to enable SMEP for kvm guest, which is under test and cleanup and will be sent out soon. Basically it contains the basic idea by exposing CR4.smep and cpuid leaf. Above idea is nice and we'll try that in a following work.
Thanks
Kevin
Quoted 2 lines · Shan, Haitao
After this basic enabling work, we could work out a patch to address Ingo's idea, which will mandatorily turn on SMEP for guests.
FYI, basic host arch/x86/ kernel SMEP support is now upstream (sent it to Linus yesterday) and will be released as part of v2.6.40.
Thanks,
Ingo
Quoted 8 lines · Fenghua Yu
From: Fenghua Yu <[email protected]>
Intel new CPU supports SMEP (Supervisor Mode Execution Protection). SMEP prevents kernel from executing code in application. Updated Intel SDM describes this CPU feature. The document will be published soon.
Note: This patch set doesn't enable the SMEP feature in KVM. If it's needed, another patch will be pushed for enabling the feature in KVM.
We can do it separately from native kernel support, but i'm sure Avi would agree that SMEP support in KVM would be nice! (as long as it's configurable as well, there might be guest OSs that break if SMEP is enabled, right?)
Thanks,
Ingo
Quoted 8 lines · Ingo Molnar
Quoted 6 lines · Fenghua Yu
From: Fenghua Yu<[email protected]>
Intel new CPU supports SMEP (Supervisor Mode Execution Protection). SMEP prevents kernel from executing code in application. Updated Intel SDM describes this CPU feature. The document will be published soon.
Quoted 5 lines
Quoted 2 lines
Note: This patch set doesn't enable the SMEP feature in KVM. If it's needed, another patch will be pushed for enabling the feature in KVM.
We can do it separately from native kernel support, but i'm sure Avi would agree that SMEP support in KVM would be nice!
Definitely.
Quoted 2 lines
(as long as it's configurable as
well, there might be guest OSs that break if SMEP is enabled, right?)
As mentioned earlier, the simple thing is to expose smep and let the guest enable it itself.
Signature · 1 line
error compiling committee.c: too many arguments to function