]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
x86/ioperm: Fix io bitmap invalidation on Xen PV
authorAndy Lutomirski <luto@kernel.org>
Fri, 17 Jul 2020 23:53:55 +0000 (16:53 -0700)
committerThomas Gleixner <tglx@linutronix.de>
Sat, 18 Jul 2020 10:31:49 +0000 (12:31 +0200)
tss_invalidate_io_bitmap() wasn't wired up properly through the pvop
machinery, so the TSS and Xen's io bitmap would get out of sync
whenever disabling a valid io bitmap.

Add a new pvop for tss_invalidate_io_bitmap() to fix it.

This is XSA-329.

Fixes: 22fe5b0439dd ("x86/ioperm: Move TSS bitmap update to exit to user work")
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/d53075590e1f91c19f8af705059d3ff99424c020.1595030016.git.luto@kernel.org
arch/x86/include/asm/io_bitmap.h
arch/x86/include/asm/paravirt.h
arch/x86/include/asm/paravirt_types.h
arch/x86/kernel/paravirt.c
arch/x86/kernel/process.c
arch/x86/xen/enlighten_pv.c

index ac1a99ffbd8d263e4dc2e8a6cba3b589a9913d58..7f080f5c7def74d1bf8a0bafec7ab413aef0a3e7 100644 (file)
@@ -19,12 +19,28 @@ struct task_struct;
 void io_bitmap_share(struct task_struct *tsk);
 void io_bitmap_exit(struct task_struct *tsk);
 
+static inline void native_tss_invalidate_io_bitmap(void)
+{
+       /*
+        * Invalidate the I/O bitmap by moving io_bitmap_base outside the
+        * TSS limit so any subsequent I/O access from user space will
+        * trigger a #GP.
+        *
+        * This is correct even when VMEXIT rewrites the TSS limit
+        * to 0x67 as the only requirement is that the base points
+        * outside the limit.
+        */
+       this_cpu_write(cpu_tss_rw.x86_tss.io_bitmap_base,
+                      IO_BITMAP_OFFSET_INVALID);
+}
+
 void native_tss_update_io_bitmap(void);
 
 #ifdef CONFIG_PARAVIRT_XXL
 #include <asm/paravirt.h>
 #else
 #define tss_update_io_bitmap native_tss_update_io_bitmap
+#define tss_invalidate_io_bitmap native_tss_invalidate_io_bitmap
 #endif
 
 #else
index 5ca5d297df75eeb8ea7234b9896003f082d78241..3d2afecde50c68b5896c7ec30b01d6cfa6f93eb7 100644 (file)
@@ -302,6 +302,11 @@ static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
 }
 
 #ifdef CONFIG_X86_IOPL_IOPERM
+static inline void tss_invalidate_io_bitmap(void)
+{
+       PVOP_VCALL0(cpu.invalidate_io_bitmap);
+}
+
 static inline void tss_update_io_bitmap(void)
 {
        PVOP_VCALL0(cpu.update_io_bitmap);
index 732f62e04ddb851f47248013fac01bd62633aaf7..8dfcb2508e6d82cbb163c8fe2c452f042352b95c 100644 (file)
@@ -141,6 +141,7 @@ struct pv_cpu_ops {
        void (*load_sp0)(unsigned long sp0);
 
 #ifdef CONFIG_X86_IOPL_IOPERM
+       void (*invalidate_io_bitmap)(void);
        void (*update_io_bitmap)(void);
 #endif
 
index 674a7d66d960b02d406e1dea5f4f2f836730b9c9..de2138ba38e5d8579e75b25e4d2c6e04b67eaa71 100644 (file)
@@ -324,7 +324,8 @@ struct paravirt_patch_template pv_ops = {
        .cpu.swapgs             = native_swapgs,
 
 #ifdef CONFIG_X86_IOPL_IOPERM
-       .cpu.update_io_bitmap   = native_tss_update_io_bitmap,
+       .cpu.invalidate_io_bitmap       = native_tss_invalidate_io_bitmap,
+       .cpu.update_io_bitmap           = native_tss_update_io_bitmap,
 #endif
 
        .cpu.start_context_switch       = paravirt_nop,
index f362ce0d5ac0f621b901c6d728445efe7f66c107..fe67dbd76e5179911dfae10bdb2ecb2d11e6e8a1 100644 (file)
@@ -322,20 +322,6 @@ void arch_setup_new_exec(void)
 }
 
 #ifdef CONFIG_X86_IOPL_IOPERM
-static inline void tss_invalidate_io_bitmap(struct tss_struct *tss)
-{
-       /*
-        * Invalidate the I/O bitmap by moving io_bitmap_base outside the
-        * TSS limit so any subsequent I/O access from user space will
-        * trigger a #GP.
-        *
-        * This is correct even when VMEXIT rewrites the TSS limit
-        * to 0x67 as the only requirement is that the base points
-        * outside the limit.
-        */
-       tss->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET_INVALID;
-}
-
 static inline void switch_to_bitmap(unsigned long tifp)
 {
        /*
@@ -346,7 +332,7 @@ static inline void switch_to_bitmap(unsigned long tifp)
         * user mode.
         */
        if (tifp & _TIF_IO_BITMAP)
-               tss_invalidate_io_bitmap(this_cpu_ptr(&cpu_tss_rw));
+               tss_invalidate_io_bitmap();
 }
 
 static void tss_copy_io_bitmap(struct tss_struct *tss, struct io_bitmap *iobm)
@@ -380,7 +366,7 @@ void native_tss_update_io_bitmap(void)
        u16 *base = &tss->x86_tss.io_bitmap_base;
 
        if (!test_thread_flag(TIF_IO_BITMAP)) {
-               tss_invalidate_io_bitmap(tss);
+               native_tss_invalidate_io_bitmap();
                return;
        }
 
index 0d68948c82ad6f13a637d2e88ad6f86cfa31d91f..c46b9f2e732ff879ec5809d04c8edf03a83da105 100644 (file)
@@ -870,6 +870,17 @@ static void xen_load_sp0(unsigned long sp0)
 }
 
 #ifdef CONFIG_X86_IOPL_IOPERM
+static void xen_invalidate_io_bitmap(void)
+{
+       struct physdev_set_iobitmap iobitmap = {
+               .bitmap = 0,
+               .nr_ports = 0,
+       };
+
+       native_tss_invalidate_io_bitmap();
+       HYPERVISOR_physdev_op(PHYSDEVOP_set_iobitmap, &iobitmap);
+}
+
 static void xen_update_io_bitmap(void)
 {
        struct physdev_set_iobitmap iobitmap;
@@ -1099,6 +1110,7 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
        .load_sp0 = xen_load_sp0,
 
 #ifdef CONFIG_X86_IOPL_IOPERM
+       .invalidate_io_bitmap = xen_invalidate_io_bitmap,
        .update_io_bitmap = xen_update_io_bitmap,
 #endif
        .io_delay = xen_io_delay,