ftrace: Fix issue that 'direct->addr' not restored in modify_ftrace_direct()
commit2a2d8c51deupstream. 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@huawei.com Cc: stable@vger.kernel.org Cc: <mhiramat@kernel.org> Cc: <mark.rutland@arm.com> Cc: <ast@kernel.org> Cc: <daniel@iogearbox.net> Fixes:8a141dd7f7("ftrace: Fix modify_ftrace_direct.") Signed-off-by: Zheng Yejian <zhengyejian1@huawei.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
eadcad0a47
commit
f018ef34c4
@@ -5390,12 +5390,15 @@ int modify_ftrace_direct(unsigned long ip,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlikely(ret && new_direct)) {
|
if (ret) {
|
||||||
direct->count++;
|
direct->addr = old_addr;
|
||||||
list_del_rcu(&new_direct->next);
|
if (unlikely(new_direct)) {
|
||||||
synchronize_rcu_tasks();
|
direct->count++;
|
||||||
kfree(new_direct);
|
list_del_rcu(&new_direct->next);
|
||||||
ftrace_direct_func_count--;
|
synchronize_rcu_tasks();
|
||||||
|
kfree(new_direct);
|
||||||
|
ftrace_direct_func_count--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out_unlock:
|
out_unlock:
|
||||||
|
|||||||
Reference in New Issue
Block a user