rcu-tasks: Fix low-probability task_struct leak
authorPaul E. McKenney <paulmck@kernel.org>
Tue, 15 Sep 2020 21:03:34 +0000 (14:03 -0700)
committerPaul E. McKenney <paulmck@kernel.org>
Wed, 16 Sep 2020 23:32:38 +0000 (16:32 -0700)
commit592031cc10858be4adb10f6c0f2608f6f21824aa
treeb8c9f82cd7965585fdabc134c5c2c945e7c8050d
parentba3a86e47232ad9f76160929f33ac9c64e4d0567
rcu-tasks: Fix low-probability task_struct leak

When rcu_tasks_trace_postgp() function detects an RCU Tasks Trace
CPU stall, it adds all tasks blocking the current grace period to
a list, invoking get_task_struct() on each to prevent them from
being freed while on the list.  It then traverses that list,
printing stall-warning messages for each one that is still blocking
the current grace period and removing it from the list.  The list
removal invokes the matching put_task_struct().

This of course means that in the admittedly unlikely event that some
task executes its outermost rcu_read_unlock_trace() in the meantime, it
won't be removed from the list and put_task_struct() won't be executing,
resulting in a task_struct leak.  This commit therefore makes the list
removal and put_task_struct() unconditional, stopping the leak.

Note further that this bug can occur only after an RCU Tasks Trace CPU
stall warning, which by default only happens after a grace period has
extended for ten minutes (yes, not a typo, minutes).

Fixes: 4593e772b502 ("rcu-tasks: Add stall warnings for RCU Tasks Trace")
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: <bpf@vger.kernel.org>
Cc: <stable@vger.kernel.org> # 5.7.x
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
kernel/rcu/tasks.h