From 2452eef0112aef133caeaebfaf34b34b9eebd572 Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Tue, 2 Dec 2003 20:59:12 -0800 Subject: [PATCH] [PATCH] Fix /proc access to dead thread group list oops The pid_alive() check within the loop is incorrect. If we are within the tasklist lock and the thread group leader is valid then the thread chain will be fully intact. Instead, the check should be _outside_ the loop, since if the group leader no longer exists, the whole list is gone and we must not try to access it. Move the check around, and add comment. Bug-hunting and fix by Srivatsa Vaddagiri --- fs/proc/base.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 3cc64eb275b1d..9da127ff6c4ff 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1666,10 +1666,14 @@ static int get_tid_list(int index, unsigned int *tids, struct inode *dir) index -= 2; read_lock(&tasklist_lock); - do { + /* + * The starting point task (leader_task) might be an already + * unlinked task, which cannot be used to access the task-list + * via next_thread(). + */ + if (pid_alive(task)) do { int tid = task->pid; - if (!pid_alive(task)) - continue; + if (--index >= 0) continue; tids[nr_tids] = tid; -- 2.53.0