exec: Factor security_bprm_creds_for_exec out of security_bprm_set_creds
authorEric W. Biederman <ebiederm@xmission.com>
Sun, 22 Mar 2020 20:46:24 +0000 (15:46 -0500)
committerEric W. Biederman <ebiederm@xmission.com>
Wed, 20 May 2020 19:45:31 +0000 (14:45 -0500)
commitb8bff599261c930630385ee21d3f98e7ce7d4843
treeabe467d5124f1df78e2d2383068c90f518a16069
parent87b047d2be417b271d80f5e490a825c6fd53ecad
exec: Factor security_bprm_creds_for_exec out of security_bprm_set_creds

Today security_bprm_set_creds has several implementations:
apparmor_bprm_set_creds, cap_bprm_set_creds, selinux_bprm_set_creds,
smack_bprm_set_creds, and tomoyo_bprm_set_creds.

Except for cap_bprm_set_creds they all test bprm->called_set_creds and
return immediately if it is true.  The function cap_bprm_set_creds
ignores bprm->calld_sed_creds entirely.

Create a new LSM hook security_bprm_creds_for_exec that is called just
before prepare_binprm in __do_execve_file, resulting in a LSM hook
that is called exactly once for the entire of exec.  Modify the bits
of security_bprm_set_creds that only want to be called once per exec
into security_bprm_creds_for_exec, leaving only cap_bprm_set_creds
behind.

Remove bprm->called_set_creds all of it's former users have been moved
to security_bprm_creds_for_exec.

Add or upate comments a appropriate to bring them up to date and
to reflect this change.

Link: https://lkml.kernel.org/r/87v9kszrzh.fsf_-_@x220.int.ebiederm.org
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Casey Schaufler <casey@schaufler-ca.com> # For the LSM and Smack bits
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
12 files changed:
fs/exec.c
include/linux/binfmts.h
include/linux/lsm_hook_defs.h
include/linux/lsm_hooks.h
include/linux/security.h
security/apparmor/domain.c
security/apparmor/include/domain.h
security/apparmor/lsm.c
security/security.c
security/selinux/hooks.c
security/smack/smack_lsm.c
security/tomoyo/tomoyo.c