Skip to content

Commit

Permalink
exec: Check __FMODE_EXEC instead of in_execve for LSMs
Browse files Browse the repository at this point in the history
After commit 978ffcb ("execve: open the executable file before
doing anything else"), current->in_execve was no longer in sync with the
open(). This broke AppArmor and TOMOYO which depend on this flag to
distinguish "open" operations from being "exec" operations.

Instead of moving around in_execve, switch to using __FMODE_EXEC, which
is where the "is this an exec?" intent is stored. Note that TOMOYO still
uses in_execve around cred handling.

Reported-by: Kevin Locke <[email protected]>
Closes: https://lore.kernel.org/all/[email protected]
Suggested-by: Linus Torvalds <[email protected]>
Fixes: 978ffcb ("execve: open the executable file before doing anything else")
Cc: Josh Triplett <[email protected]>
Cc: John Johansen <[email protected]>
Cc: Paul Moore <[email protected]>
Cc: James Morris <[email protected]>
Cc: Serge E. Hallyn <[email protected]>
Cc: Kentaro Takeda <[email protected]>
Cc: Tetsuo Handa <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: Christian Brauner <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: Eric Biederman <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Sebastian Andrzej Siewior <[email protected]>
Cc:  <[email protected]>
Cc:  <[email protected]>
Cc:  <[email protected]>
Cc:  <[email protected]>
Signed-off-by: Kees Cook <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
kees authored and torvalds committed Jan 24, 2024
1 parent 1110ebe commit 4759ff7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion security/apparmor/lsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,10 @@ static int apparmor_file_open(struct file *file)
* Cache permissions granted by the previous exec check, with
* implicit read and executable mmap which are required to
* actually execute the image.
*
* Illogically, FMODE_EXEC is in f_flags, not f_mode.
*/
if (current->in_execve) {
if (file->f_flags & __FMODE_EXEC) {
fctx->allow = MAY_EXEC | MAY_READ | AA_EXEC_MMAP;
return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion security/tomoyo/tomoyo.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ static int tomoyo_file_fcntl(struct file *file, unsigned int cmd,
static int tomoyo_file_open(struct file *f)
{
/* Don't check read permission here if called from execve(). */
if (current->in_execve)
/* Illogically, FMODE_EXEC is in f_flags, not f_mode. */
if (f->f_flags & __FMODE_EXEC)
return 0;
return tomoyo_check_open_permission(tomoyo_domain(), &f->f_path,
f->f_flags);
Expand Down

0 comments on commit 4759ff7

Please sign in to comment.