feat(uprobe): implement uprobe breakpoint support (#2150 phase 1) - #2163
Open
sparkzky wants to merge 2 commits into
Open
feat(uprobe): implement uprobe breakpoint support (#2150 phase 1)#2163sparkzky wants to merge 2 commits into
sparkzky wants to merge 2 commits into
Conversation
Member
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5c8c8a99c5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
sparkzky
force-pushed
the
feat/uprobe-uretprobe
branch
from
August 1, 2026 06:18
5c8c8a9 to
dbeea45
Compare
…#2150 phase 1) Implement userspace breakpoint probes (uprobe), phase 1 of issue DragonOS-Community#2150, enabling agentsight to instrument SSL_read/SSL_write entry points. The design is XOL-based rather than reusing kprobe's kernel-buffer single-step (impossible at CPL=3). Key pieces: - per-mm uprobe table guarded by an irqsave SpinLock (not the global KPROBE_MANAGER lock nor the mm RwSem; the #BP/#DB hit path is IRQ-off) - breakpoint page install replicates do_wp_page private COW: copy_page_as_normal + single atomic set_entry + rmap attach/detach + flush_tlb_range. No transient empty PTE; each mm gets a private copy so writeback never persists 0xcc into the shared page-cache (.so) - XOL: a per-mm user slot page executes the saved instruction copy with RIP-relative relocation (yaxpeax-x86), validated at registration time - do_int3/do_debug gain is_from_user() dispatch. The #BP handler runs pre_handler + BPF (rip kept as the original probe address), then jumps rip to the pre-filled XOL slot, sets TF and NEED_UPROBE. The #DB handler recognizes XOL completion via NEED_UPROBE and restores rip; unconsumed user #BP is delivered as SIGTRAP(TRAP_BRKPT) - perf: PERF_TYPE_MAX dispatches to uprobe when the name contains '/'; UprobePerfEvent mirrors KprobePerfEvent and reuses BPF_PROG_TYPE_KPROBE Delivered in four batches: uprobe crate (x86 instruction analysis), mm integration (per-mm table / XOL / breakpoint page), exception dispatch, and perf attach. Verified: `make kernel` builds with 0 error / 0 warning; `cargo test -p uprobe` passes 7/7. An independent reviewer confirmed the F1-F10 review findings are satisfied with no kprobe/fork regression, and flagged two bugs that are fixed: re-registering the same probe_vaddr no longer reads 0xcc as the original instruction, and a RIP-relative displacement overflow now fails fast at registration instead of panicking at hit time. Out of scope: uretprobe (phase 2) and the QEMU runtime integration test. Refs: DragonOS-Community#2150 test(uprobe): add dunitest suite for uprobe breakpoint probes Add suites/normal/uprobe.cc covering the userspace perf_event_open uprobe path (issue DragonOS-Community#2150 phase 1): - RegisterAndTriggerSurvivesHit: perf_event_open(type=PERF_TYPE_MAX, config1=path, config2=offset) on the current process, then call the probed function and assert it survives the #BP -> XOL -> #DB -> resume hit path and returns the correct value - InvalidPathIsRejected / InvalidOffsetIsRejected: error inputs return negative errno Target offset is resolved from /proc/self/maps (executable segment + file pgoff), so the suite works regardless of PIE layout. Compiles cleanly via `make build-suites`; the gtest framework runs (the two negative cases pass on host Linux; the core trigger case is DragonOS-specific and is validated at runtime under QEMU). Refs: DragonOS-Community#2150 fix(uprobe): resolve CI failures - format check and cross-arch build - Apply rustfmt to uprobe integration code (reorder modules, imports, line width) to pass format-check on all arches - Add #[cfg(target_arch = "x86_64")] gates to uprobe integration points (exception/perf/mm-ucontext modules, AddressSpace fields, fork path, perf dispatch arm) so riscv64/loongarch64 build succeeds - Non-x86_64 perf dispatch returns ENOSYS for uprobe paths - Fix unused_mut on phys_addr in fork path for non-x86_64
sparkzky
force-pushed
the
feat/uprobe-uretprobe
branch
from
August 1, 2026 06:26
dbeea45 to
db00ce5
Compare
- Thread 1: add ptrace access check (check_process_vm_access) before taking a target mm for cross-process uprobe, preventing unprivileged users from instrumenting arbitrary processes - Thread 2: reject control-flow instructions (call/jmp/ret/jcc/loop/int/ syscall) at registration time — XOL cannot safely single-step them - Thread 3: read_user_insn_bytes now continues into the next page when the probe is near a page boundary, returning real bytes instead of zero-padding that could decode to a different instruction - Thread 5: build_xol_slot fills trailing slot bytes with int3 (0xcc) so that a racy unregister during the XOL single-step window re-triggers #BP instead of executing zero-filled garbage
sparkzky
force-pushed
the
feat/uprobe-uretprobe
branch
from
August 1, 2026 07:31
3a99e3d to
86f1f09
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue
Refs #2150(阶段一:uprobe 断点探针)
概述
实现用户态断点探针(uprobe),使 agentsight 能在用户态函数(如
SSL_read/SSL_write)入口挂探针捕获参数。本 PR 完成阶段一(断点探针),命中路径#BP → XOL 单步 → #DB → 恢复端到端打通。设计决策
经盲区扫描 + 对抗评审纠正后的架构(关键点:不复用 kprobe 的内核缓冲区单步——CPL=3 时内核页不可执行):
KPROBE_MANAGER锁 / 非RwSem,命中路径关中断不可睡眠)do_wp_page私有 COW:copy_page_as_normal+ 单次set_entry原子帧替换 + rmap 账簿,每 mm 私有副本(writeback 不回写 0xcc 损坏 .so)do_int3/do_debug加is_from_user()二分;未消费用户态 #BP 投递SIGTRAP(TRAP_BRKPT)PERF_TYPE_MAX(6),按 config1 name 含/区分 uprobe/kprobe;复用BPF_PROG_TYPE_KPROBE改动文件
kernel/crates/uprobe/kernel/src/mm/ucontext/uprobe.rskernel/src/exception/uprobe.rskernel/src/perf/uprobe.rsinterrupt/{trap,mod}.rs、exception/mod.rs、mm/ucontext/{address_space,inner,mod}.rs、perf/mod.rs、process/state.rsuser/apps/tests/dunitest/suites/normal/uprobe.cc验证
make kernel:0 error / 0 warningcargo test -p uprobe:7/7 通过(指令长度、RIP-relative 检测/重定位、位移溢出)probe_vaddr读到 0xcc 当原指令 → 改为复用已有指令信息命中流程
flowchart TD A["用户态执行到 0xcc"] -->|"#BP"| B["do_int3: is_from_user?"] B -->|是| C["uprobe_breakpoint_handler\nlock uprobe_list(irqsave)"] C --> D["跑 pre_handler + BPF\nrip=原探针址"] D --> E["取 entries[0] XOL slot\n(slot 注册时已预填)"] E --> F["rip→XOL slot + TF + NEED_UPROBE"] F --> G["iretq: 用户态执行原指令"] G -->|"TF 触发 #DB"| H["uprobe_debug_handler\nNEED_UPROBE?"] H -->|是| I["rip 回原址+insn_len\n清 TF → post_handler"] I --> J["正常继续"]后续
sslsniff.bpf.c)