mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-09 04:10:18 +09:00
UPSTREAM: 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/20210308170651.919148-1-kaleshsingh@google.com Bug: 254441685 Link: https://lkml.kernel.org/r/20210713162008.1056986-1-kaleshsingh@google.com Fixes:7bc3fa0172("procfs: allow reading fdinfo with PTRACE_MODE_READ") Signed-off-by: Kalesh Singh <kaleshsingh@google.com> Cc: Kees Cook <keescook@chromium.org> Cc: Eric W. Biederman <ebiederm@xmission.com> Cc: Christian Brauner <christian.brauner@ubuntu.com> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Hridya Valsaraju <hridya@google.com> Cc: Jann Horn <jannh@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit1927e498ae) Signed-off-by: Lee Jones <joneslee@google.com> Change-Id: Idaeffb84ce297c0a393652325c74ddd533ffcfbf
This commit is contained in:
committed by
Treehugger Robot
parent
ae1f81f7f4
commit
9257ade3bc
23
fs/proc/fd.c
23
fs/proc/fd.c
@@ -71,7 +71,7 @@ out:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int seq_fdinfo_open(struct inode *inode, struct file *file)
|
static int proc_fdinfo_access_allowed(struct inode *inode)
|
||||||
{
|
{
|
||||||
bool allowed = false;
|
bool allowed = false;
|
||||||
struct task_struct *task = get_proc_task(inode);
|
struct task_struct *task = get_proc_task(inode);
|
||||||
@@ -85,6 +85,16 @@ static int seq_fdinfo_open(struct inode *inode, struct file *file)
|
|||||||
if (!allowed)
|
if (!allowed)
|
||||||
return -EACCES;
|
return -EACCES;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int seq_fdinfo_open(struct inode *inode, struct file *file)
|
||||||
|
{
|
||||||
|
int ret = proc_fdinfo_access_allowed(inode);
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
return single_open(file, seq_show, inode);
|
return single_open(file, seq_show, inode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -365,12 +375,23 @@ static int proc_readfdinfo(struct file *file, struct dir_context *ctx)
|
|||||||
proc_fdinfo_instantiate);
|
proc_fdinfo_instantiate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int proc_open_fdinfo(struct inode *inode, struct file *file)
|
||||||
|
{
|
||||||
|
int ret = proc_fdinfo_access_allowed(inode);
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const struct inode_operations proc_fdinfo_inode_operations = {
|
const struct inode_operations proc_fdinfo_inode_operations = {
|
||||||
.lookup = proc_lookupfdinfo,
|
.lookup = proc_lookupfdinfo,
|
||||||
.setattr = proc_setattr,
|
.setattr = proc_setattr,
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct file_operations proc_fdinfo_operations = {
|
const struct file_operations proc_fdinfo_operations = {
|
||||||
|
.open = proc_open_fdinfo,
|
||||||
.read = generic_read_dir,
|
.read = generic_read_dir,
|
||||||
.iterate_shared = proc_readfdinfo,
|
.iterate_shared = proc_readfdinfo,
|
||||||
.llseek = generic_file_llseek,
|
.llseek = generic_file_llseek,
|
||||||
|
|||||||
Reference in New Issue
Block a user