kprobes: Fixes for ftrace ops and optprobe state machine
Get series with b4
b4 am 179440640176.328088.17106877243326801914.stgit@devnote2Versions newest first · linked by author and title
- v3 Latest5 patches 1 replyIn review
- v24 patches 1 replySuperseded
- v18 patches 4 repliesSuperseded
Changes in v3 from the cover letter
[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().
Patches in v3 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/5 | kprobes: Switch ftrace ops when adding probe with post_handlerkernel/ | +45 | 0 replies | |
| 2/5 | kprobes: Fix UAF and queue cooling probes on forced unoptimizationkernel/ | +11 | 0 replies | |
| 3/5 | kprobes: Do not overwrite jump instruction when re-arming unoptimizing probekernel/ | +17 | 0 replies | |
| 4/5 | kprobes: Re-optimize blocked sibling probe when cooling finisheskernel/ | +8 | 0 replies | |
| 5/5 | kprobes: Add KUnit test cases for kprobes regressionslib/ | +139 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.
Cover letter [PATCH v3 0/5] kprobes: Fixes for ftrace ops and optprobe state machine
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/
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) <[email protected]>