Commit-ID:  86cc35109029b7f1b195cef6c74654bad95e81af
Gitweb:     https://git.kernel.org/tip/86cc35109029b7f1b195cef6c74654bad95e81af
Author:     Ricardo Neri <ricardo.neri-calde...@linux.intel.com>
AuthorDate: Sun, 5 Nov 2017 18:27:49 -0800
Committer:  Ingo Molnar <mi...@kernel.org>
CommitDate: Wed, 8 Nov 2017 11:16:20 +0100

x86/insn-eval: Handle 32-bit address encodings in virtual-8086 mode

It is possible to utilize 32-bit address encodings in virtual-8086 mode via
an address override instruction prefix. However, the range of the
effective address is still limited to [0x-0xffff]. In such a case, return
error.

Also, linear addresses in virtual-8086 mode are limited to 20 bits. Enforce
such limit by truncating the most significant bytes of the computed linear
address.

Signed-off-by: Ricardo Neri <ricardo.neri-calde...@linux.intel.com>
Reviewed-by: Thomas Gleixner <t...@linutronix.de>
Cc: Adam Buchbinder <adam.buchbin...@gmail.com>
Cc: Adrian Hunter <adrian.hun...@intel.com>
Cc: Andrew Morton <a...@linux-foundation.org>
Cc: Andy Lutomirski <l...@kernel.org>
Cc: Arnaldo Carvalho de Melo <a...@redhat.com>
Cc: Borislav Petkov <b...@alien8.de>
Cc: Borislav Petkov <b...@suse.de>
Cc: Brian Gerst <brge...@gmail.com>
Cc: Chen Yucong <sla...@gmail.com>
Cc: Chris Metcalf <cmetc...@mellanox.com>
Cc: Colin Ian King <colin.k...@canonical.com>
Cc: Dave Hansen <dave.han...@linux.intel.com>
Cc: Denys Vlasenko <dvlas...@redhat.com>
Cc: Dmitry Vyukov <dvyu...@google.com>
Cc: H. Peter Anvin <h...@zytor.com>
Cc: Huang Rui <ray.hu...@amd.com>
Cc: Jiri Slaby <jsl...@suse.cz>
Cc: Jonathan Corbet <cor...@lwn.net>
Cc: Josh Poimboeuf <jpoim...@redhat.com>
Cc: Kees Cook <keesc...@chromium.org>
Cc: Linus Torvalds <torva...@linux-foundation.org>
Cc: Lorenzo Stoakes <lstoa...@gmail.com>
Cc: Masami Hiramatsu <mhira...@kernel.org>
Cc: Michael S. Tsirkin <m...@redhat.com>
Cc: Paolo Bonzini <pbonz...@redhat.com>
Cc: Paul Gortmaker <paul.gortma...@windriver.com>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Qiaowei Ren <qiaowei....@intel.com>
Cc: Ravi V. Shankar <ravi.v.shan...@intel.com>
Cc: Shuah Khan <sh...@kernel.org>
Cc: Thomas Garnier <thgar...@google.com>
Cc: Tony Luck <tony.l...@intel.com>
Cc: Vlastimil Babka <vba...@suse.cz>
Cc: ricardo.n...@intel.com
Link: 
http://lkml.kernel.org/r/1509935277-22138-5-git-send-email-ricardo.neri-calde...@linux.intel.com
Signed-off-by: Ingo Molnar <mi...@kernel.org>
---
 arch/x86/lib/insn-eval.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c
index 1ac3973..ef102db 100644
--- a/arch/x86/lib/insn-eval.c
+++ b/arch/x86/lib/insn-eval.c
@@ -1042,12 +1042,23 @@ static void __user *get_addr_ref_32(struct insn *insn, 
struct pt_regs *regs)
                goto out;
 
        /*
+        * Even though 32-bit address encodings are allowed in virtual-8086
+        * mode, the address range is still limited to [0x-0xffff].
+        */
+       if (v8086_mode(regs) && (eff_addr & ~0xffff))
+               goto out;
+
+       /*
         * Data type long could be 64 bits in size. Ensure that our 32-bit
         * effective address is not sign-extended when computing the linear
         * address.
         */
        linear_addr = (unsigned long)(eff_addr & 0xffffffff) + seg_base;
 
+       /* Limit linear address to 20 bits */
+       if (v8086_mode(regs))
+               linear_addr &= 0xfffff;
+
 out:
        return (void __user *)linear_addr;
 }

Reply via email to