linux-stable/arch/csky
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
..
abiv1 mm: Introduce flush_cache_vmap_early() 2024-02-16 19:10:52 +01:00
abiv2 mm: Introduce flush_cache_vmap_early() 2024-02-16 19:10:52 +01:00
boot csky: Remove unused $(dtb-y) from boot/Makefile 2022-05-13 14:45:09 +08:00
configs csky: Minimize defconfig to support buildroot config.fragment 2020-02-21 15:43:25 +08:00
include work around gcc bugs with 'asm goto' with outputs 2024-02-23 09:24:47 +01:00
kernel kprobe/ftrace: bail out if ftrace was killed 2024-06-27 13:49:03 +02:00
lib csky: delay: Add function alignment 2022-12-29 23:47:52 -05:00
mm csky: fix up lock_mm_and_find_vma() conversion 2023-06-29 23:34:29 -07:00
Kbuild csky: Move $(core-y) into arch/csky/Kbuild 2022-05-13 15:09:28 +08:00
Kconfig Merge branch 'expand-stack' 2023-06-28 20:35:21 -07:00
Kconfig.debug treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Kconfig.platforms csky/Kconfig: Add Kconfig.platforms to support some drivers 2020-02-21 15:43:24 +08:00
Makefile kbuild: remove head-y syntax 2022-10-02 18:06:03 +09:00