proc: actually make proc_fd_permission() thread-friendly
PATCH 1/1 proc: actually make proc_fd_permission() thread-friendly
The commit 96d0df79f264 ("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).
Reported-by "Jin, Yihua" <[email protected]>
Signed-off-by Oleg Nesterov <[email protected]>
--- fs/proc/fd.c | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-)
fs/proc/fd.c +11 -3
@@ -291,11 +291,19 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,*/ 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 ) -return 0 ; -if (task_tgid (current) ==proc_pid (inode)) +return rv; + +rcu_read_lock (); + p =pid_task (proc_pid (inode),PIDTYPE_PID ); +if (p &&same_thread_group (p, current)) rv =0 ; +rcu_read_unlock (); +return rv; }
Signature · 1 line
1.5.5.1