Skip to content

Commit 8058bd0

Browse files
compudjrostedt
authored andcommitted
tracepoint: Fix use of tracepoint funcs after rcu free
Commit de7b297 "tracepoint: Use struct pointer instead of name hash for reg/unreg tracepoints" introduces a use after free by calling release_probes on the old struct tracepoint array before the newly allocated array is published with rcu_assign_pointer. There is a race window where tracepoints (RCU readers) can perform a "use-after-grace-period-after-free", which shows up as a GPF in stress-tests. Link: http://lkml.kernel.org/r/53698021.5020108@oracle.com Link: http://lkml.kernel.org/p/1399549669-25465-1-git-send-email-mathieu.desnoyers@efficios.com Reported-by: Sasha Levin <sasha.levin@oracle.com> CC: Oleg Nesterov <oleg@redhat.com> CC: Dave Jones <davej@redhat.com> Fixes: de7b297 "tracepoint: Use struct pointer instead of name hash for reg/unreg tracepoints" Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 098507a commit 8058bd0

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎kernel/tracepoint.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ static int tracepoint_add_func(struct tracepoint *tp,
188188
WARN_ON_ONCE(1);
189189
return PTR_ERR(old);
190190
}
191-
release_probes(old);
192191

193192
/*
194193
* rcu_assign_pointer has a smp_wmb() which makes sure that the new
@@ -200,6 +199,7 @@ static int tracepoint_add_func(struct tracepoint *tp,
200199
rcu_assign_pointer(tp->funcs, tp_funcs);
201200
if (!static_key_enabled(&tp->key))
202201
static_key_slow_inc(&tp->key);
202+
release_probes(old);
203203
return 0;
204204
}
205205

@@ -221,7 +221,6 @@ static int tracepoint_remove_func(struct tracepoint *tp,
221221
WARN_ON_ONCE(1);
222222
return PTR_ERR(old);
223223
}
224-
release_probes(old);
225224

226225
if (!tp_funcs) {
227226
/* Removed last function */
@@ -232,6 +231,7 @@ static int tracepoint_remove_func(struct tracepoint *tp,
232231
static_key_slow_dec(&tp->key);
233232
}
234233
rcu_assign_pointer(tp->funcs, tp_funcs);
234+
release_probes(old);
235235
return 0;
236236
}
237237

0 commit comments

Comments
 (0)