Skip to contentSkip to conversation

procfs: Fix listing of /proc/NOT_A_TGID/task

PATCH In review Guillaume Chazarain 2 participants 2 messages Jan 31, 2007 – Feb 1, 2007 Proc filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 procfs: Fix listing of /proc/NOT_A_TGID/task

Hi,

I think this is 2.6.20 material, if it gets appropriately reviewed ;-)

Thanks.

Signature · 1 line
Guillaume

Listing /proc/PID/task were PID is not a TGID should not result in duplicated entries.

[g ~]$ pidof thunderbird-bin
2751
[g ~]$ ls /proc/2751/task
2751 2770 2771 2824 2826 2834 2835 2851 2853 [g ~]$ ls /proc/2770/task

2751  2770  2771  2824  2826  2834  2835  2851  2853
2770  2771  2824  2826  2834  2835  2851  2853

[g ~]$

---

 fs/proc/base.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
fs/proc/base.c +11 -1
diff -r f99a8b402753 fs/proc/base.c
@@ -2328,13 +2328,23 @@ static int proc_task_readdir(struct file
 {
 	struct dentry *dentry = filp->f_path.dentry;
 	struct inode *inode = dentry->d_inode;
-	struct task_struct *leader = get_proc_task(inode);
+	struct task_struct *leader = NULL;
 	struct task_struct *task;
 	int retval = -ENOENT;
 	ino_t ino;
 	int tid;
 	unsigned long pos = filp->f_pos;  /* avoiding "long long" filp->f_pos */
 
+	task = get_proc_task(inode);
+	if (!task)
+		goto out_no_task;
+	rcu_read_lock();
+	if (pid_alive(task)) {
+		leader = task->group_leader;
+		get_task_struct(leader);
+	}
+	rcu_read_unlock();
+	put_task_struct(task);
 	if (!leader)
 		goto out_no_task;
 	retval = 0;
#1 lore raw
Quoted 3 lines · Guillaume Chazarain

Hi,

I think this is 2.6.20 material, if it gets appropriately reviewed ;-)

Look good to me.

Lookup doesn't have this problem because it only tests for tgid. I'm not certain at the moment if we need the rcu_read_lock, and pid_alive checks, but at worst they are overkill.

Quoted 51 lines

Thanks.

Signature · 21 lines
Guillaume

Listing /proc/PID/task were PID is not a TGID
should not result in duplicated entries.

[g ~]$ pidof thunderbird-bin
2751
[g ~]$ ls /proc/2751/task
2751  2770  2771  2824  2826  2834  2835  2851  2853
[g ~]$ ls /proc/2770/task
2751  2770  2771  2824  2826  2834  2835  2851  2853
2770  2771  2824  2826  2834  2835  2851  2853
[g ~]$ 

Signed-off-by: Guillaume Chazarain <[email protected]>
---

 fs/proc/base.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff -r f99a8b402753 fs/proc/base.c
fs/proc/base.c +11 -1
@@ -2328,13 +2328,23 @@ static int proc_task_readdir(struct file
 {
 	struct dentry *dentry = filp->f_path.dentry;
 	struct inode *inode = dentry->d_inode;
-	struct task_struct *leader = get_proc_task(inode);
+	struct task_struct *leader = NULL;
 	struct task_struct *task;
 	int retval = -ENOENT;
 	ino_t ino;
 	int tid;
 	unsigned long pos = filp->f_pos; /* avoiding "long long" filp->f_pos */
 
+	task = get_proc_task(inode);
+	if (!task)
+		goto out_no_task;
+	rcu_read_lock();
+	if (pid_alive(task)) {
+		leader = task->group_leader;
+		get_task_struct(leader);
+	}
+	rcu_read_unlock();
+	put_task_struct(task);
 	if (!leader)
 		goto out_no_task;
 	retval = 0;