x86/sev: Harden #VC instruction emulation somewhat
PATCH 1/2 x86/sev: Harden #VC instruction emulation somewhat
From: "Borislav Petkov (AMD)" <[email protected]>
[ Upstream commit e3ef461af35a8c74f2f4ce6616491ddb355a208f ]
Compare the opcode bytes at rIP for each #VC exit reason to verify the instruction which raised the #VC exception is actually the right one.
Signed-off-by Borislav Petkov (AMD) <[email protected]>
Acked-by Tom Lendacky <[email protected]>
Signed-off-by Wenshan Lan <[email protected]>
--- arch/x86/boot/compressed/sev.c | 4 ++ arch/x86/kernel/sev-shared.c | 102 ++++++++++++++++++++++++++++++++- arch/x86/kernel/sev.c | 5 +- 3 files changed, 108 insertions(+), 3 deletions(-)
arch/x86/boot/compressed/sev.c +4 -0
@@ -277,6 +277,10 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code)if (result !=ES_OK ) goto finish; + result =vc_check_opcode_bytes (&ctxt, exit_code); +if (result !=ES_OK ) + goto finish; +switch (exit_code) {case SVM_EXIT_RDTSC :case SVM_EXIT_RDTSCP :
arch/x86/kernel/sev-shared.c +100 -2
126 lines not on this page · raw message
arch/x86/kernel/sev.c +4 -1
@@ -1749,7 +1749,10 @@ static enum es_result vc_handle_exitcode(struct es_em_ctxt *ctxt,struct ghcb *ghcb, unsigned long exit_code) { - enum es_result result; + enum es_result result = vc_check_opcode_bytes(ctxt, exit_code); + +if (result !=ES_OK ) +return result;switch (exit_code) {case SVM_EXIT_READ_DR7 :
Signature · 1 line
2.43.0
PATCH 2/2 x86/sev: Check for MWAITX and MONITORX opcodes in the #VC handler
From: Tom Lendacky <[email protected]>
[ Upstream commit e70316d17f6ab49a6038ffd115397fd68f8c7be8 ]
The MWAITX and MONITORX instructions generate the same #VC error code as the MWAIT and MONITOR instructions, respectively. Update the #VC handler opcode checking to also support the MWAITX and MONITORX opcodes.
Fixes e3ef461af35a ("x86/sev: Harden #VC instruction emulation somewhat")
Signed-off-by Tom Lendacky <[email protected]>
Signed-off-by Borislav Petkov (AMD) <[email protected]>
Link https://lore.kernel.org/r/453d5a7cfb4b9fe818b6fb67f93ae25468bc9e23.1713793161.git.thomas.lendacky@amd.com open here
Signed-off-by Wenshan Lan <[email protected]>
--- arch/x86/kernel/sev-shared.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/kernel/sev-shared.c +4 -2
@@ -1237,12 +1237,14 @@ static enum es_result vc_check_opcode_bytes(struct es_em_ctxt *ctxt,break ;case SVM_EXIT_MONITOR : -if (opcode ==0x010f && modrm ==0xc8 ) +/* MONITOR and MONITORX instructions generate the same error code */ +if (opcode ==0x010f && (modrm ==0xc8 || modrm ==0xfa ))return ES_OK ;break ;case SVM_EXIT_MWAIT : -if (opcode ==0x010f && modrm ==0xc9 ) +/* MWAIT and MWAITX instructions generate the same error code */ +if (opcode ==0x010f && (modrm ==0xc9 || modrm ==0xfb ))return ES_OK ;break ;
Signature · 1 line
2.43.0