linux/arch/riscv
Stephen Brennan 1a7d0890dd kprobe/ftrace: bail out if ftrace was killed
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>
2024-05-16 07:23:30 +09:00
..
boot RISC-V Patches for the 6.9 Merge Window 2024-03-22 10:41:13 -07:00
configs RISC-V Patches for the 6.9 Merge Window 2024-03-22 10:41:13 -07:00
crypto crypto: riscv - add vector crypto accelerated AES-CBC-CTS 2024-03-20 08:56:11 -07:00
errata Merge patch series "RISC-V: Test th.sxstatus.MAEE bit before enabling MAEE" 2024-04-26 10:21:57 -07:00
include Merge patch series "RISC-V: Test th.sxstatus.MAEE bit before enabling MAEE" 2024-04-26 10:21:57 -07:00
kernel kprobe/ftrace: bail out if ftrace was killed 2024-05-16 07:23:30 +09:00
kvm RISC-V: KVM: Fix APLIC in_clrip[x] read emulation 2024-03-26 09:40:55 +05:30
lib RISC-V Patches for the 6.9 Merge Window 2024-03-22 10:41:13 -07:00
mm Merge patch the fixes from "riscv: 64-bit NOMMU fixes and enhancements" 2024-04-09 11:41:01 -07:00
net riscv, bpf: Fix kfunc parameters incompatibility between bpf and riscv abi 2024-03-25 11:39:31 -07:00
purgatory riscv: Use SYM_*() assembly macros instead of deprecated ones 2023-11-06 09:42:47 -08:00
tools riscv: Check relocations at compile time 2023-04-19 07:46:32 -07:00
Kbuild RISC-V: hook new crypto subdir into build-system 2024-01-22 17:55:17 -08:00
Kconfig RISC-V Patches for the 6.9 Merge Window 2024-03-22 10:41:13 -07:00
Kconfig.debug riscv: Add tests for riscv module loading 2023-11-07 14:59:32 -08:00
Kconfig.errata riscv: thead: Rename T-Head PBMT to MAE 2024-04-25 10:22:33 -07:00
Kconfig.socs riscv: dts: Move BUILTIN_DTB_SOURCE to common Kconfig 2024-03-06 00:08:32 +00:00
Makefile riscv: compat_vdso: install compat_vdso.so.dbg to /lib/modules/*/vdso/ 2024-03-26 14:08:02 -07:00
Makefile.postlink kbuild: remove ARCH_POSTLINK from module builds 2023-10-28 21:10:08 +09:00