Skip to content

Commit 2a2d8c5

Browse files
Zheng Yejianrostedt
authored andcommitted
ftrace: Fix issue that 'direct->addr' not restored in modify_ftrace_direct()
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/[email protected] Cc: [email protected] Cc: <[email protected]> Cc: <[email protected]> Cc: <[email protected]> Cc: <[email protected]> Fixes: 8a141dd ("ftrace: Fix modify_ftrace_direct.") Signed-off-by: Zheng Yejian <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 3357c6e commit 2a2d8c5

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

kernel/trace/ftrace.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5667,12 +5667,15 @@ int modify_ftrace_direct(unsigned long ip,
56675667
ret = 0;
56685668
}
56695669

5670-
if (unlikely(ret && new_direct)) {
5671-
direct->count++;
5672-
list_del_rcu(&new_direct->next);
5673-
synchronize_rcu_tasks();
5674-
kfree(new_direct);
5675-
ftrace_direct_func_count--;
5670+
if (ret) {
5671+
direct->addr = old_addr;
5672+
if (unlikely(new_direct)) {
5673+
direct->count++;
5674+
list_del_rcu(&new_direct->next);
5675+
synchronize_rcu_tasks();
5676+
kfree(new_direct);
5677+
ftrace_direct_func_count--;
5678+
}
56765679
}
56775680

56785681
out_unlock:

0 commit comments

Comments
 (0)