Skip to content

Commit 4759ff7

Browse files
keestorvalds
authored andcommitted
exec: Check __FMODE_EXEC instead of in_execve for LSMs
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 <kevin@kevinlocke.name> Closes: https://lore.kernel.org/all/ZbE4qn9_h14OqADK@kevinlocke.name Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Fixes: 978ffcb ("execve: open the executable file before doing anything else") Cc: Josh Triplett <josh@joshtriplett.org> Cc: John Johansen <john.johansen@canonical.com> Cc: Paul Moore <paul@paul-moore.com> Cc: James Morris <jmorris@namei.org> Cc: Serge E. Hallyn <serge@hallyn.com> Cc: Kentaro Takeda <takedakn@nttdata.co.jp> Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Christian Brauner <brauner@kernel.org> Cc: Jan Kara <jack@suse.cz> Cc: Eric Biederman <ebiederm@xmission.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: <linux-fsdevel@vger.kernel.org> Cc: <linux-mm@kvack.org> Cc: <apparmor@lists.ubuntu.com> Cc: <linux-security-module@vger.kernel.org> Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 1110ebe commit 4759ff7

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

security/apparmor/lsm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,10 @@ static int apparmor_file_open(struct file *file)
469469
* Cache permissions granted by the previous exec check, with
470470
* implicit read and executable mmap which are required to
471471
* actually execute the image.
472+
*
473+
* Illogically, FMODE_EXEC is in f_flags, not f_mode.
472474
*/
473-
if (current->in_execve) {
475+
if (file->f_flags & __FMODE_EXEC) {
474476
fctx->allow = MAY_EXEC | MAY_READ | AA_EXEC_MMAP;
475477
return 0;
476478
}

security/tomoyo/tomoyo.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ static int tomoyo_file_fcntl(struct file *file, unsigned int cmd,
328328
static int tomoyo_file_open(struct file *f)
329329
{
330330
/* Don't check read permission here if called from execve(). */
331-
if (current->in_execve)
331+
/* Illogically, FMODE_EXEC is in f_flags, not f_mode. */
332+
if (f->f_flags & __FMODE_EXEC)
332333
return 0;
333334
return tomoyo_check_open_permission(tomoyo_domain(), &f->f_path,
334335
f->f_flags);

0 commit comments

Comments
 (0)