linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] exec: Set file unwritable before LSM check
@ 2018-03-09 19:07 Kees Cook
  2018-03-09 19:13 ` Linus Torvalds
  0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2018-03-09 19:07 UTC (permalink / raw)
  To: James Morris
  Cc: linux-kernel, linux-security-module, Serge E. Hallyn,
	Linus Torvalds, Mimi Zohar, linux-integrity, Paul Moore,
	Stephen Smalley

The LSM check should happen after the file has been confirmed to be
unchanging. Without this, we could have a ToCToU issue between the
LSM verification and the actual contents of the file later.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
Only loadpin and SELinux implement this hook. From what I can see, this
won't change anything for either of them. IMA calls kernel_read_file(),
but looking there it seems those callers won't be negatively impacted
either. Can folks double-check this and send an Ack please?
---
 fs/exec.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index 7eb8d21bcab9..a919a827d181 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -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) {
-- 
2.7.4


-- 
Kees Cook
Pixel Security

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] exec: Set file unwritable before LSM check
  2018-03-09 19:07 [PATCH] exec: Set file unwritable before LSM check Kees Cook
@ 2018-03-09 19:13 ` Linus Torvalds
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Torvalds @ 2018-03-09 19:13 UTC (permalink / raw)
  To: Kees Cook
  Cc: James Morris, Linux Kernel Mailing List, LSM List,
	Serge E. Hallyn, Mimi Zohar, linux-integrity, Paul Moore,
	Stephen Smalley

On Fri, Mar 9, 2018 at 11:07 AM, Kees Cook <keescook@chromium.org> wrote:
> The LSM check should happen after the file has been confirmed to be
> unchanging. Without this, we could have a ToCToU issue between the
> LSM verification and the actual contents of the file later.

Can we please not add random crazy six-letter acronyms that nobody
uses outside of a very small community?

The point of a commit message is to *explain*, not confuse.

            Linus

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-03-09 19:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-09 19:07 [PATCH] exec: Set file unwritable before LSM check Kees Cook
2018-03-09 19:13 ` Linus Torvalds

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).