This is a note to let you know that I've just added the patch titled ftrace: Fix issue that 'direct->addr' not restored in modify_ftrace_direct() to the 5.10-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: ftrace-fix-issue-that-direct-addr-not-restored-in-modify_ftrace_direct.patch and it can be found in the queue-5.10 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 2a2d8c51defb446e8d89a83f42f8e5cd529111e9 Mon Sep 17 00:00:00 2001 From: Zheng Yejian <zhengyejian1@xxxxxxxxxx> Date: Thu, 30 Mar 2023 10:52:23 +0800 Subject: ftrace: Fix issue that 'direct->addr' not restored in modify_ftrace_direct() From: Zheng Yejian <zhengyejian1@xxxxxxxxxx> commit 2a2d8c51defb446e8d89a83f42f8e5cd529111e9 upstream. Syzkaller report a WARNING: "WARN_ON(!direct)" in modify_ftrace_direct(). Root cause is 'direct->addr' was changed from 'old_addr' to 'new_addr' but not restored if error happened on calling ftrace_modify_direct_caller(). Then it can no longer find 'direct' by that 'old_addr'. To fix it, restore 'direct->addr' to 'old_addr' explicitly in error path. Link: https://lore.kernel.org/linux-trace-kernel/20230330025223.1046087-1-zhengyejian1@xxxxxxxxxx Cc: stable@xxxxxxxxxxxxxxx Cc: <mhiramat@xxxxxxxxxx> Cc: <mark.rutland@xxxxxxx> Cc: <ast@xxxxxxxxxx> Cc: <daniel@xxxxxxxxxxxxx> Fixes: 8a141dd7f706 ("ftrace: Fix modify_ftrace_direct.") Signed-off-by: Zheng Yejian <zhengyejian1@xxxxxxxxxx> Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- kernel/trace/ftrace.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -5390,12 +5390,15 @@ int modify_ftrace_direct(unsigned long i ret = 0; } - if (unlikely(ret && new_direct)) { - direct->count++; - list_del_rcu(&new_direct->next); - synchronize_rcu_tasks(); - kfree(new_direct); - ftrace_direct_func_count--; + if (ret) { + direct->addr = old_addr; + if (unlikely(new_direct)) { + direct->count++; + list_del_rcu(&new_direct->next); + synchronize_rcu_tasks(); + kfree(new_direct); + ftrace_direct_func_count--; + } } out_unlock: Patches currently in stable-queue which might be from zhengyejian1@xxxxxxxxxx are queue-5.10/ftrace-fix-issue-that-direct-addr-not-restored-in-modify_ftrace_direct.patch