* [PATCH 0/3] x86/vm86/32: A bugfix and a matching test improvement @ 2018-03-14 5:03 Andy Lutomirski 2018-03-14 5:03 ` [PATCH 1/3] selftests/x86/entry_from_vm86: Exit with 1 if we fail Andy Lutomirski ` (2 more replies) 0 siblings, 3 replies; 7+ messages in thread From: Andy Lutomirski @ 2018-03-14 5:03 UTC (permalink / raw) To: x86, LKML Cc: Borislav Petkov, Stas Sergeev, bartoldeman, Brian Gerst, Andy Lutomirski A patch in 4.2 broke vm86's POPF emulation in a way that was somehow subtle enough that no one noticed until now. Fix it and improve the test case to exercise the code. (The improved test case also exercises some code paths that were *not* broken but that would have become broken if Stas' original suggested patch were applied. Go testing!) Andy Lutomirski (3): selftests/x86/entry_from_vm86: Exit with 1 if we fail selftests/x86/entry_from_vm86: Add test cases for POPF x86/vm86/32: Fix POPF emulation arch/x86/kernel/vm86_32.c | 3 ++- tools/testing/selftests/x86/entry_from_vm86.c | 32 +++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) -- 2.14.3 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/3] selftests/x86/entry_from_vm86: Exit with 1 if we fail 2018-03-14 5:03 [PATCH 0/3] x86/vm86/32: A bugfix and a matching test improvement Andy Lutomirski @ 2018-03-14 5:03 ` Andy Lutomirski 2018-03-14 8:46 ` [tip:x86/pti] " tip-bot for Andy Lutomirski 2018-03-14 5:03 ` [PATCH 2/3] selftests/x86/entry_from_vm86: Add test cases for POPF Andy Lutomirski 2018-03-14 5:03 ` [PATCH 3/3] x86/vm86/32: Fix POPF emulation Andy Lutomirski 2 siblings, 1 reply; 7+ messages in thread From: Andy Lutomirski @ 2018-03-14 5:03 UTC (permalink / raw) To: x86, LKML Cc: Borislav Petkov, Stas Sergeev, bartoldeman, Brian Gerst, Andy Lutomirski, stable Fix a logic error that caused the test to exit with 0 even if test cases failed. Cc: stable@vger.kernel.org Signed-off-by: Andy Lutomirski <luto@kernel.org> --- tools/testing/selftests/x86/entry_from_vm86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/x86/entry_from_vm86.c b/tools/testing/selftests/x86/entry_from_vm86.c index 361466a2eaef..6e85f0d0498d 100644 --- a/tools/testing/selftests/x86/entry_from_vm86.c +++ b/tools/testing/selftests/x86/entry_from_vm86.c @@ -318,7 +318,7 @@ int main(void) clearhandler(SIGSEGV); /* Make sure nothing explodes if we fork. */ - if (fork() > 0) + if (fork() == 0) return 0; return (nerrs == 0 ? 0 : 1); -- 2.14.3 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [tip:x86/pti] selftests/x86/entry_from_vm86: Exit with 1 if we fail 2018-03-14 5:03 ` [PATCH 1/3] selftests/x86/entry_from_vm86: Exit with 1 if we fail Andy Lutomirski @ 2018-03-14 8:46 ` tip-bot for Andy Lutomirski 0 siblings, 0 replies; 7+ messages in thread From: tip-bot for Andy Lutomirski @ 2018-03-14 8:46 UTC (permalink / raw) To: linux-tip-commits Cc: peterz, jpoimboe, brgerst, hpa, stsp, torvalds, dvlasenk, tglx, mingo, luto, linux-kernel, bp Commit-ID: 327d53d005ca47b10eae940616ed11c569f75a9b Gitweb: https://git.kernel.org/tip/327d53d005ca47b10eae940616ed11c569f75a9b Author: Andy Lutomirski <luto@kernel.org> AuthorDate: Tue, 13 Mar 2018 22:03:10 -0700 Committer: Ingo Molnar <mingo@kernel.org> CommitDate: Wed, 14 Mar 2018 09:21:01 +0100 selftests/x86/entry_from_vm86: Exit with 1 if we fail Fix a logic error that caused the test to exit with 0 even if test cases failed. Signed-off-by: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stas Sergeev <stsp@list.ru> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: bartoldeman@gmail.com Cc: stable@vger.kernel.org Link: http://lkml.kernel.org/r/b1cc37144038958a469c8f70a5f47a6a5638636a.1521003603.git.luto@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org> --- tools/testing/selftests/x86/entry_from_vm86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/x86/entry_from_vm86.c b/tools/testing/selftests/x86/entry_from_vm86.c index 361466a2eaef..6e85f0d0498d 100644 --- a/tools/testing/selftests/x86/entry_from_vm86.c +++ b/tools/testing/selftests/x86/entry_from_vm86.c @@ -318,7 +318,7 @@ int main(void) clearhandler(SIGSEGV); /* Make sure nothing explodes if we fork. */ - if (fork() > 0) + if (fork() == 0) return 0; return (nerrs == 0 ? 0 : 1); ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] selftests/x86/entry_from_vm86: Add test cases for POPF 2018-03-14 5:03 [PATCH 0/3] x86/vm86/32: A bugfix and a matching test improvement Andy Lutomirski 2018-03-14 5:03 ` [PATCH 1/3] selftests/x86/entry_from_vm86: Exit with 1 if we fail Andy Lutomirski @ 2018-03-14 5:03 ` Andy Lutomirski 2018-03-14 8:46 ` [tip:x86/pti] " tip-bot for Andy Lutomirski 2018-03-14 5:03 ` [PATCH 3/3] x86/vm86/32: Fix POPF emulation Andy Lutomirski 2 siblings, 1 reply; 7+ messages in thread From: Andy Lutomirski @ 2018-03-14 5:03 UTC (permalink / raw) To: x86, LKML Cc: Borislav Petkov, Stas Sergeev, bartoldeman, Brian Gerst, Andy Lutomirski, stable POPF is currently broken -- add tests to catch the error. This results in: [RUN] POPF with VIP set and IF clear from vm86 mode [INFO] Exited vm86 mode due to STI [FAIL] Incorrect return reason (started at eip = 0xd, ended at eip = 0xf) because POPF currently fails to check IF before reporting a pending interrupt. This patch also makes the FAIL message a bit more informative. Cc: stable@vger.kernel.org Reported-by: Bart Oldeman <bartoldeman@gmail.com> Signed-off-by: Andy Lutomirski <luto@kernel.org> --- tools/testing/selftests/x86/entry_from_vm86.c | 30 ++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/x86/entry_from_vm86.c b/tools/testing/selftests/x86/entry_from_vm86.c index 6e85f0d0498d..ade443a88421 100644 --- a/tools/testing/selftests/x86/entry_from_vm86.c +++ b/tools/testing/selftests/x86/entry_from_vm86.c @@ -95,6 +95,10 @@ asm ( "int3\n\t" "vmcode_int80:\n\t" "int $0x80\n\t" + "vmcode_popf_hlt:\n\t" + "push %ax\n\t" + "popf\n\t" + "hlt\n\t" "vmcode_umip:\n\t" /* addressing via displacements */ "smsw (2052)\n\t" @@ -124,8 +128,8 @@ asm ( extern unsigned char vmcode[], end_vmcode[]; extern unsigned char vmcode_bound[], vmcode_sysenter[], vmcode_syscall[], - vmcode_sti[], vmcode_int3[], vmcode_int80[], vmcode_umip[], - vmcode_umip_str[], vmcode_umip_sldt[]; + vmcode_sti[], vmcode_int3[], vmcode_int80[], vmcode_popf_hlt[], + vmcode_umip[], vmcode_umip_str[], vmcode_umip_sldt[]; /* Returns false if the test was skipped. */ static bool do_test(struct vm86plus_struct *v86, unsigned long eip, @@ -175,7 +179,7 @@ static bool do_test(struct vm86plus_struct *v86, unsigned long eip, (VM86_TYPE(ret) == rettype && VM86_ARG(ret) == retarg)) { printf("[OK]\tReturned correctly\n"); } else { - printf("[FAIL]\tIncorrect return reason\n"); + printf("[FAIL]\tIncorrect return reason (started at eip = 0x%lx, ended at eip = 0x%lx)\n", eip, v86->regs.eip); nerrs++; } @@ -264,6 +268,9 @@ int main(void) v86.regs.ds = load_addr / 16; v86.regs.es = load_addr / 16; + /* Use the end of the page as our stack. */ + v86.regs.esp = 4096; + assert((v86.regs.cs & 3) == 0); /* Looks like RPL = 0 */ /* #BR -- should deliver SIG??? */ @@ -295,6 +302,23 @@ int main(void) v86.regs.eflags &= ~X86_EFLAGS_IF; do_test(&v86, vmcode_sti - vmcode, VM86_STI, 0, "STI with VIP set"); + /* POPF with VIP set but IF clear: should not trap */ + v86.regs.eflags = X86_EFLAGS_VIP; + v86.regs.eax = 0; + do_test(&v86, vmcode_popf_hlt - vmcode, VM86_UNKNOWN, 0, "POPF with VIP set and IF clear"); + + /* POPF with VIP set and IF set: should trap */ + v86.regs.eflags = X86_EFLAGS_VIP; + v86.regs.eax = X86_EFLAGS_IF; + do_test(&v86, vmcode_popf_hlt - vmcode, VM86_STI, 0, "POPF with VIP and IF set"); + + /* POPF with VIP clear and IF set: should not trap */ + v86.regs.eflags = 0; + v86.regs.eax = X86_EFLAGS_IF; + do_test(&v86, vmcode_popf_hlt - vmcode, VM86_UNKNOWN, 0, "POPF with VIP clear and IF set"); + + v86.regs.eflags = 0; + /* INT3 -- should cause #BP */ do_test(&v86, vmcode_int3 - vmcode, VM86_TRAP, 3, "INT3"); -- 2.14.3 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [tip:x86/pti] selftests/x86/entry_from_vm86: Add test cases for POPF 2018-03-14 5:03 ` [PATCH 2/3] selftests/x86/entry_from_vm86: Add test cases for POPF Andy Lutomirski @ 2018-03-14 8:46 ` tip-bot for Andy Lutomirski 0 siblings, 0 replies; 7+ messages in thread From: tip-bot for Andy Lutomirski @ 2018-03-14 8:46 UTC (permalink / raw) To: linux-tip-commits Cc: luto, jpoimboe, brgerst, peterz, bartoldeman, bp, hpa, mingo, linux-kernel, torvalds, dvlasenk, stsp, tglx Commit-ID: 78393fdde2a456cafa414b171c90f26a3df98b20 Gitweb: https://git.kernel.org/tip/78393fdde2a456cafa414b171c90f26a3df98b20 Author: Andy Lutomirski <luto@kernel.org> AuthorDate: Tue, 13 Mar 2018 22:03:11 -0700 Committer: Ingo Molnar <mingo@kernel.org> CommitDate: Wed, 14 Mar 2018 09:21:01 +0100 selftests/x86/entry_from_vm86: Add test cases for POPF POPF is currently broken -- add tests to catch the error. This results in: [RUN] POPF with VIP set and IF clear from vm86 mode [INFO] Exited vm86 mode due to STI [FAIL] Incorrect return reason (started at eip = 0xd, ended at eip = 0xf) because POPF currently fails to check IF before reporting a pending interrupt. This patch also makes the FAIL message a bit more informative. Reported-by: Bart Oldeman <bartoldeman@gmail.com> Signed-off-by: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stas Sergeev <stsp@list.ru> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: stable@vger.kernel.org Link: http://lkml.kernel.org/r/a16270b5cfe7832d6d00c479d0f871066cbdb52b.1521003603.git.luto@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org> --- tools/testing/selftests/x86/entry_from_vm86.c | 30 ++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/x86/entry_from_vm86.c b/tools/testing/selftests/x86/entry_from_vm86.c index 6e85f0d0498d..ade443a88421 100644 --- a/tools/testing/selftests/x86/entry_from_vm86.c +++ b/tools/testing/selftests/x86/entry_from_vm86.c @@ -95,6 +95,10 @@ asm ( "int3\n\t" "vmcode_int80:\n\t" "int $0x80\n\t" + "vmcode_popf_hlt:\n\t" + "push %ax\n\t" + "popf\n\t" + "hlt\n\t" "vmcode_umip:\n\t" /* addressing via displacements */ "smsw (2052)\n\t" @@ -124,8 +128,8 @@ asm ( extern unsigned char vmcode[], end_vmcode[]; extern unsigned char vmcode_bound[], vmcode_sysenter[], vmcode_syscall[], - vmcode_sti[], vmcode_int3[], vmcode_int80[], vmcode_umip[], - vmcode_umip_str[], vmcode_umip_sldt[]; + vmcode_sti[], vmcode_int3[], vmcode_int80[], vmcode_popf_hlt[], + vmcode_umip[], vmcode_umip_str[], vmcode_umip_sldt[]; /* Returns false if the test was skipped. */ static bool do_test(struct vm86plus_struct *v86, unsigned long eip, @@ -175,7 +179,7 @@ static bool do_test(struct vm86plus_struct *v86, unsigned long eip, (VM86_TYPE(ret) == rettype && VM86_ARG(ret) == retarg)) { printf("[OK]\tReturned correctly\n"); } else { - printf("[FAIL]\tIncorrect return reason\n"); + printf("[FAIL]\tIncorrect return reason (started at eip = 0x%lx, ended at eip = 0x%lx)\n", eip, v86->regs.eip); nerrs++; } @@ -264,6 +268,9 @@ int main(void) v86.regs.ds = load_addr / 16; v86.regs.es = load_addr / 16; + /* Use the end of the page as our stack. */ + v86.regs.esp = 4096; + assert((v86.regs.cs & 3) == 0); /* Looks like RPL = 0 */ /* #BR -- should deliver SIG??? */ @@ -295,6 +302,23 @@ int main(void) v86.regs.eflags &= ~X86_EFLAGS_IF; do_test(&v86, vmcode_sti - vmcode, VM86_STI, 0, "STI with VIP set"); + /* POPF with VIP set but IF clear: should not trap */ + v86.regs.eflags = X86_EFLAGS_VIP; + v86.regs.eax = 0; + do_test(&v86, vmcode_popf_hlt - vmcode, VM86_UNKNOWN, 0, "POPF with VIP set and IF clear"); + + /* POPF with VIP set and IF set: should trap */ + v86.regs.eflags = X86_EFLAGS_VIP; + v86.regs.eax = X86_EFLAGS_IF; + do_test(&v86, vmcode_popf_hlt - vmcode, VM86_STI, 0, "POPF with VIP and IF set"); + + /* POPF with VIP clear and IF set: should not trap */ + v86.regs.eflags = 0; + v86.regs.eax = X86_EFLAGS_IF; + do_test(&v86, vmcode_popf_hlt - vmcode, VM86_UNKNOWN, 0, "POPF with VIP clear and IF set"); + + v86.regs.eflags = 0; + /* INT3 -- should cause #BP */ do_test(&v86, vmcode_int3 - vmcode, VM86_TRAP, 3, "INT3"); ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] x86/vm86/32: Fix POPF emulation 2018-03-14 5:03 [PATCH 0/3] x86/vm86/32: A bugfix and a matching test improvement Andy Lutomirski 2018-03-14 5:03 ` [PATCH 1/3] selftests/x86/entry_from_vm86: Exit with 1 if we fail Andy Lutomirski 2018-03-14 5:03 ` [PATCH 2/3] selftests/x86/entry_from_vm86: Add test cases for POPF Andy Lutomirski @ 2018-03-14 5:03 ` Andy Lutomirski 2018-03-14 8:47 ` [tip:x86/pti] " tip-bot for Andy Lutomirski 2 siblings, 1 reply; 7+ messages in thread From: Andy Lutomirski @ 2018-03-14 5:03 UTC (permalink / raw) To: x86, LKML Cc: Borislav Petkov, Stas Sergeev, bartoldeman, Brian Gerst, Andy Lutomirski, stable POPF would trap if VIP was set regardless of whether IF was set. Fix it. Reported-by: Bart Oldeman <bartoldeman@gmail.com> Suggested-by: Stas Sergeev <stsp@list.ru> Cc: stable@vger.kernel.org Fixes: 5ed92a8ab71f ("x86/vm86: Use the normal pt_regs area for vm86") Signed-off-by: Andy Lutomirski <luto@kernel.org> --- arch/x86/kernel/vm86_32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c index 5edb27f1a2c4..9d0b5af7db91 100644 --- a/arch/x86/kernel/vm86_32.c +++ b/arch/x86/kernel/vm86_32.c @@ -727,7 +727,8 @@ void handle_vm86_fault(struct kernel_vm86_regs *regs, long error_code) return; check_vip: - if (VEFLAGS & X86_EFLAGS_VIP) { + if ((VEFLAGS & (X86_EFLAGS_VIP | X86_EFLAGS_VIF)) == + (X86_EFLAGS_VIP | X86_EFLAGS_VIF)) { save_v86_state(regs, VM86_STI); return; } -- 2.14.3 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [tip:x86/pti] x86/vm86/32: Fix POPF emulation 2018-03-14 5:03 ` [PATCH 3/3] x86/vm86/32: Fix POPF emulation Andy Lutomirski @ 2018-03-14 8:47 ` tip-bot for Andy Lutomirski 0 siblings, 0 replies; 7+ messages in thread From: tip-bot for Andy Lutomirski @ 2018-03-14 8:47 UTC (permalink / raw) To: linux-tip-commits Cc: dvlasenk, torvalds, bp, bartoldeman, hpa, linux-kernel, jpoimboe, stsp, luto, brgerst, mingo, tglx, peterz Commit-ID: b5069782453459f6ec1fdeb495d9901a4545fcb5 Gitweb: https://git.kernel.org/tip/b5069782453459f6ec1fdeb495d9901a4545fcb5 Author: Andy Lutomirski <luto@kernel.org> AuthorDate: Tue, 13 Mar 2018 22:03:12 -0700 Committer: Ingo Molnar <mingo@kernel.org> CommitDate: Wed, 14 Mar 2018 09:21:01 +0100 x86/vm86/32: Fix POPF emulation POPF would trap if VIP was set regardless of whether IF was set. Fix it. Suggested-by: Stas Sergeev <stsp@list.ru> Reported-by: Bart Oldeman <bartoldeman@gmail.com> Signed-off-by: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: stable@vger.kernel.org Fixes: 5ed92a8ab71f ("x86/vm86: Use the normal pt_regs area for vm86") Link: http://lkml.kernel.org/r/ce95f40556e7b2178b6bc06ee9557827ff94bd28.1521003603.git.luto@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org> --- arch/x86/kernel/vm86_32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c index 5edb27f1a2c4..9d0b5af7db91 100644 --- a/arch/x86/kernel/vm86_32.c +++ b/arch/x86/kernel/vm86_32.c @@ -727,7 +727,8 @@ void handle_vm86_fault(struct kernel_vm86_regs *regs, long error_code) return; check_vip: - if (VEFLAGS & X86_EFLAGS_VIP) { + if ((VEFLAGS & (X86_EFLAGS_VIP | X86_EFLAGS_VIF)) == + (X86_EFLAGS_VIP | X86_EFLAGS_VIF)) { save_v86_state(regs, VM86_STI); return; } ^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-03-14 8:48 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-03-14 5:03 [PATCH 0/3] x86/vm86/32: A bugfix and a matching test improvement Andy Lutomirski 2018-03-14 5:03 ` [PATCH 1/3] selftests/x86/entry_from_vm86: Exit with 1 if we fail Andy Lutomirski 2018-03-14 8:46 ` [tip:x86/pti] " tip-bot for Andy Lutomirski 2018-03-14 5:03 ` [PATCH 2/3] selftests/x86/entry_from_vm86: Add test cases for POPF Andy Lutomirski 2018-03-14 8:46 ` [tip:x86/pti] " tip-bot for Andy Lutomirski 2018-03-14 5:03 ` [PATCH 3/3] x86/vm86/32: Fix POPF emulation Andy Lutomirski 2018-03-14 8:47 ` [tip:x86/pti] " tip-bot for Andy Lutomirski
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.