v1
2026-07-15
动态硬件断点内存损坏检测 · v1
引入 mm/kwatch 机制,利用硬件 watchpoint 在内存写入时捕获损坏源头,补充 KASAN/KFENCE 无法检测的合法指针越界写问题。
原始补丁链接
子 Patch(13)
1/13
arch: add HAVE_REINSTALL_HW_BREAKPOINT
新增 HAVE_REINSTALL_HW_BREAKPOINT Kconfig 符号,允许架构在原子上下文中原地更新硬件断点,无需释放和重新分配槽位。
2/13
x86/hw_breakpoint: Unify breakpoint install/uninstall
重构 x86 硬件断点安装/卸载代码,减少重复并缩小代码体积,为引入 arch_reinstall_hw_breakpoint() 做准备。
3/13
x86/hw_breakpoint: Add arch_reinstall_hw_breakpoint
为 x86 实现 arch_reinstall_hw_breakpoint(),支持在原子上下文中原地更新断点,并在 setup_hwbp() 中清除旧 len/type 位避免合并错误。
4/13
HWBP: Add modify_wide_hw_breakpoint_local() API
新增 modify_wide_hw_breakpoint_local() API,允许在支持 HAVE_REINSTALL_HW_BREAKPOINT 的架构上在线更新断点地址,但限制类型兼容性。
5/13
mm/kwatch: add watch expression parser and dereference engine
实现 KWatch 的表达式解析器 kwatch_deref_parse() 和运行时解引用引擎 kwatch_deref_resolve(),支持基于函数参数和偏移链的地址追踪。
6/13
mm/kwatch: add lockless per-task context pool
为 KWatch 实现基于 cmpxchg 的无锁 per-task 上下文池,在 kprobe/NMI 上下文中无需分配或加锁即可管理窗口状态。
7/13
stacktrace: export stack_trace_save_regs()
导出 stack_trace_save_regs() 函数,使模块能从 pt_regs 捕获栈回溯,供 KWatch 记录断点触发时的调用栈。
8/13
mm/kwatch: add hardware breakpoint backend
On Wed, 15 Jul 2026 02:32:06 +0800 Jinchao Wang wangjinchao600@gmail.com wrote: > — /dev/null > +++ b/include/trace/events/kwatch.h > @@ -0,0 +1,57 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +
9/13
mm/kwatch: add probe lifecycle runtime
Open and close the watch window with a kretprobe on the target function: the entry handler tracks per-task nesting depth and, when the configured depth is reached, resolves the watch expression and ar
10/13
mm/kwatch: add anchor thread for global watchpoints
Global variables have no function whose execution can bound the watch window. Provide one: a kernel thread sleeps for the configured duration inside a dedicated noinline function, kwatch_global_anchor
11/13
mm/kwatch: add debugfs control plane
Wire the pieces together behind a single debugfs file, /sys/kernel/debug/kwatch/config. Writing a key=value configuration string stops any active session and starts a new one; reading shows the active
12/13
mm/kwatch: add KUnit tests for the watch expression parser
Cover base anchors (stack, argN, absolute address), positive and negative offsets, dereference chains, and rejection of malformed expressions (missing offsets, bad argument index, junk offsets). Sign
13/13
Documentation/dev-tools: document KWatch
Describe what KWatch is for, how it compares with KASAN and KFENCE, the debugfs configuration interface, the watch expression syntax, how to read hits from the trace buffer (including after a crash),