linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] tracing: Fix syscall tracepoint use-after-free
@ 2024-10-22 15:18 Mathieu Desnoyers
  2024-10-22 16:14 ` Jordan Rife
  0 siblings, 1 reply; 21+ messages in thread
From: Mathieu Desnoyers @ 2024-10-22 15:18 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: linux-kernel, Mathieu Desnoyers, syzbot+b390c8062d8387b6272a,
	Michael Jeanson, Masami Hiramatsu, Peter Zijlstra,
	Alexei Starovoitov, Yonghong Song, Paul E . McKenney, Ingo Molnar,
	Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
	Namhyung Kim, Andrii Nakryiko, bpf, Joel Fernandes, Jordan Rife

The grace period used internally within tracepoint.c:release_probes()
uses call_rcu() to batch waiting for quiescence of old probe arrays,
rather than using the tracepoint_synchronize_unregister() which blocks
while waiting for quiescence.

This causes use-after-free issues reproduced with syzkaller.

Fix this by introducing the following call_rcu chaining:

   call_rcu() -> rcu_free_old_probes -> call_rcu_tasks_trace() -> rcu_tasks_trace_free_old_probes.

Just like it was done when SRCU was used.

Reported-by: syzbot+b390c8062d8387b6272a@syzkaller.appspotmail.com
Fixes: a363d27cdbc2 ("tracing: Allow system call tracepoints to handle page faults")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Michael Jeanson <mjeanson@efficios.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Yonghong Song <yhs@fb.com>
Cc: Paul E. McKenney <paulmck@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org
Cc: Joel Fernandes <joel@joelfernandes.org>
Cc: Jordan Rife <jrife@google.com>
---
 kernel/tracepoint.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
index 6474e2cf22c9..33f6fa94d383 100644
--- a/kernel/tracepoint.c
+++ b/kernel/tracepoint.c
@@ -101,11 +101,16 @@ static inline void *allocate_probes(int count)
 	return p == NULL ? NULL : p->probes;
 }
 
-static void rcu_free_old_probes(struct rcu_head *head)
+static void rcu_tasks_trace_free_old_probes(struct rcu_head *head)
 {
 	kfree(container_of(head, struct tp_probes, rcu));
 }
 
+static void rcu_free_old_probes(struct rcu_head *head)
+{
+	call_rcu_tasks_trace(head, rcu_tasks_trace_free_old_probes);
+}
+
 static inline void release_probes(struct tracepoint_func *old)
 {
 	if (old) {
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2024-10-25 20:19 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-22 15:18 [RFC PATCH] tracing: Fix syscall tracepoint use-after-free Mathieu Desnoyers
2024-10-22 16:14 ` Jordan Rife
2024-10-22 17:54   ` Mathieu Desnoyers
2024-10-22 19:53     ` Andrii Nakryiko
2024-10-22 20:04       ` Mathieu Desnoyers
2024-10-23  0:20         ` Steven Rostedt
2024-10-23  1:11           ` Mathieu Desnoyers
2024-10-23  1:24             ` Jordan Rife
2024-10-23 14:56               ` Jordan Rife
2024-10-23 15:13                 ` Mathieu Desnoyers
2024-10-24  0:40                   ` Steven Rostedt
2024-10-23 15:14                 ` Alexei Starovoitov
2024-10-23 15:19                   ` Mathieu Desnoyers
2024-10-24  1:28                     ` Alexei Starovoitov
2024-10-24  2:05                     ` Steven Rostedt
2024-10-24 17:12                       ` Jordan Rife
2024-10-24 17:12                       ` Andrii Nakryiko
2024-10-24 17:50                         ` Jordan Rife
2024-10-24 18:18                         ` Mathieu Desnoyers
2024-10-25 15:01                         ` Jordan Rife
2024-10-25 20:19                           ` Andrii Nakryiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).