In the Linux kernel, the following vulnerability has been resolved:
kprobes: Skip clearing aggrprobe's post_handler in kprobe-on-ftrace case
In _unregisterkprobetop(), if the currently unregistered probe has posthandler but other child probes of the aggrprobe do not have posthandler, the posthandler of the aggrprobe is cleared. If this is a ftrace-based probe, there is a problem. In later calls to disarmkprobe(), we will use kprobeftraceops because posthandler is NULL. But we're armed with kprobeipmodifyops. This triggers a WARN in _disarmkprobe_ftrace() and may even cause use-after-free:
Failed to disarm kprobe-ftrace at kernelclone+0x0/0x3c0 (error -2) WARNING: CPU: 5 PID: 137 at kernel/kprobes.c:1135 _disarmkprobeftrace.isra.21+0xcf/0xe0 Modules linked in: testKprobe007(-) CPU: 5 PID: 137 Comm: rmmod Not tainted 6.1.0-rc4-dirty #18 [...] Call Trace: <TASK> _disablekprobe+0xcd/0xe0 _unregisterkprobetop+0x12/0x150 ? mutexlock+0xe/0x30 unregisterkprobes.part.23+0x31/0xa0 unregisterkprobe+0x32/0x40 _x64sysdeletemodule+0x15e/0x260 ? douseraddrfault+0x2cd/0x6b0 dosyscall64+0x3a/0x90 entrySYSCALL64afterhwframe+0x63/0xcd [...]
For the kprobe-on-ftrace case, we keep the posthandler setting to identify this aggrprobe armed with kprobeipmodify_ops. This way we can disarm it correctly.