/proc//fd and /proc//map_files are mode 0500 and belong to the user the task runs as, or to root if the task isn't dumpable. The owner is stored in the inode and only brought up to date by pid_revalidate(), i.e. when somebody looks the directory up by name. A lookup that starts at a descriptor for the directory checks MAY_EXEC against whatever the inode says: observer, uid 1000 target, uid 1000 d = open("/proc//fd", O_PATH) execve("/usr/bin/su") opens its files fstatat(d, "5", AT_SYMLINK_NOFOLLOW) fd/ still belongs to uid 1000 succeeds if su has descriptor 5 open, st_mode tells how it was opened That works until somebody walks through /proc//fd by name. The links themselves are checked on their own, so what is behind the numbers isn't at risk. Refresh the owner in proc_fd_permission() under RCU, the way pid_revalidate() does it. Let the task itself in first, there's nothing to refresh for that and /proc/self/fd is what nearly all lookups are about. Reported-by: Josef Bacik Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Christian Brauner (Amutable) --- fs/proc/fd.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/fs/proc/fd.c b/fs/proc/fd.c index 2d51344267ee..09ca4a5916d3 100644 --- a/fs/proc/fd.c +++ b/fs/proc/fd.c @@ -348,25 +348,25 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry, /* * /proc/pid/fd needs a special permission handler so that a process can still - * access /proc/self/fd after it has executed a setuid(). + * access /proc/self/fd after it has executed a setuid(). A lookup that starts + * at a descriptor for the directory skips pid_revalidate(), so refresh the + * owner here. */ int proc_fd_permission(const struct mnt_idmap *idmap, struct inode *inode, int mask) { struct task_struct *p; - int rv; - rv = generic_permission(&nop_mnt_idmap, 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)) - rv = 0; - rcu_read_unlock(); + scoped_guard(rcu) { + p = pid_task(proc_pid(inode), PIDTYPE_PID); + if (p) { + if (same_thread_group(p, current)) + return 0; + pid_update_inode(p, inode); + } + } - return rv; + return generic_permission(&nop_mnt_idmap, inode, mask); } static int proc_fd_getattr(const struct mnt_idmap *idmap, -- 2.53.0