Skip to content

Commit 591a22c

Browse files
keestorvalds
authored andcommitted
proc: Track /proc/$pid/attr/ opener mm_struct
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 <[email protected]> Reported-by: Andrea Righi <[email protected]> Tested-by: Andrea Righi <[email protected]> Fixes: bfb819e ("proc: Check /proc/$pid/attr/ writes against file opener") Cc: [email protected] Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 4c8684f commit 591a22c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

fs/proc/base.c

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

26762676
#ifdef CONFIG_SECURITY
2677+
static int proc_pid_attr_open(struct inode *inode, struct file *file)
2678+
{
2679+
return __mem_open(inode, file, PTRACE_MODE_READ_FSCREDS);
2680+
}
2681+
26772682
static ssize_t proc_pid_attr_read(struct file * file, char __user * buf,
26782683
size_t count, loff_t *ppos)
26792684
{
@@ -2704,7 +2709,7 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
27042709
int rv;
27052710

27062711
/* A task may only write when it was the opener. */
2707-
if (file->f_cred != current_real_cred())
2712+
if (file->private_data != current->mm)
27082713
return -EPERM;
27092714

27102715
rcu_read_lock();
@@ -2754,9 +2759,11 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
27542759
}
27552760

27562761
static const struct file_operations proc_pid_attr_operations = {
2762+
.open = proc_pid_attr_open,
27572763
.read = proc_pid_attr_read,
27582764
.write = proc_pid_attr_write,
27592765
.llseek = generic_file_llseek,
2766+
.release = mem_release,
27602767
};
27612768

27622769
#define LSM_DIR_OPS(LSM) \

0 commit comments

Comments
 (0)