Hi,
Here is v3 of the remaining bug fixes for kprobes and optprobes.
The previous version is here:
https://lore.kernel.org/all/179427358690.291326.2078291446658598883.stgit@devnote2/ (local)
This version restores __arm_kprobe() fix as patch 3, and update the KUnit
test code to check it.
This includes following fixes.
1. Ftrace Ops Switching for Post-Handlers (Patch 1):
- When adding a second probe with a post_handler to an existing ftrace
kprobe, the aggregate probe's post_handler was set but remained armed
on kprobe_ftrace_ops. Subsequent disarming attempted to disarm from
kprobe_ipmodify_ops, failing with -ENOENT and leaking the armed probe.
Switch ftrace ops safely in register_aggr_kprobe() outside of
text_mutex and cpus_read_lock.
2. Optprobe State Machine & Tasks RCU Quiescence (Patches 2-4):
- Forcibly unoptimized probes (unoptimize_kprobe(force = true)) were
not queued to cooling_list, causing kprobe_disarmed() to return true
prematurely and risking use-after-free in the optinsn detour buffer
before Tasks RCU completed.
- When re-arming a probe that is queued on unoptimizing_list before the
optimizer thread runs, skip arch_arm_kprobe() in __arm_kprobe() so
the active jump instruction is not overwritten with a breakpoint.
- When a disabled cooling probe finishes cooling and transitions to
safely disarmed in optprobe_finalize_generation(), re-optimize any
blocked sibling probe whose jump range covers its address.
3. KUnit Regression Tests (Patch 5):
- Add KUnit test cases to lib/tests/test_kprobes.c covering the recent
kprobes, kretprobes, ftrace ops, and optprobe fixes.
Changes in v3:
[03/05]
- Restore the __arm_kprobe() fix that was accidentally dropped in v2
while omitting the reuse_unused_kprobe() hunk superseded by commit
1ffd6efb1b58 ("kprobes: Arm reused optprobe on cooling list").
[05/05]
- Check that the jump opcode at *opt_kp.addr is preserved across
disable_kprobe() and enable_kprobe() in
test_optprobe_rearm_unoptimizing().
Thank you,
---
base-commit: 1ffd6efb1b58e596ed70f660182803264a4c84d9
Masami Hiramatsu (Google) (5):
kprobes: Switch ftrace ops when adding probe with post_handler
kprobes: Fix UAF and queue cooling probes on forced unoptimization
kprobes: Do not overwrite jump instruction when re-arming unoptimizing probe
kprobes: Re-optimize blocked sibling probe when cooling finishes
kprobes: Add KUnit test cases for kprobes regressions
kernel/kprobes.c | 116 +++++++++++++++++++++++++++-----------
lib/tests/test_kprobes.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 220 insertions(+), 35 deletions(-)
--
Masami Hiramatsu (Google) [off-list ref]