[for-next][PATCH 03/21] tracing: Fix sched switch start/stop refcount racy updates

From: Steven Rostedt
Date: Thu Jan 30 2020 - 09:48:14 EST


From: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>

Reading the sched_cmdline_ref and sched_tgid_ref initial state within
tracing_start_sched_switch without holding the sched_register_mutex is
racy against concurrent updates, which can lead to tracepoint probes
being registered more than once (and thus trigger warnings within
tracepoint.c).

[ May be the fix for this bug ]
Link: https://lore.kernel.org/r/000000000000ab6f84056c786b93@xxxxxxxxxx

Link: http://lkml.kernel.org/r/20190817141208.15226-1-mathieu.desnoyers@xxxxxxxxxxxx

Cc: stable@xxxxxxxxxxxxxxx
CC: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx>
CC: Joel Fernandes (Google) <joel@xxxxxxxxxxxxxxxxx>
CC: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
CC: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
CC: Paul E. McKenney <paulmck@xxxxxxxxxxxxx>
Reported-by: syzbot+774fddf07b7ab29a1e55@xxxxxxxxxxxxxxxxxxxxxxxxx
Fixes: d914ba37d7145 ("tracing: Add support for recording tgid of tasks")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Signed-off-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx>
---
kernel/trace/trace_sched_switch.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace_sched_switch.c b/kernel/trace/trace_sched_switch.c
index e288168661e1..e304196d7c28 100644
--- a/kernel/trace/trace_sched_switch.c
+++ b/kernel/trace/trace_sched_switch.c
@@ -89,8 +89,10 @@ static void tracing_sched_unregister(void)

static void tracing_start_sched_switch(int ops)
{
- bool sched_register = (!sched_cmdline_ref && !sched_tgid_ref);
+ bool sched_register;
+
mutex_lock(&sched_register_mutex);
+ sched_register = (!sched_cmdline_ref && !sched_tgid_ref);

switch (ops) {
case RECORD_CMDLINE:
--
2.24.1