aboutsummaryrefslogtreecommitdiff
path: root/fs/proc
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2013-09-11 14:24:37 -0700
committerMister Oyster <oysterized@gmail.com>2017-05-24 02:22:21 +0200
commit46dd3cad9b928734e459d5e7c625ab8727b4a39d (patch)
tree10024347d6a37ba50bc9b18581023e709e17ec1f /fs/proc
parent7b864986f96686b84af94cb3c0488a0374fd167c (diff)
UPSTREAM: proc: make proc_fd_permission() thread-friendly
(cherry pick from commit 96d0df79f2644fc823f26c06491e182d87a90c2a) proc_fd_permission() says "process can still access /proc/self/fd after it has executed a setuid()", but the "task_pid() = proc_pid() check only helps if the task is group leader, /proc/self points to /proc/<leader-pid>. Change this check to use task_tgid() so that the whole thread group can access its /proc/self/fd or /proc/<tid-of-sub-thread>/fd. Notes: - CLONE_THREAD does not require CLONE_FILES so task->files can differ, but I don't think this can lead to any security problem. And this matches same_thread_group() in __ptrace_may_access(). - /proc/self should probably point to /proc/<thread-tid>, but it is too late to change the rules. Perhaps it makes sense to add /proc/thread though. Test-case: void *tfunc(void *arg) { assert(opendir("/proc/self/fd")); return NULL; } int main(void) { pthread_t t; pthread_create(&t, NULL, tfunc, NULL); pthread_join(t, NULL); return 0; } fails if, say, this executable is not readable and suid_dumpable = 0. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Bug: 26016905 Change-Id: Ifdd6403a8fccd073122e89d3547c13ccc08f0dce Signed-off-by: Joe Maples <joe@frap129.org> Conflicts: fs/proc/fd.c
Diffstat (limited to 'fs/proc')
-rw-r--r--fs/proc/fd.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/fs/proc/fd.c b/fs/proc/fd.c
index d8eda9702..7bd032b5b 100644
--- a/fs/proc/fd.c
+++ b/fs/proc/fd.c
@@ -307,11 +307,8 @@ int proc_fd_permission(struct inode *inode, int mask)
rv = generic_permission(inode, mask);
if (rv == 0)
- return rv;
-
- rcu_read_lock();
- p = pid_task(proc_pid(inode), PIDTYPE_PID);
- if (p && same_thread_group(p, current))
+ return 0;
+ if (task_tgid(current) == proc_pid(inode))
rv = 0;
rcu_read_unlock();