Conversation
…ath argument When fs_watch() is called with a non-null path, the else branch incorrectly calls trace_file_init() instead of mountsnoop_init(). This is a copy-paste error from file_watch(). The correct behavior is to initialize mountsnoop for filesystem event monitoring. Signed-off-by: JoeSergen <jxq142857@163.com>
|
你好,这是对 libdkapture#112 fix: fs_watch calls trace_file_init instead of mountsnoop_in 的评审。 本轮为 DKapture 两仓(libdkapture / dkapture-bpf)全部以 fix 开头 open PR 的批量评审,共 17 个;汇总表如下,本 PR 加粗。逐项详评见分隔线下方。
本 PR 评审详情作者: JoeSergen | 规模: +1/-1 | 文件: 1 总体结论: fs_watch(path) 带 path 的 else 分支原先调用 trace_file_init(3,...),与同函数另外两个分支(cb 为空调用 mountsnoop_deinit、path 为空调用 mountsnoop_init(1,...),so/dkapture.cpp:374,380 仓库行号)不一致。改为 mountsnoop_init(3, {"dkapture","-p",path},...) 正确:mountsnoop_init 在 BUILTIN 模式下存在(observe/mountsnoop.cpp:471),签名与 dkapture.cpp:364-369 的前置声明一致(DKapture::DKCallback);且 mountsnoop 的 -p 选项实际是路径过滤而非 PID 过滤(observe/mountsnoop.cpp:81-88 解析进 filter_path,:533 写入 "filter" map;BPF 侧 repos/dkapture-bpf/observe/mountsnoop.bpf.c:44-56 用其匹配 mount 的 source/target),传入文件系统路径语义自洽。 主要问题: 无
亮点:
commit message: 符合规范(fix: 标题 + 根因正文 + Signed-off-by) |
Summary
Fix copy-paste bug in
so/dkapture.cppwherefs_watch()calledtrace_file_init()instead ofmountsnoop_init()in its path-specific else branch.Root Cause
This is a copy-paste error from
file_watch(). The developer correctly changed the deinit and null-path branches tomountsnoop_*, but the else branch was missed.Why
mountsnoop_initis Correctfs_watchmonitors filesystem-level mount/umount events, not per-file I/O. Evidence from the BPF kernel side:mountsnoop_init — Filesystem Event Monitoring
User-space (
observe/mountsnoop.cpp): The-pargument is stored as a path prefix and written to a BPFchar[4096]array map.Kernel-space (
bpf/observe/mountsnoop.bpf.c:44-60):filter_path()performs path prefix matching against mount source/target paths:Monitored events:
sys_enter_mount,sys_enter_umount,fsopen,fsmount,move_mount, etc. — all filesystem-level syscalls.trace_file_init — Per-File I/O Monitoring
User-space (
observe/trace-file.cpp:1206-1212): The-pargument is used toopen()+fstat()the file, resolving it to an inode:Kernel-space (
bpf/observe/trace-file.bpf.c:128-146):find_file_inodematches by inode+dev:Monitored events:
vfs_open,vfs_read,vfs_write,vfs_chmod,vfs_chown,vfs_removexattr— all per-file I/O operations.Semantic Mismatch
-psemanticsfexit/vfs_*file opstracepoint/.../sys_enter_mountetc.Calling
trace_file_initfromfs_watchwould open the given path as a regular file, resolve its inode, and attach VFS-level file I/O hooks — completely unrelated to filesystem event monitoring.Changes
so/dkapture.cpp:388: Changedtrace_file_inittomountsnoop_init(1 line)Verification
int(int argc, char** argv, DKCallback cb, void* ctx)Closes #111