Commit 720ae734 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Luis Henriques

proc: actually make proc_fd_permission() thread-friendly

commit 54708d28 upstream.

The commit 96d0df79 ("proc: make proc_fd_permission() thread-friendly")
fixed the access to /proc/self/fd from sub-threads, but introduced another
problem: a sub-thread can't access /proc/<tid>/fd/ or /proc/thread-self/fd
if generic_permission() fails.

Change proc_fd_permission() to check same_thread_group(pid_task(), current).

Fixes: 96d0df79 ("proc: make proc_fd_permission() thread-friendly")
Reported-by: default avatar"Jin, Yihua" <yihua.jin@intel.com>
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent edd540a6
...@@ -285,11 +285,19 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry, ...@@ -285,11 +285,19 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
*/ */
int proc_fd_permission(struct inode *inode, int mask) int proc_fd_permission(struct inode *inode, int mask)
{ {
int rv = generic_permission(inode, mask); struct task_struct *p;
int rv;
rv = generic_permission(inode, mask);
if (rv == 0) if (rv == 0)
return 0; return rv;
if (task_tgid(current) == proc_pid(inode))
rcu_read_lock();
p = pid_task(proc_pid(inode), PIDTYPE_PID);
if (p && same_thread_group(p, current))
rv = 0; rv = 0;
rcu_read_unlock();
return rv; return rv;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment