My kernel version is 6.8
and the ftrace callback function looks like:
(We set USE_FENTRY_OFFSET to zero, prevent ftrace recursive by checking the address)
static void notrace ftrace_callback_handler(unsigned long ip, unsigned long parent_ip,
struct ftrace_ops *ops, struct ftrace_regs *fregs)
{
struct pt_regs *regs = ftrace_get_regs(fregs);
struct ftrace_hook *hook = container_of(ops, struct ftrace_hook, ops);
#if USE_FENTRY_OFFSET
regs->ip = (unsigned long)hook->function;
#else
if (!within_module(parent_ip, THIS_MODULE)){
LOG_DEBUG("not true within_module(parent_ip, THIS_MODULE)");
regs->ip = (unsigned long)hook->function;
} else {
LOG_DEBUG("true within_module(parent_ip, THIS_MODULE)");
}
#endif //USE_FENTRY_OFFSET
}
But a little bit weird thing is in kernel v6.6 and v6.8
when we enter the callback function within_module(parent_ip, THIS_MODULE)
always return false
This make the infinity loop in ftrace, but the same code works on kernel v5.15
I found the related kernel commit is about module layout
I am not sure is this commit makes checking by address does not work anymore?
If somebody can give me another solution to avoid go into infinity loop?