Skip to content

Commit

Permalink
tracepoint: Fix race between tracing and removing tracepoint
Browse files Browse the repository at this point in the history
When executing a tracepoint, the tracepoint's func is dereferenced twice -
in __DO_TRACE() (where the returned pointer is checked) and later on in
__traceiter_##_name where the returned pointer is dereferenced without
checking which leads to races against tracepoint_removal_sync() and
crashes.

This adds a check before referencing the pointer in tracepoint_ptr_deref.

Link: https://lkml.kernel.org/r/[email protected]

Cc: [email protected]
Fixes: d25e37d ("tracepoint: Optimize using static_call()")
Acked-by: Peter Zijlstra (Intel) <[email protected]>
Signed-off-by: Alexey Kardashevskiy <[email protected]>
Signed-off-by: Steven Rostedt (VMware) <[email protected]>
  • Loading branch information
aik authored and rostedt committed Feb 2, 2021
1 parent 0188b87 commit c8b186a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions include/linux/tracepoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,13 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
\
it_func_ptr = \
rcu_dereference_raw((&__tracepoint_##_name)->funcs); \
do { \
it_func = (it_func_ptr)->func; \
__data = (it_func_ptr)->data; \
((void(*)(void *, proto))(it_func))(__data, args); \
} while ((++it_func_ptr)->func); \
if (it_func_ptr) { \
do { \
it_func = (it_func_ptr)->func; \
__data = (it_func_ptr)->data; \
((void(*)(void *, proto))(it_func))(__data, args); \
} while ((++it_func_ptr)->func); \
} \
return 0; \
} \
DEFINE_STATIC_CALL(tp_func_##_name, __traceiter_##_name);
Expand Down

0 comments on commit c8b186a

Please sign in to comment.