linux-stable/arch/powerpc
Jens Axboe 064a1c7b0f powerpc: Don't try to copy PPR for task with NULL pt_regs
commit fd72761894 upstream.

powerpc sets up PF_KTHREAD and PF_IO_WORKER with a NULL pt_regs, which
from my (arguably very short) checking is not commonly done for other
archs. This is fine, except when PF_IO_WORKER's have been created and
the task does something that causes a coredump to be generated. Then we
get this crash:

  Kernel attempted to read user page (160) - exploit attempt? (uid: 1000)
  BUG: Kernel NULL pointer dereference on read at 0x00000160
  Faulting instruction address: 0xc0000000000c3a60
  Oops: Kernel access of bad area, sig: 11 [#1]
  LE PAGE_SIZE=64K MMU=Radix SMP NR_CPUS=32 NUMA pSeries
  Modules linked in: bochs drm_vram_helper drm_kms_helper xts binfmt_misc ecb ctr syscopyarea sysfillrect cbc sysimgblt drm_ttm_helper aes_generic ttm sg libaes evdev joydev virtio_balloon vmx_crypto gf128mul drm dm_mod fuse loop configfs drm_panel_orientation_quirks ip_tables x_tables autofs4 hid_generic usbhid hid xhci_pci xhci_hcd usbcore usb_common sd_mod
  CPU: 1 PID: 1982 Comm: ppc-crash Not tainted 6.3.0-rc2+ #88
  Hardware name: IBM pSeries (emulated by qemu) POWER9 (raw) 0x4e1202 0xf000005 of:SLOF,HEAD hv:linux,kvm pSeries
  NIP:  c0000000000c3a60 LR: c000000000039944 CTR: c0000000000398e0
  REGS: c0000000041833b0 TRAP: 0300   Not tainted  (6.3.0-rc2+)
  MSR:  800000000280b033 <SF,VEC,VSX,EE,FP,ME,IR,DR,RI,LE>  CR: 88082828  XER: 200400f8
  ...
  NIP memcpy_power7+0x200/0x7d0
  LR  ppr_get+0x64/0xb0
  Call Trace:
    ppr_get+0x40/0xb0 (unreliable)
    __regset_get+0x180/0x1f0
    regset_get_alloc+0x64/0x90
    elf_core_dump+0xb98/0x1b60
    do_coredump+0x1c34/0x24a0
    get_signal+0x71c/0x1410
    do_notify_resume+0x140/0x6f0
    interrupt_exit_user_prepare_main+0x29c/0x320
    interrupt_exit_user_prepare+0x6c/0xa0
    interrupt_return_srr_user+0x8/0x138

Because ppr_get() is trying to copy from a PF_IO_WORKER with a NULL
pt_regs.

Check for a valid pt_regs in both ppc_get/ppr_set, and return an error
if not set. The actual error value doesn't seem to be important here, so
just pick -EINVAL.

Fixes: fa439810cc ("powerpc/ptrace: Enable support for NT_PPPC_TAR, NT_PPC_PPR, NT_PPC_DSCR")
Cc: stable@vger.kernel.org # v4.8+
Signed-off-by: Jens Axboe <axboe@kernel.dk>
[mpe: Trim oops in change log, add Fixes & Cc stable]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/d9f63344-fe7c-56ae-b420-4a1a04a2ae4c@kernel.dk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-04-06 12:10:53 +02:00
..
boot powerpc/boot: Don't always pass -mcpu=powerpc when building 32-bit uImage 2023-03-22 13:34:03 +01:00
configs - Yu Zhao's Multi-Gen LRU patches are here. They've been under test in 2022-10-10 17:53:04 -07:00
crypto treewide: use get_random_bytes() when possible 2022-10-11 17:42:58 -06:00
include powerpc/64: Move paca allocation to early_setup() 2023-03-17 08:50:31 +01:00
kernel powerpc: Don't try to copy PPR for task with NULL pt_regs 2023-04-06 12:10:53 +02:00
kexec powerpc/64/kdump: Limit kdump base to 512MB 2022-09-28 19:22:09 +10:00
kvm KVM: PPC: BookS PR-KVM and BookE do not support context tracking 2022-10-18 22:46:19 +11:00
lib powerpc: Fix reschedule bug in KUAP-unlocked user copy 2022-10-18 22:46:19 +11:00
math-emu powerpc/math-emu: Inhibit W=1 warnings 2022-09-08 11:11:18 +10:00
mm powerpc/mm: Fix false detection of read faults 2023-03-22 13:33:47 +01:00
net powerpc/bpf/32: Only set a stack frame when necessary 2023-03-17 08:50:30 +01:00
perf powerpc/imc-pmu: Revert nest_init_lock to being a mutex 2023-02-09 11:28:26 +01:00
platforms powerpc/64: Replace -mcpu=e500mc64 by -mcpu=e5500 2023-03-22 13:34:07 +01:00
purgatory powerpc/purgatory: Omit use of bin2c 2022-07-27 21:36:03 +10:00
sysdev powerpc/xive: add missing iounmap() in error path in xive_spapr_populate_irq_data() 2022-12-31 13:32:50 +01:00
tools
xmon powerpc/xmon: Fix -Wswitch-unreachable warning in bpt_cmds 2022-12-31 13:32:50 +01:00
Kbuild
Kconfig powerpc: Don't select ARCH_WANTS_NO_INSTR 2023-03-03 11:52:21 +01:00
Kconfig.debug powerpc: Add support for early debugging via Serial 16550 console 2022-09-28 19:22:09 +10:00
Makefile powerpc: Pass correct CPU reference to assembler 2023-03-22 13:34:05 +01:00
Makefile.postlink