x86/iopl: Fix iopl capability check on Xen PV
authorAndy Lutomirski <luto@kernel.org>
Wed, 16 Mar 2016 21:14:22 +0000 (14:14 -0700)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 30 Apr 2016 22:05:19 +0000 (00:05 +0200)
commit c29016cf41fe9fa994a5ecca607cf5f1cd98801e upstream.

iopl(3) is supposed to work if iopl is already 3, even if
unprivileged.  This didn't work right on Xen PV.  Fix it.

Reviewewd-by: Jan Beulich <JBeulich@suse.com>
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/8ce12013e6e4c0a44a97e316be4a6faff31bd5ea.1458162709.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
arch/x86/kernel/ioport.c

index 8c96897..6a2fa4a 100644 (file)
@@ -95,9 +95,14 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
  */
 long sys_iopl(unsigned int level, struct pt_regs *regs)
 {
-       unsigned int old = (regs->flags >> 12) & 3;
        struct thread_struct *t = &current->thread;
 
+       /*
+        * Careful: the IOPL bits in regs->flags are undefined under Xen PV
+        * and changing them has no effect.
+        */
+       unsigned int old = t->iopl >> 12;
+
        if (level > 3)
                return -EINVAL;
        /* Trying to gain more privileges? */