Skip to content

Commit f70102c

Browse files
keesgregkh
authored andcommitted
proc: Track /proc/$pid/attr/ opener mm_struct
commit 591a22c upstream. Commit bfb819e ("proc: Check /proc/$pid/attr/ writes against file opener") tried to make sure that there could not be a confusion between the opener of a /proc/$pid/attr/ file and the writer. It used struct cred to make sure the privileges didn't change. However, there were existing cases where a more privileged thread was passing the opened fd to a differently privileged thread (during container setup). Instead, use mm_struct to track whether the opener and writer are still the same process. (This is what several other proc files already do, though for different reasons.) Reported-by: Christian Brauner <christian.brauner@ubuntu.com> Reported-by: Andrea Righi <andrea.righi@canonical.com> Tested-by: Andrea Righi <andrea.righi@canonical.com> Fixes: bfb819e ("proc: Check /proc/$pid/attr/ writes against file opener") Cc: stable@vger.kernel.org Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 951358a commit f70102c

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎fs/proc/base.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2675,6 +2675,11 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
26752675
}
26762676

26772677
#ifdef CONFIG_SECURITY
2678+
static int proc_pid_attr_open(struct inode *inode, struct file *file)
2679+
{
2680+
return __mem_open(inode, file, PTRACE_MODE_READ_FSCREDS);
2681+
}
2682+
26782683
static ssize_t proc_pid_attr_read(struct file * file, char __user * buf,
26792684
size_t count, loff_t *ppos)
26802685
{
@@ -2705,7 +2710,7 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
27052710
int rv;
27062711

27072712
/* A task may only write when it was the opener. */
2708-
if (file->f_cred != current_real_cred())
2713+
if (file->private_data != current->mm)
27092714
return -EPERM;
27102715

27112716
rcu_read_lock();
@@ -2755,9 +2760,11 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
27552760
}
27562761

27572762
static const struct file_operations proc_pid_attr_operations = {
2763+
.open = proc_pid_attr_open,
27582764
.read = proc_pid_attr_read,
27592765
.write = proc_pid_attr_write,
27602766
.llseek = generic_file_llseek,
2767+
.release = mem_release,
27612768
};
27622769

27632770
#define LSM_DIR_OPS(LSM) \

0 commit comments

Comments
 (0)