linux-yocto/arch
Thomas Gleixner 2cfcbe1554 x86/iopl: Cure TIF_IO_BITMAP inconsistencies
commit 8b68e978718f14fdcb080c2a7791c52a0d09bc6d upstream.

io_bitmap_exit() is invoked from exit_thread() when a task exists or
when a fork fails. In the latter case the exit_thread() cleans up
resources which were allocated during fork().

io_bitmap_exit() invokes task_update_io_bitmap(), which in turn ends up
in tss_update_io_bitmap(). tss_update_io_bitmap() operates on the
current task. If current has TIF_IO_BITMAP set, but no bitmap installed,
tss_update_io_bitmap() crashes with a NULL pointer dereference.

There are two issues, which lead to that problem:

  1) io_bitmap_exit() should not invoke task_update_io_bitmap() when
     the task, which is cleaned up, is not the current task. That's a
     clear indicator for a cleanup after a failed fork().

  2) A task should not have TIF_IO_BITMAP set and neither a bitmap
     installed nor IOPL emulation level 3 activated.

     This happens when a kernel thread is created in the context of
     a user space thread, which has TIF_IO_BITMAP set as the thread
     flags are copied and the IO bitmap pointer is cleared.

     Other than in the failed fork() case this has no impact because
     kernel threads including IO workers never return to user space and
     therefore never invoke tss_update_io_bitmap().

Cure this by adding the missing cleanups and checks:

  1) Prevent io_bitmap_exit() to invoke task_update_io_bitmap() if
     the to be cleaned up task is not the current task.

  2) Clear TIF_IO_BITMAP in copy_thread() unconditionally. For user
     space forks it is set later, when the IO bitmap is inherited in
     io_bitmap_share().

For paranoia sake, add a warning into tss_update_io_bitmap() to catch
the case, when that code is invoked with inconsistent state.

Fixes: ea5f1cd7ab ("x86/ioperm: Remove bitmap if all permissions dropped")
Reported-by: syzbot+e2b1803445d236442e54@syzkaller.appspotmail.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/87wmdceom2.ffs@tglx
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-06-19 15:28:46 +02:00
..
alpha alpha/elf: Fix misc/setarch test of util-linux by removing 32bit support 2025-03-22 12:50:41 -07:00
arc ARC: build: Try to guess GCC variant of cross compiler 2025-01-09 13:32:05 +01:00
arm ARM: aspeed: Don't select SRAM 2025-06-19 15:28:25 +02:00
arm64 xen/arm: call uaccess_ttbr0_enable for dm_op hypercall 2025-06-19 15:28:46 +02:00
csky of/fdt: add dt_phys arg to early_init_dt_scan and early_init_dt_verify 2024-12-09 10:31:56 +01:00
hexagon hexagon: Fix unbalanced spinlock in die() 2025-02-08 09:52:34 +01:00
ia64 vgacon: rework screen_info #ifdef checks 2024-06-27 13:49:15 +02:00
loongarch LoongArch: Explicitly specify code model in Makefile 2025-05-22 14:12:25 +02:00
m68k m68k: mac: Fix macintosh_config for Mac II 2025-06-19 15:28:07 +02:00
microblaze of/fdt: add dt_phys arg to early_init_dt_scan and early_init_dt_verify 2024-12-09 10:31:56 +01:00
mips MIPS: Loongson64: Add missing '#interrupt-cells' for loongson64c_ls7a 2025-06-19 15:28:31 +02:00
nios2 of/fdt: add dt_phys arg to early_init_dt_scan and early_init_dt_verify 2024-12-09 10:31:56 +01:00
openrisc openrisc: Use asm-generic's version of fix_to_virt() & virt_to_fix() 2024-12-11 16:13:43 +01:00
parisc parisc: Fix double SIGFPE crash 2025-05-09 09:43:50 +02:00
powerpc powerpc/vas: Return -EINVAL if the offset is non-zero in mmap() 2025-06-19 15:28:40 +02:00
riscv RISC-V: KVM: lock the correct mp_state during reset 2025-06-19 15:28:18 +02:00
s390 s390/bpf: Store backchain even for leaf progs 2025-06-19 15:28:15 +02:00
sh sh: cpuinfo: Fix a warning for CONFIG_CPUMASK_OFFSTACK 2024-12-09 10:32:50 +01:00
sparc sparc/mm: avoid calling arch_enter/leave_lazy_mmu() in set_ptes 2025-04-25 10:45:30 +02:00
um um: let 'make clean' properly clean underlying SUBARCH as well 2025-06-04 14:42:25 +02:00
x86 x86/iopl: Cure TIF_IO_BITMAP inconsistencies 2025-06-19 15:28:46 +02:00
xtensa of/fdt: add dt_phys arg to early_init_dt_scan and early_init_dt_verify 2024-12-09 10:31:56 +01:00
.gitignore
Kconfig Revert "mm: mmap: allow for the maximum number of bits for randomizing mmap_base by default" 2024-06-27 13:49:15 +02:00