Since commit 6650527444da ("proc: protect ptrace_may_access() with exec_update_lock (part 1)") do_task_stat() holds the exec_update_lock of the task from the access check until the last field is printed. In between it calls task_vsize() and without an MMU that takes the mmap lock to add up the vmas: locks held by stat-reader/46: #0: (&p->lock){+.+.}-{4:4}, at: seq_read_iter+0x38/0x32a #1: (&sig->exec_update_lock){++++}-{4:4}, at: do_task_stat+0x50/0xd04 #2: (&mm->mmap_lock){++++}-{4:4}, at: task_vsize+0x5e/0xd2 So a read of /proc//stat waits for the mmap lock with exec_update_lock held. And without an MMU the mmap lock can be held for a long time. A private mapping of a file is read into memory with it held for writing: locks held by holder/47: #0: (&mm->mmap_lock){++++}-{4:4}, at: vm_mmap_pgoff+0x56/0x136 #1: (nommu_region_sem){+.+.}-{4:4}, at: do_mmap+0x21e/0xb02 #2: (&sb->s_type->i_mutex_key#7){.+.+}-{4:4}, at: blkdev_read_iter+0xa6/0x1c0 The lock is only needed for the access check and for what is read from the task depending on it. The mm is pinned and everything else is shown to everyone anyway. So drop the lock once that is done and call task_vsize() afterwards. Signed-off-by: Christian Brauner (Amutable) --- fs/proc/array.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/proc/array.c b/fs/proc/array.c index f6f75d206762a..3ff6f2455e5e4 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -493,7 +493,6 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, permitted = ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS | PTRACE_MODE_NOAUDIT); mm = get_task_mm(task); if (mm) { - vsize = task_vsize(mm); /* * esp and eip are intentionally zeroed out. There is no * non-racy way to read them without freezing the task. @@ -543,6 +542,17 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, if (permitted && (!whole || num_threads < 2)) wchan = !task_is_running(task); + /* + * What depends on the access check has been read from the task or + * comes from the mm that was pinned along with it. Don't hold + * exec_update_lock for the rest, task_vsize() takes the mmap lock + * without an MMU. + */ + up_read(&task->signal->exec_update_lock); + + if (mm) + vsize = task_vsize(mm); + scoped_guard(rcu) { scoped_seqlock_read (&sig->stats_lock, ss_lock_irqsave) { cmin_flt = sig->cmin_flt; @@ -662,7 +672,6 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, seq_puts(m, " 0"); seq_putc(m, '\n'); - up_read(&task->signal->exec_update_lock); if (mm) mmput(mm); return 0; -- 2.53.0