Skip to content

Commit 7bd698b

Browse files
keesJames Morris
authored andcommitted
exec: Set file unwritable before LSM check
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 <[email protected]> Reviewed-by: Mimi Zohar <[email protected]> Signed-off-by: James Morris <[email protected]>
1 parent 6b4f3d0 commit 7bd698b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

fs/exec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -895,13 +895,13 @@ int kernel_read_file(struct file *file, void **buf, loff_t *size,
895895
if (!S_ISREG(file_inode(file)->i_mode) || max_size < 0)
896896
return -EINVAL;
897897

898-
ret = security_kernel_read_file(file, id);
898+
ret = deny_write_access(file);
899899
if (ret)
900900
return ret;
901901

902-
ret = deny_write_access(file);
902+
ret = security_kernel_read_file(file, id);
903903
if (ret)
904-
return ret;
904+
goto out;
905905

906906
i_size = i_size_read(file_inode(file));
907907
if (max_size > 0 && i_size > max_size) {

0 commit comments

Comments
 (0)