Skip to content

Commit

Permalink
Smack: Don't ignore other bprm->unsafe flags if LSM_UNSAFE_PTRACE is set
Browse files Browse the repository at this point in the history
There is a logic bug in the current smack_bprm_set_creds():
If LSM_UNSAFE_PTRACE is set, but the ptrace state is deemed to be
acceptable (e.g. because the ptracer detached in the meantime), the other
->unsafe flags aren't checked. As far as I can tell, this means that
something like the following could work (but I haven't tested it):

 - task A: create task B with fork()
 - task B: set NO_NEW_PRIVS
 - task B: install a seccomp filter that makes open() return 0 under some
   conditions
 - task B: replace fd 0 with a malicious library
 - task A: attach to task B with PTRACE_ATTACH
 - task B: execve() a file with an SMACK64EXEC extended attribute
 - task A: while task B is still in the middle of execve(), exit (which
   destroys the ptrace relationship)

Make sure that if any flags other than LSM_UNSAFE_PTRACE are set in
bprm->unsafe, we reject the execve().

Cc: stable@vger.kernel.org
Fixes: 5663884 ("Smack: unify all ptrace accesses in the smack")
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
  • Loading branch information
thejh authored and cschaufler committed Sep 4, 2019
1 parent 0ecfebd commit 3675f05
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion security/smack/smack_lsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,8 @@ static int smack_bprm_set_creds(struct linux_binprm *bprm)

if (rc != 0)
return rc;
} else if (bprm->unsafe)
}
if (bprm->unsafe & ~LSM_UNSAFE_PTRACE)
return -EPERM;

bsp->smk_task = isp->smk_task;
Expand Down

0 comments on commit 3675f05

Please sign in to comment.