fs/proc: do_task_stat: use sig->stats_lock to gather the threads/children stats
authorOleg Nesterov <oleg@redhat.com>
Tue, 23 Jan 2024 15:33:57 +0000 (16:33 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 8 Feb 2024 05:20:33 +0000 (21:20 -0800)
commit7601df8031fd67310af891897ef6cc0df4209305
treeede6b84c438d11b00d632086a15ca3900c98671e
parent60f92acb60a989b14e4b744501a0df0f82ef30a3
fs/proc: do_task_stat: use sig->stats_lock to gather the threads/children stats

lock_task_sighand() can trigger a hard lockup.  If NR_CPUS threads call
do_task_stat() at the same time and the process has NR_THREADS, it will
spin with irqs disabled O(NR_CPUS * NR_THREADS) time.

Change do_task_stat() to use sig->stats_lock to gather the statistics
outside of ->siglock protected section, in the likely case this code will
run lockless.

Link: https://lkml.kernel.org/r/20240123153357.GA21857@redhat.com
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Dylan Hatch <dylanbhatch@google.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/proc/array.c