linux-stable/arch/powerpc
Stephen Brennan ae0d1ea3e8 kprobe/ftrace: bail out if ftrace was killed
[ Upstream commit 1a7d0890dd ]

If an error happens in ftrace, ftrace_kill() will prevent disarming
kprobes. Eventually, the ftrace_ops associated with the kprobes will be
freed, yet the kprobes will still be active, and when triggered, they
will use the freed memory, likely resulting in a page fault and panic.

This behavior can be reproduced quite easily, by creating a kprobe and
then triggering a ftrace_kill(). For simplicity, we can simulate an
ftrace error with a kernel module like [1]:

[1]: https://github.com/brenns10/kernel_stuff/tree/master/ftrace_killer

  sudo perf probe --add commit_creds
  sudo perf trace -e probe:commit_creds
  # In another terminal
  make
  sudo insmod ftrace_killer.ko  # calls ftrace_kill(), simulating bug
  # Back to perf terminal
  # ctrl-c
  sudo perf probe --del commit_creds

After a short period, a page fault and panic would occur as the kprobe
continues to execute and uses the freed ftrace_ops. While ftrace_kill()
is supposed to be used only in extreme circumstances, it is invoked in
FTRACE_WARN_ON() and so there are many places where an unexpected bug
could be triggered, yet the system may continue operating, possibly
without the administrator noticing. If ftrace_kill() does not panic the
system, then we should do everything we can to continue operating,
rather than leave a ticking time bomb.

Link: https://lore.kernel.org/all/20240501162956.229427-1-stephen.s.brennan@oracle.com/

Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Acked-by: Guo Ren <guoren@kernel.org>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-06-27 13:49:03 +02:00
..
boot powerpc: dts: add missing space before { 2023-08-25 08:39:30 +10:00
configs powerpc/ps3_defconfig: Disable PPC64_BIG_ENDIAN_ELF_ABI_V2 2024-01-31 16:18:49 -08:00
crypto powerpc/crypto/chacha-p10: Fix failure on non Power10 2024-05-17 12:02:18 +02:00
include powerpc/io: Avoid clang null pointer arithmetic warnings 2024-06-27 13:49:03 +02:00
kernel kprobe/ftrace: bail out if ftrace was killed 2024-06-27 13:49:03 +02:00
kexec powerpc/vmcore: Add MMU information to vmcoreinfo 2023-11-20 11:59:29 +01:00
kvm KVM: PPC: Book3S HV: Handle pending exceptions on guest entry with MSR_EE 2024-01-25 15:35:13 -08:00
lib powerpc: xor_vmx: Add '-mhard-float' to CFLAGS 2024-04-03 15:28:26 +02:00
math-emu
mm mm: fix race between __split_huge_pmd_locked() and GUP-fast 2024-06-16 13:47:40 +02:00
net powerpc/bpf: enforce full ordering for ATOMIC operations with BPF_FETCH 2024-06-16 13:47:48 +02:00
perf powerpc/hv-gpci: Fix the H_GET_PERF_COUNTER_INFO hcall return value checks 2024-03-26 18:19:54 -04:00
platforms powerpc/pseries/lparcfg: drop error message from guest name lookup 2024-06-12 11:12:59 +02:00
purgatory powerpc/purgatory: remove PGO flags 2023-06-12 11:31:50 -07:00
sysdev powerpc/fsl-soc: hide unused const variable 2024-06-12 11:11:59 +02:00
tools powerpc/ftrace: Add support for -fpatchable-function-entry 2023-08-22 00:09:06 +10:00
xmon TTY/Serial driver changes for 6.6-rc1 2023-09-01 09:38:00 -07:00
Kbuild
Kconfig powerpc/64s: Increase default stack size to 32KB 2024-01-25 15:35:42 -08:00
Kconfig.debug powerpc: allow PPC_EARLY_DEBUG_CPM only when SERIAL_CPM=y 2023-07-03 16:07:55 +10:00
Makefile powerpc/64s: Move CPU -mtune options into Kconfig 2023-08-25 08:39:29 +10:00
Makefile.postlink kbuild: remove --include-dir MAKEFLAG from top Makefile 2023-02-05 18:51:22 +09:00