Commit 229c4ef8ae56d69f8dec64533bf1c7f8070c1a4a

Authored by Oleg Nesterov
Committed by Ingo Molnar
1 parent b1792e3670

ftrace: do_each_pid_task() needs rcu lock

"ftrace: use struct pid" commit 978f3a45d9499c7a447ca7615455cefb63d44165
converted ftrace_pid_trace to "struct pid*".

But we can't use do_each_pid_task() without rcu_read_lock() even if
we know the pid itself can't go away (it was pinned in ftrace_pid_write).
The exiting task can detach itself from this pid at any moment.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

Showing 1 changed file with 5 additions and 0 deletions Side-by-side Diff

kernel/trace/ftrace.c
... ... @@ -1737,9 +1737,12 @@
1737 1737 {
1738 1738 struct task_struct *p;
1739 1739  
  1740 + rcu_read_lock();
1740 1741 do_each_pid_task(pid, PIDTYPE_PID, p) {
1741 1742 clear_tsk_trace_trace(p);
1742 1743 } while_each_pid_task(pid, PIDTYPE_PID, p);
  1744 + rcu_read_unlock();
  1745 +
1743 1746 put_pid(pid);
1744 1747 }
1745 1748  
1746 1749  
... ... @@ -1747,9 +1750,11 @@
1747 1750 {
1748 1751 struct task_struct *p;
1749 1752  
  1753 + rcu_read_lock();
1750 1754 do_each_pid_task(pid, PIDTYPE_PID, p) {
1751 1755 set_tsk_trace_trace(p);
1752 1756 } while_each_pid_task(pid, PIDTYPE_PID, p);
  1757 + rcu_read_unlock();
1753 1758 }
1754 1759  
1755 1760 static void clear_ftrace_pid_task(struct pid **pid)