Skip to content

Commit

Permalink
exec: Set file unwritable before LSM check
Browse files Browse the repository at this point in the history
The LSM check should happen after the file has been confirmed to be
unchanging. Without this, we could have a race between the Time of Check
(the call to security_kernel_read_file() which could read the file and
make access policy decisions) and the Time of Use (starting with
kernel_read_file()'s reading of the file contents). In theory, file
contents could change between the two.

Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
Signed-off-by: James Morris <james.morris@microsoft.com>
  • Loading branch information
Kees Cook authored and James Morris committed Mar 19, 2018
1 parent 6b4f3d0 commit 7bd698b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,13 +895,13 @@ int kernel_read_file(struct file *file, void **buf, loff_t *size,
if (!S_ISREG(file_inode(file)->i_mode) || max_size < 0)
return -EINVAL;

ret = security_kernel_read_file(file, id);
ret = deny_write_access(file);
if (ret)
return ret;

ret = deny_write_access(file);
ret = security_kernel_read_file(file, id);
if (ret)
return ret;
goto out;

i_size = i_size_read(file_inode(file));
if (max_size > 0 && i_size > max_size) {
Expand Down

0 comments on commit 7bd698b

Please sign in to comment.