Skip to content

Commit 1927e49

Browse files
Kalesh Singhakpm00
authored andcommitted
procfs: prevent unprivileged processes accessing fdinfo dir
The file permissions on the fdinfo dir from were changed from S_IRUSR|S_IXUSR to S_IRUGO|S_IXUGO, and a PTRACE_MODE_READ check was added for opening the fdinfo files [1]. However, the ptrace permission check was not added to the directory, allowing anyone to get the open FD numbers by reading the fdinfo directory. Add the missing ptrace permission check for opening the fdinfo directory. [1] https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Fixes: 7bc3fa0 ("procfs: allow reading fdinfo with PTRACE_MODE_READ") Signed-off-by: Kalesh Singh <[email protected]> Cc: Kees Cook <[email protected]> Cc: Eric W. Biederman <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Cc: Hridya Valsaraju <[email protected]> Cc: Jann Horn <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 7d1e649 commit 1927e49

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

fs/proc/fd.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static int seq_show(struct seq_file *m, void *v)
7272
return 0;
7373
}
7474

75-
static int seq_fdinfo_open(struct inode *inode, struct file *file)
75+
static int proc_fdinfo_access_allowed(struct inode *inode)
7676
{
7777
bool allowed = false;
7878
struct task_struct *task = get_proc_task(inode);
@@ -86,6 +86,16 @@ static int seq_fdinfo_open(struct inode *inode, struct file *file)
8686
if (!allowed)
8787
return -EACCES;
8888

89+
return 0;
90+
}
91+
92+
static int seq_fdinfo_open(struct inode *inode, struct file *file)
93+
{
94+
int ret = proc_fdinfo_access_allowed(inode);
95+
96+
if (ret)
97+
return ret;
98+
8999
return single_open(file, seq_show, inode);
90100
}
91101

@@ -348,12 +358,23 @@ static int proc_readfdinfo(struct file *file, struct dir_context *ctx)
348358
proc_fdinfo_instantiate);
349359
}
350360

361+
static int proc_open_fdinfo(struct inode *inode, struct file *file)
362+
{
363+
int ret = proc_fdinfo_access_allowed(inode);
364+
365+
if (ret)
366+
return ret;
367+
368+
return 0;
369+
}
370+
351371
const struct inode_operations proc_fdinfo_inode_operations = {
352372
.lookup = proc_lookupfdinfo,
353373
.setattr = proc_setattr,
354374
};
355375

356376
const struct file_operations proc_fdinfo_operations = {
377+
.open = proc_open_fdinfo,
357378
.read = generic_read_dir,
358379
.iterate_shared = proc_readfdinfo,
359380
.llseek = generic_file_llseek,

0 commit comments

Comments
 (0)