Skip to content

Commit

Permalink
tracepoint: Fix use of tracepoint funcs after rcu free
Browse files Browse the repository at this point in the history
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/[email protected]
Link: http://lkml.kernel.org/p/[email protected]

Reported-by: Sasha Levin <[email protected]>
CC: Oleg Nesterov <[email protected]>
CC: Dave Jones <[email protected]>
Fixes: de7b297 "tracepoint: Use struct pointer instead of name hash for reg/unreg tracepoints"
Signed-off-by: Mathieu Desnoyers <[email protected]>
Signed-off-by: Steven Rostedt <[email protected]>
  • Loading branch information
compudj authored and rostedt committed May 8, 2014
1 parent 098507a commit 8058bd0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kernel/tracepoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ static int tracepoint_add_func(struct tracepoint *tp,
WARN_ON_ONCE(1);
return PTR_ERR(old);
}
release_probes(old);

/*
* rcu_assign_pointer has a smp_wmb() which makes sure that the new
Expand All @@ -200,6 +199,7 @@ static int tracepoint_add_func(struct tracepoint *tp,
rcu_assign_pointer(tp->funcs, tp_funcs);
if (!static_key_enabled(&tp->key))
static_key_slow_inc(&tp->key);
release_probes(old);
return 0;
}

Expand All @@ -221,7 +221,6 @@ static int tracepoint_remove_func(struct tracepoint *tp,
WARN_ON_ONCE(1);
return PTR_ERR(old);
}
release_probes(old);

if (!tp_funcs) {
/* Removed last function */
Expand All @@ -232,6 +231,7 @@ static int tracepoint_remove_func(struct tracepoint *tp,
static_key_slow_dec(&tp->key);
}
rcu_assign_pointer(tp->funcs, tp_funcs);
release_probes(old);
return 0;
}

Expand Down

0 comments on commit 8058bd0

Please sign in to comment.