Skip to content

Commit 08275e5

Browse files
committed
ftrace: Reinitialize hash to EMPTY_HASH after freeing
There's several locations that free a ftrace hash pointer but may be referenced again. Reset them to EMPTY_HASH so that a u-a-f bug doesn't happen. Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Link: https://lore.kernel.org/20250417110933.20ab718b@gandalf.local.home Fixes: 0ae6b8c ("ftrace: Fix accounting of subop hashes") Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 31d1139 commit 08275e5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

kernel/trace/ftrace.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,8 @@ void ftrace_free_filter(struct ftrace_ops *ops)
12971297
return;
12981298
free_ftrace_hash(ops->func_hash->filter_hash);
12991299
free_ftrace_hash(ops->func_hash->notrace_hash);
1300+
ops->func_hash->filter_hash = EMPTY_HASH;
1301+
ops->func_hash->notrace_hash = EMPTY_HASH;
13001302
}
13011303
EXPORT_SYMBOL_GPL(ftrace_free_filter);
13021304

@@ -3443,6 +3445,7 @@ static int add_next_hash(struct ftrace_hash **filter_hash, struct ftrace_hash **
34433445
size_bits);
34443446
if (ret < 0) {
34453447
free_ftrace_hash(*filter_hash);
3448+
*filter_hash = EMPTY_HASH;
34463449
return ret;
34473450
}
34483451
}
@@ -3472,6 +3475,7 @@ static int add_next_hash(struct ftrace_hash **filter_hash, struct ftrace_hash **
34723475
subops_hash->notrace_hash);
34733476
if (ret < 0) {
34743477
free_ftrace_hash(*notrace_hash);
3478+
*notrace_hash = EMPTY_HASH;
34753479
return ret;
34763480
}
34773481
}

0 commit comments

Comments
 (0)