This series has grown... :P
As discussed with Linus and Andy, we need to reset the stack rlimit
before we do memory layouts when execing a privilege-gaining (e.g.
setuid) program. To do this, we need to know the results of the
bprm_secureexec hook before memory layouts. As it turns out, this
can be made _mostly_ trivial by collapsing bprm_secureexec into
bprm_set_creds.
The LSMs using bprm_secureexec nearly always save state between
bprm_set_creds and bprm_secureexec. In the face of multiple calls to
bprm_set_creds (via prepare_binprm() calls from binfmt_script, etc),
all LSMs except commoncap only pay attention to the first call, so
that aligns well with collapsing bprm_secureexec into bprm_set_creds.
The commoncaps, though, needs to check the _last_ bprm_set_creds, so
this series just swaps one bprm flag for another (cap_effective is no
longer needed to save state between bprm_set_creds and bprm_secureexec,
but we do need to keep a separate state, so we add the cap_elevated flag).
Once secureexec is available to setup_new_exec() before the memory
layout, we can add an rlimit sanity-check for setuid execs. (With no
need to clean up since we're past the point of no return.)
Along the way, this fixes comments, renames a variable, and consolidates
dumpability and pdeath_signal clearing, which includes some commit log
archeology to examine the subtle differences between what we had and
what we need.
I'd appreciate some extra eyes on this to make sure this isn't broken
in some special way. Looking at the diffstat, even after all my long
comments, this is a net reduction in lines. :)
Given this crosses a bunch of areas, I think this is likely best to
go via the -mm tree, which is where nearly all of my prior exec work
has lived too.
Thanks!
-Kees
----------------------------------------------------------------
Kees Cook (15):
binfmt: Introduce secureexec flag
exec: Rename bprm->cred_prepared to called_set_creds
apparmor: Refactor to remove bprm_secureexec hook
selinux: Refactor to remove bprm_secureexec hook
smack: Refactor to remove bprm_secureexec hook
commoncap: Refactor to remove bprm_secureexec hook
commoncap: Move cap_elevated calculation into bprm_set_creds
LSM: drop bprm_secureexec hook
exec: Correct comments about "point of no return"
exec: Use secureexec for setting dumpability
exec: Use secureexec for clearing pdeath_signal
smack: Remove redundant pdeath_signal clearing
exec: Consolidate dumpability logic
exec: Use sane stack rlimit under secureexec
exec: Consolidate pdeath_signal clearing
fs/binfmt_elf.c | 2 +-
fs/binfmt_elf_fdpic.c | 2 +-
fs/binfmt_flat.c | 2 +-
fs/exec.c | 56 ++++++++++++++++++++++++++++----------
include/linux/binfmts.h | 24 ++++++++++++----
include/linux/lsm_hooks.h | 14 ++++------
include/linux/security.h | 7 -----
security/apparmor/domain.c | 24 ++--------------
security/apparmor/include/domain.h | 1 -
security/apparmor/include/file.h | 3 --
security/apparmor/lsm.c | 1 -
security/commoncap.c | 50 ++++++++--------------------------
security/security.c | 5 ----
security/selinux/hooks.c | 26 ++++--------------
security/smack/smack_lsm.c | 34 ++---------------------
security/tomoyo/tomoyo.c | 2 +-
16 files changed, 91 insertions(+), 162 deletions(-)
v3:
- collapse brpm_secureexec into bprm_set_creds; ebiederm.
- continue to improve various comments
v2:
- fix missed current_security() uses in LSMs.
- research/consolidate dumpability setting logic
- research/consolidate pdeath_signal clearing logic
- split up logical steps a little more for easier review (and bisection)
- fix some old broken comments
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
The bprm_secureexec hook can be moved earlier. Right now, it is called
during create_elf_tables(), via load_binary(), via search_binary_handler(),
via exec_binprm(). Nearly all (see exception below) state used by
bprm_secureexec is created during the bprm_set_creds hook, called from
prepare_binprm().
For all LSMs (except commoncaps described next), only the first execution
of bprm_set_creds takes any effect (they all check bprm->cred_prepared which
prepare_binprm() sets after the first call to the bprm_set_creds hook).
However, all these LSMs also only do anything with bprm_secureexec when
they detected a secure state during their first run of bprm_set_creds.
Therefore, it is functionally identical to move the detection into
bprm_set_creds, since the results from secureexec here only need to be
based on the first call to the LSM's bprm_set_creds hook.
The single exception is that the commoncaps secureexec hook also examines
euid/uid and egid/gid differences which are controlled by bprm_fill_uid(),
via prepare_binprm(), which can be called multiple times (e.g.
binfmt_script, binfmt_misc), and may clear the euid/egid for the final
load (i.e. the script interpreter). However, while commoncaps specifically
ignores bprm->cred_prepared, and runs its bprm_set_creds hook each time
prepare_binprm() may get called, it needs to base the secureexec decision
on the final call to bprm_set_creds. As a result, it will need special
handling.
To begin this refactoring, this adds the secureexec flag to the bprm
struct, which will eventually be used in place of the LSM hook.
Cc: David Howells <dhowells@redhat.com>
Signed-off-by: Kees Cook <redacted>
---
fs/binfmt_elf.c | 3 ++-
fs/binfmt_elf_fdpic.c | 3 ++-
include/linux/binfmts.h | 8 +++++++-
3 files changed, 11 insertions(+), 3 deletions(-)
@@ -27,9 +27,15 @@ struct linux_binprm {unsignedintcred_prepared:1,/* true if creds already prepared (multiple*prepshappenforinterpreters)*/-cap_effective:1;/* true if has elevated effective capabilities,+cap_effective:1,/* true if has elevated effective capabilities,*falseifnot;exceptforinitwhichinherits*itsparent'scapsanyway*/+/*+*Setbybprm_set_credshooktoindicateaprivilege-gaining+*exechashappened.Usedtosanitizeexecutionenvironment+*andtosetAT_SECUREauxvforglibc.+*/+secureexec:1;#ifdef __alpha__unsignedinttaso:1;#endif
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
The Smack bprm_secureexec hook can be merged with the bprm_set_creds
hook since it's dealing with the same information, and all of the details
are finalized during the first call to the bprm_set_creds hook via
prepare_binprm() (subsequent calls due to binfmt_script, etc, are ignored
via bprm->called_set_creds).
Here, the test can just happen at the end of the bprm_set_creds hook,
and the bprm_secureexec hook can be dropped.
Cc: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Kees Cook <redacted>
---
security/smack/smack_lsm.c | 21 ++++-----------------
1 file changed, 4 insertions(+), 17 deletions(-)
@@ -950,6 +950,10 @@ static int smack_bprm_set_creds(struct linux_binprm *bprm)bsp->smk_task=isp->smk_task;bprm->per_clear|=PER_CLEAR_ON_SETID;+/* Decide if this is a secure exec. */+if(bsp->smk_task!=bsp->smk_forked)+bprm->secureexec=1;+return0;}
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
The commoncap implementation of the bprm_secureexec hook is the only LSM
that depends on the final call to its bprm_set_creds hook (since it may
be called for multiple files, it ignores bprm->called_set_creds). As a
result, it cannot safely _clear_ bprm->secureexec since other LSMs may
have set it. Instead, remove the bprm_secureexec hook by introducing a
new flag to bprm specific to commoncap: cap_elevated. This is similar to
cap_effective, but that is used for a specific subset of elevated
privileges, and exists solely to track state from bprm_set_creds to
bprm_secureexec. As such, it will be removed in the next patch.
Here, set the new bprm->cap_elevated flag when setuid/setgid has happened
from bprm_fill_uid() or fscapabilities have been prepared. This temporarily
moves the bprm_secureexec hook to a static inline. The helper will be
removed in the next patch; this makes the step easier to review and bisect,
since this does not introduce any changes to inputs nor outputs to the
"elevated privileges" calculation.
The new flag is merged with the bprm->secureexec flag in setup_new_exec()
since this marks the end of any further prepare_binprm() calls.
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Kees Cook <redacted>
---
fs/exec.c | 7 +++++++
include/linux/binfmts.h | 7 +++++++
security/commoncap.c | 12 ++++++++----
3 files changed, 22 insertions(+), 4 deletions(-)
@@ -1330,6 +1330,13 @@ EXPORT_SYMBOL(would_dump);voidsetup_new_exec(structlinux_binprm*bprm){+/*+*Oncehere,prepare_binrpm()willnotbecalledanymore,so+*thefinalstateofsetuid/setgid/fscapscanbemergedintothe+*secureexecflag.+*/+bprm->secureexec|=bprm->cap_elevated;+arch_pick_mmap_layout(current->mm);/* This is the point of no return */
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Instead of a separate function, open-code the cap_elevated test, which
lets us entirely remove bprm->cap_effective (to use the local "effective"
variable instead), and more accurately examine euid/egid changes via the
existing local "is_setid".
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Kees Cook <redacted>
---
include/linux/binfmts.h | 3 ---
security/commoncap.c | 52 ++++++++++---------------------------------------
2 files changed, 10 insertions(+), 45 deletions(-)
@@ -587,8 +576,6 @@ int cap_bprm_set_creds(struct linux_binprm *bprm)if(WARN_ON(!cap_ambient_invariant_ok(new)))return-EPERM;-bprm->cap_effective=effective;-/**Auditcandidateifcurrent->cap_effectiveisset*
@@ -617,35 +604,16 @@ int cap_bprm_set_creds(struct linux_binprm *bprm)return-EPERM;/* Check for privilege-elevated exec. */-bprm->cap_elevated=is_secureexec(bprm);--return0;-}--/**-*is_secureexec-Determinewhetherasecureexecutionisrequired-*@bprm:Theexecutionparameters-*-*Determinewhetherasecureexecutionisrequired,return1ifitis,and0-*ifitisnot.-*-*Thecredentialshavebeencommittedbythispoint,andsoarenolonger-*availablethrough@bprm->cred.-*/-staticintis_secureexec(structlinux_binprm*bprm)-{-conststructcred*cred=bprm->cred;-kuid_troot_uid=make_kuid(cred->user_ns,0);--if(!uid_eq(cred->uid,root_uid)){-if(bprm->cap_effective)-return1;-if(!cap_issubset(cred->cap_permitted,cred->cap_ambient))-return1;+bprm->cap_elevated=0;+if(is_setid){+bprm->cap_elevated=1;+}elseif(!uid_eq(new->uid,root_uid)){+if(effective||+!cap_issubset(new->cap_permitted,new->cap_ambient))+bprm->cap_elevated=1;}-return(!uid_eq(cred->euid,cred->uid)||-!gid_eq(cred->egid,cred->gid));+return0;}/**
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
This removes the bprm_secureexec hook since the logic has been folded into
the bprm_set_creds hook for all LSMs now.
Cc: James Morris <redacted>
Cc: Eric W. Biederman <redacted>
Signed-off-by: Kees Cook <redacted>
---
fs/binfmt_elf.c | 1 -
fs/binfmt_elf_fdpic.c | 1 -
include/linux/lsm_hooks.h | 14 +++++---------
include/linux/security.h | 7 -------
security/security.c | 5 -----
5 files changed, 5 insertions(+), 23 deletions(-)
@@ -40,7 +40,11 @@*interpreters.Thehookcantellwhetherithasalreadybeencalledby*checkingtoseeif@bprm->securityisnon-NULL.Ifso,thenthehook*maydecideeithertoretainthesecurityinformationsavedearlieror-*toreplaceit.+*toreplaceit.Thehookmustset@bprm->secureexecto1ifa"secure+*exec" has happened as a result of this hook call. The flag is used to+*indicatetheneedforasanitizedexecutionenvironment,andisalso+*passedintheELFauxiliarytableontheinitialstacktoindicate+*whetherlibcshouldenablesecuremode.*@bprmcontainsthelinux_binprmstructure.*Return0ifthehookissuccessfulandpermissionisgranted.*@bprm_check_security:
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Like dumpability, clearing pdeath_signal happens both in setup_new_exec()
and later in commit_creds(). The test in setup_new_exec() is different
from all other privilege comparisons, though: it is checking the new cred
(bprm) uid vs the old cred (current) euid. This appears to be a bug,
introduced by commit a6f76f23d297 ("CRED: Make execve() take advantage of
copy-on-write credentials"):
- if (bprm->e_uid != current_euid() ||
- bprm->e_gid != current_egid()) {
- set_dumpable(current->mm, suid_dumpable);
+ /* install the new credentials */
+ if (bprm->cred->uid != current_euid() ||
+ bprm->cred->gid != current_egid()) {
It was bprm euid vs current euid (and egids), but the effective got
dropped. Nothing in the exec flow changes bprm->cred->uid (nor gid).
The call traces are:
prepare_bprm_creds()
prepare_exec_creds()
prepare_creds()
memcpy(new_creds, old_creds, ...)
security_prepare_creds() (unimplemented by commoncap)
...
prepare_binprm()
bprm_fill_uid()
resets euid/egid to current euid/egid
sets euid/egid on bprm based on set*id file bits
security_bprm_set_creds()
cap_bprm_set_creds()
handle all caps-based manipulations
so this test is effectively a test of current_uid() vs current_euid(),
which is wrong, just like the prior dumpability tests were wrong.
The commit log says "Clear pdeath_signal and set dumpable on
certain circumstances that may not be covered by commit_creds()." This
may be meaning the earlier old euid vs new euid (and egid) test that
got changed.
Luckily, as with dumpability, this is all masked by commit_creds()
which performs old/new euid and egid tests and clears pdeath_signal.
And again, like dumpability, we should include LSM secureexec logic for
pdeath_signal clearing. For example, Smack goes out of its way to clear
pdeath_signal when it finds a secureexec condition.
Cc: David Howells <dhowells@redhat.com>
Signed-off-by: Kees Cook <redacted>
---
fs/exec.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Instead of an additional secureexec check for pdeath_signal, just move it
up into the initial secureexec test. Neither perf nor arch code touches
pdeath_signal, so the relocation shouldn't change anything.
Signed-off-by: Kees Cook <redacted>
---
fs/exec.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
@@ -1350,6 +1350,9 @@ void setup_new_exec(struct linux_binprm * bprm)bprm->secureexec|=bprm->cap_elevated;if(bprm->secureexec){+/* Make sure parent cannot signal privileged process. */+current->pdeath_signal=0;+/**Forsecureexec,resetthestacklimittosanedefaultto*avoidbadbehaviorfromthepriorrlimits.Thishasto
@@ -1382,10 +1385,6 @@ void setup_new_exec(struct linux_binprm * bprm)*/current->mm->task_size=TASK_SIZE;-if(bprm->secureexec){-current->pdeath_signal=0;-}-/* An exec changes our domain. We are no longer part of the threadgroup*/current->self_exec_id++;
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
The SELinux bprm_secureexec hook can be merged with the bprm_set_creds
hook since it's dealing with the same information, and all of the details
are finalized during the first call to the bprm_set_creds hook via
prepare_binprm() (subsequent calls due to binfmt_script, etc, are ignored
via bprm->called_set_creds).
Here, the test can just happen at the end of the bprm_set_creds hook,
and the bprm_secureexec hook can be dropped.
Cc: Paul Moore <paul@paul-moore.com>
Cc: Stephen Smalley <redacted>
Signed-off-by: Kees Cook <redacted>
---
security/selinux/hooks.c | 24 +++++-------------------
1 file changed, 5 insertions(+), 19 deletions(-)
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
The cred_prepared bprm flag has a misleading name. It has nothing to do
with the bprm_prepare_cred hook, and actually tracks if bprm_set_creds has
been called. Rename this flag and improve its comment.
Cc: David Howells <dhowells@redhat.com>
Cc: John Johansen <john.johansen@canonical.com>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Stephen Smalley <redacted>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: James Morris <redacted>
Signed-off-by: Kees Cook <redacted>
---
fs/binfmt_flat.c | 2 +-
fs/exec.c | 2 +-
include/linux/binfmts.h | 8 ++++++--
security/apparmor/domain.c | 2 +-
security/selinux/hooks.c | 2 +-
security/smack/smack_lsm.c | 2 +-
security/tomoyo/tomoyo.c | 2 +-
7 files changed, 12 insertions(+), 8 deletions(-)
@@ -25,8 +25,12 @@ struct linux_binprm {structmm_struct*mm;unsignedlongp;/* current top of mem */unsignedint-cred_prepared:1,/* true if creds already prepared (multiple-*prepshappenforinterpreters)*/+/*+*Trueafterthebprm_set_credshookhasbeencalledonce+*(multiplecallscanbemadeviaprepare_binprm()for+*binfmt_script/misc).+*/+called_set_creds:1,cap_effective:1,/* true if has elevated effective capabilities,*falseifnot;exceptforinitwhichinherits*itsparent'scapsanyway*/
@@ -2327,7 +2327,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)/* SELinux context only depends on initial program or script and not*thescriptinterpreter*/-if(bprm->cred_prepared)+if(bprm->called_set_creds)return0;old_tsec=current_security();
@@ -76,7 +76,7 @@ static int tomoyo_bprm_set_creds(struct linux_binprm *bprm)*Doonlyifthisfunctioniscalledforthefirsttimeofanexecve*operation.*/-if(bprm->cred_prepared)+if(bprm->called_set_creds)return0;#ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER/*
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
The AppArmor bprm_secureexec hook can be merged with the bprm_set_creds
hook since it's dealing with the same information, and all of the details
are finalized during the first call to the bprm_set_creds hook via
prepare_binprm() (subsequent calls due to binfmt_script, etc, are ignored
via bprm->called_set_creds).
Here, all the comments describe how secureexec is actually calculated
during bprm_set_creds, so this actually does it, drops the bprm flag that
was being used internally by AppArmor, and drops the bprm_secureexec hook.
Cc: John Johansen <john.johansen@canonical.com>
Signed-off-by: Kees Cook <redacted>
---
security/apparmor/domain.c | 22 +---------------------
security/apparmor/include/domain.h | 1 -
security/apparmor/include/file.h | 3 ---
security/apparmor/lsm.c | 1 -
4 files changed, 1 insertion(+), 26 deletions(-)
@@ -485,14 +485,11 @@ int apparmor_bprm_set_creds(struct linux_binprm *bprm)**Cases2and3aremarkedasrequiringsecureexec*(unlesspolicyspecified"unsafe exec")-*-*bprm->unsafeisusedtocachetheAA_X_UNSAFEpermission-*toavoidhavingtorecomputeinsecureexec*/if(!(perms.xindex&AA_X_UNSAFE)){AA_DEBUG("scrubbing environment variables for %s profile=%s\n",name,new_profile->base.hname);-bprm->unsafe|=AA_SECURE_X_NEEDED;+bprm->secureexec=1;}apply:/* when transitioning profiles clear unsafe personality bits */
@@ -521,23 +518,6 @@ int apparmor_bprm_set_creds(struct linux_binprm *bprm)}/**-*apparmor_bprm_secureexec-determineifsecureexecisneeded-*@bprm:binprmforexec(NOTNULL)-*-*Returns:%1ifsecureexecisneededelse%0-*/-intapparmor_bprm_secureexec(structlinux_binprm*bprm)-{-/* the decision to use secure exec is computed in set_creds-*andstoredinbprm->unsafe.-*/-if(bprm->unsafe&AA_SECURE_X_NEEDED)-return1;--return0;-}--/***apparmor_bprm_committing_creds-dotaskcleanuponcommittingnewcreds*@bprm:binprmfortheexec(NOTNULL)*/
@@ -66,9 +66,6 @@ struct path;#define AA_X_INHERIT 0x4000#define AA_X_UNCONFINED 0x8000-/* AA_SECURE_X_NEEDED - is passed in the bprm->unsafe field */-#define AA_SECURE_X_NEEDED 0x8000-/* need to make conditional which ones are being set */structpath_cond{kuid_tuid;
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
The examination of "current" to decide dumpability is wrong. This was a
check of and euid/uid (or egid/gid) mismatch in the existing process,
not the newly created one. This appears to stretch back into even the
"history.git" tree. Luckily, dumpability is later set in commit_creds().
In earlier kernel versions before creds existed, similar checks also
existed late in the exec flow, covering up the mistake as far back as I
could find.
Note that because the commit_creds() check examines differences of euid,
uid, egid, gid, and capabilities between the old and new creds, it would
look like the setup_new_exec() dumpability test could be entirely removed.
However, the secureexec test may cover a different set of tests (specific
to the LSMs) than what commit_creds() checks for. So, fix this test to
use secureexec (the removed euid tests are redundant to the commoncap
secureexec checks now).
Cc: David Howells <dhowells@redhat.com>
Signed-off-by: Kees Cook <redacted>
---
fs/exec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
In commit 221af7f87b97 ("Split 'flush_old_exec' into two functions"),
the comment about the point of no return should have stayed in
flush_old_exec() since it refers to "bprm->mm = NULL;" line, but prior
changes in commits c89681ed7d0e ("remove steal_locks()"), and
fd8328be874f ("sanitize handling of shared descriptor tables in failing
execve()") made it look like it meant the current->sas_ss_sp line instead.
The comment was referring to the fact that once bprm->mm is NULL, all
failures from a binfmt load_binary hook (e.g. load_elf_binary), will
get SEGV raised against current. Move this comment and expand the
explanation a bit, putting it above the assignment this time, and add
details about the true nature of "point of no return" being the call
to flush_old_exec() itself.
This also removes an erroneous commet about when credentials are being
installed. That has its own dedicated function, install_exec_creds(),
which carries a similar (and correct) comment, so remove the bogus comment
where installation is not actually happening.
Cc: David Howells <dhowells@redhat.com>
Cc: Eric W. Biederman <redacted>
Signed-off-by: Kees Cook <redacted>
---
fs/exec.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
@@ -1285,7 +1291,13 @@ int flush_old_exec(struct linux_binprm * bprm)if(retval)gotoout;-bprm->mm=NULL;/* We're using it now */+/*+*Afterclearingbprm->mm(tomarkthatcurrentisusingthe+*preparedmmnow),wehavenothingleftoftheoriginal+*process.Ifanythingfromhereonreturnsanerror,thecheck+*insearch_binary_handler()willSEGVcurrent.+*/+bprm->mm=NULL;set_fs(USER_DS);current->flags&=~(PF_RANDOMIZE|PF_FORKNOEXEC|PF_KTHREAD|
@@ -1339,7 +1351,6 @@ void setup_new_exec(struct linux_binprm * bprm)arch_pick_mmap_layout(current->mm);-/* This is the point of no return */current->sas_ss_sp=current->sas_ss_size=0;if(uid_eq(current_euid(),current_uid())&&gid_eq(current_egid(),current_gid()))
@@ -1357,7 +1368,6 @@ void setup_new_exec(struct linux_binprm * bprm)*/current->mm->task_size=TASK_SIZE;-/* install the new credentials */if(!uid_eq(bprm->cred->uid,current_euid())||!gid_eq(bprm->cred->gid,current_egid())){current->pdeath_signal=0;
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
This removes the redundant pdeath_signal clearing in Smack: the check in
smack_bprm_committing_creds() matches the check in smack_bprm_set_creds()
(which used to be in the now-removed smack_bprm_securexec() hook) and
since secureexec is now being checked for clearing pdeath_signal, this
is redundant to the common exec code.
Cc: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Kees Cook <redacted>
---
security/smack/smack_lsm.c | 15 ---------------
1 file changed, 15 deletions(-)
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Since it's already valid to set dumpability in the early part of
setup_new_exec(), we can consolidate the logic into a single place.
The BINPRM_FLAGS_ENFORCE_NONDUMP is set during would_dump() calls
before setup_new_exec(), so its test is safe to move as well.
Signed-off-by: Kees Cook <redacted>
---
fs/exec.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
@@ -1370,9 +1372,6 @@ void setup_new_exec(struct linux_binprm * bprm)if(bprm->secureexec){current->pdeath_signal=0;-}else{-if(bprm->interp_flags&BINPRM_FLAGS_ENFORCE_NONDUMP)-set_dumpable(current->mm,suid_dumpable);}/* An exec changes our domain. We are no longer part of the thread
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hmm. It may be bigger, but I like it a lot better. Each step now looks
fairly obvious and is well documented.
I don't love the timing of it, but I think I'd be willing to just pull
this in before rc2 as a "we need to do this sooner or later anyway and
probably mark much of it for stable" kind of thing.
But it would be really good to get people to look at the series,
particularly Andy and the LSM folks..
Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: John Johansen <john.johansen@canonical.com> Date: 2017-07-19 00:00:04
On 07/18/2017 03:25 PM, Kees Cook wrote:
The AppArmor bprm_secureexec hook can be merged with the bprm_set_creds
hook since it's dealing with the same information, and all of the details
are finalized during the first call to the bprm_set_creds hook via
prepare_binprm() (subsequent calls due to binfmt_script, etc, are ignored
via bprm->called_set_creds).
Here, all the comments describe how secureexec is actually calculated
during bprm_set_creds, so this actually does it, drops the bprm flag that
was being used internally by AppArmor, and drops the bprm_secureexec hook.
Cc: John Johansen <john.johansen@canonical.com>
Signed-off-by: Kees Cook <redacted>
Acked-by: John Johansen <john.johansen@canonical.com>
@@ -485,14 +485,11 @@ int apparmor_bprm_set_creds(struct linux_binprm *bprm)**Cases2and3aremarkedasrequiringsecureexec*(unlesspolicyspecified"unsafe exec")-*-*bprm->unsafeisusedtocachetheAA_X_UNSAFEpermission-*toavoidhavingtorecomputeinsecureexec*/if(!(perms.xindex&AA_X_UNSAFE)){AA_DEBUG("scrubbing environment variables for %s profile=%s\n",name,new_profile->base.hname);-bprm->unsafe|=AA_SECURE_X_NEEDED;+bprm->secureexec=1;}apply:/* when transitioning profiles clear unsafe personality bits */
@@ -521,23 +518,6 @@ int apparmor_bprm_set_creds(struct linux_binprm *bprm)}/**-*apparmor_bprm_secureexec-determineifsecureexecisneeded-*@bprm:binprmforexec(NOTNULL)-*-*Returns:%1ifsecureexecisneededelse%0-*/-intapparmor_bprm_secureexec(structlinux_binprm*bprm)-{-/* the decision to use secure exec is computed in set_creds-*andstoredinbprm->unsafe.-*/-if(bprm->unsafe&AA_SECURE_X_NEEDED)-return1;--return0;-}--/***apparmor_bprm_committing_creds-dotaskcleanuponcommittingnewcreds*@bprm:binprmfortheexec(NOTNULL)*/
@@ -66,9 +66,6 @@ struct path;#define AA_X_INHERIT 0x4000#define AA_X_UNCONFINED 0x8000-/* AA_SECURE_X_NEEDED - is passed in the bprm->unsafe field */-#define AA_SECURE_X_NEEDED 0x8000-/* need to make conditional which ones are being set */structpath_cond{kuid_tuid;
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: John Johansen <john.johansen@canonical.com> Date: 2017-07-19 00:02:43
On 07/18/2017 03:25 PM, Kees Cook wrote:
This removes the bprm_secureexec hook since the logic has been folded into
the bprm_set_creds hook for all LSMs now.
Cc: James Morris <redacted>
Cc: Eric W. Biederman <redacted>
Signed-off-by: Kees Cook <redacted>
looks good
Reviewed-by: John Johansen <john.johansen@canonical.com>
@@ -40,7 +40,11 @@*interpreters.Thehookcantellwhetherithasalreadybeencalledby*checkingtoseeif@bprm->securityisnon-NULL.Ifso,thenthehook*maydecideeithertoretainthesecurityinformationsavedearlieror-*toreplaceit.+*toreplaceit.Thehookmustset@bprm->secureexecto1ifa"secure+*exec" has happened as a result of this hook call. The flag is used to+*indicatetheneedforasanitizedexecutionenvironment,andisalso+*passedintheELFauxiliarytableontheinitialstacktoindicate+*whetherlibcshouldenablesecuremode.*@bprmcontainsthelinux_binprmstructure.*Return0ifthehookissuccessfulandpermissionisgranted.*@bprm_check_security:
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: John Johansen <john.johansen@canonical.com> Date: 2017-07-19 00:06:02
On 07/18/2017 03:25 PM, Kees Cook wrote:
The bprm_secureexec hook can be moved earlier. Right now, it is called
during create_elf_tables(), via load_binary(), via search_binary_handler(),
via exec_binprm(). Nearly all (see exception below) state used by
bprm_secureexec is created during the bprm_set_creds hook, called from
prepare_binprm().
For all LSMs (except commoncaps described next), only the first execution
of bprm_set_creds takes any effect (they all check bprm->cred_prepared which
prepare_binprm() sets after the first call to the bprm_set_creds hook).
However, all these LSMs also only do anything with bprm_secureexec when
they detected a secure state during their first run of bprm_set_creds.
Therefore, it is functionally identical to move the detection into
bprm_set_creds, since the results from secureexec here only need to be
based on the first call to the LSM's bprm_set_creds hook.
The single exception is that the commoncaps secureexec hook also examines
euid/uid and egid/gid differences which are controlled by bprm_fill_uid(),
via prepare_binprm(), which can be called multiple times (e.g.
binfmt_script, binfmt_misc), and may clear the euid/egid for the final
load (i.e. the script interpreter). However, while commoncaps specifically
ignores bprm->cred_prepared, and runs its bprm_set_creds hook each time
prepare_binprm() may get called, it needs to base the secureexec decision
on the final call to bprm_set_creds. As a result, it will need special
handling.
To begin this refactoring, this adds the secureexec flag to the bprm
struct, which will eventually be used in place of the LSM hook.
Cc: David Howells <dhowells@redhat.com>
Signed-off-by: Kees Cook <redacted>
looks good
Reviewed-by: John Johansen <john.johansen@canonical.com>
@@ -27,9 +27,15 @@ struct linux_binprm {unsignedintcred_prepared:1,/* true if creds already prepared (multiple*prepshappenforinterpreters)*/-cap_effective:1;/* true if has elevated effective capabilities,+cap_effective:1,/* true if has elevated effective capabilities,*falseifnot;exceptforinitwhichinherits*itsparent'scapsanyway*/+/*+*Setbybprm_set_credshooktoindicateaprivilege-gaining+*exechashappened.Usedtosanitizeexecutionenvironment+*andtosetAT_SECUREauxvforglibc.+*/+secureexec:1;#ifdef __alpha__unsignedinttaso:1;#endif
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: John Johansen <john.johansen@canonical.com> Date: 2017-07-19 00:08:08
On 07/18/2017 03:25 PM, Kees Cook wrote:
The cred_prepared bprm flag has a misleading name. It has nothing to do
with the bprm_prepare_cred hook, and actually tracks if bprm_set_creds has
been called. Rename this flag and improve its comment.
Cc: David Howells <dhowells@redhat.com>
Cc: John Johansen <john.johansen@canonical.com>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Stephen Smalley <redacted>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: James Morris <redacted>
Signed-off-by: Kees Cook <redacted>
looks good
Acked-by: John Johansen <john.johansen@canonical.com>
@@ -25,8 +25,12 @@ struct linux_binprm {structmm_struct*mm;unsignedlongp;/* current top of mem */unsignedint-cred_prepared:1,/* true if creds already prepared (multiple-*prepshappenforinterpreters)*/+/*+*Trueafterthebprm_set_credshookhasbeencalledonce+*(multiplecallscanbemadeviaprepare_binprm()for+*binfmt_script/misc).+*/+called_set_creds:1,cap_effective:1,/* true if has elevated effective capabilities,*falseifnot;exceptforinitwhichinherits*itsparent'scapsanyway*/
@@ -2327,7 +2327,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)/* SELinux context only depends on initial program or script and not*thescriptinterpreter*/-if(bprm->cred_prepared)+if(bprm->called_set_creds)return0;old_tsec=current_security();
@@ -76,7 +76,7 @@ static int tomoyo_bprm_set_creds(struct linux_binprm *bprm)*Doonlyifthisfunctioniscalledforthefirsttimeofanexecve*operation.*/-if(bprm->cred_prepared)+if(bprm->called_set_creds)return0;#ifndef CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER/*
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
@@ -27,9 +27,15 @@ struct linux_binprm {unsignedintcred_prepared:1,/* true if creds already prepared (multiple*prepshappenforinterpreters)*/-cap_effective:1;/* true if has elevated effective capabilities,+cap_effective:1,/* true if has elevated effective capabilities,*falseifnot;exceptforinitwhichinherits*itsparent'scapsanyway*/+/*+*Setbybprm_set_credshooktoindicateaprivilege-gaining+*exechashappened.Usedtosanitizeexecutionenvironment+*andtosetAT_SECUREauxvforglibc.+*/
... which is not bprm_set_creds().
What am I missing here?
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Andy Lutomirski <luto@kernel.org> Date: 2017-07-19 01:06:03
On Tue, Jul 18, 2017 at 3:25 PM, Kees Cook [off-list ref] wrote:
quoted hunk
The cred_prepared bprm flag has a misleading name. It has nothing to do
with the bprm_prepare_cred hook, and actually tracks if bprm_set_creds has
been called. Rename this flag and improve its comment.
Cc: David Howells <dhowells@redhat.com>
Cc: John Johansen <john.johansen@canonical.com>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Stephen Smalley <redacted>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: James Morris <redacted>
Signed-off-by: Kees Cook <redacted>
---
fs/binfmt_flat.c | 2 +-
fs/exec.c | 2 +-
include/linux/binfmts.h | 8 ++++++--
security/apparmor/domain.c | 2 +-
security/selinux/hooks.c | 2 +-
security/smack/smack_lsm.c | 2 +-
security/tomoyo/tomoyo.c | 2 +-
7 files changed, 12 insertions(+), 8 deletions(-)
WTF is this? It's not, strictly speaking, a bug in this patch, but
it's nonsensical. Is it fixed (presuably deleted) later?
Otherwise looks good.
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Andy Lutomirski <luto@kernel.org> Date: 2017-07-19 01:10:32
On Tue, Jul 18, 2017 at 3:25 PM, Kees Cook [off-list ref] wrote:
The commoncap implementation of the bprm_secureexec hook is the only LSM
that depends on the final call to its bprm_set_creds hook (since it may
be called for multiple files, it ignores bprm->called_set_creds). As a
result, it cannot safely _clear_ bprm->secureexec since other LSMs may
have set it. Instead, remove the bprm_secureexec hook by introducing a
new flag to bprm specific to commoncap: cap_elevated. This is similar to
cap_effective, but that is used for a specific subset of elevated
privileges, and exists solely to track state from bprm_set_creds to
bprm_secureexec. As such, it will be removed in the next patch.
Here, set the new bprm->cap_elevated flag when setuid/setgid has happened
from bprm_fill_uid() or fscapabilities have been prepared. This temporarily
moves the bprm_secureexec hook to a static inline. The helper will be
removed in the next patch; this makes the step easier to review and bisect,
since this does not introduce any changes to inputs nor outputs to the
"elevated privileges" calculation.
The new flag is merged with the bprm->secureexec flag in setup_new_exec()
since this marks the end of any further prepare_binprm() calls.
Reviewed-by: Andy Lutomirski <luto@kernel.org>
with the redundant caveat that...
...the weird placement of the other assignments to bprm->secureexec
makes this exceedingly confusing.
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Andy Lutomirski <luto@kernel.org> Date: 2017-07-19 01:52:31
On Tue, Jul 18, 2017 at 3:25 PM, Kees Cook [off-list ref] wrote:
Instead of a separate function, open-code the cap_elevated test, which
lets us entirely remove bprm->cap_effective (to use the local "effective"
variable instead), and more accurately examine euid/egid changes via the
existing local "is_setid".
I think this matches the old behavior. IOW it looks right.
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: "Serge E. Hallyn" <serge@hallyn.com> Date: 2017-07-19 03:22:05
On Tue, Jul 18, 2017 at 03:25:21PM -0700, Kees Cook wrote:
This series has grown... :P
As discussed with Linus and Andy, we need to reset the stack rlimit
before we do memory layouts when execing a privilege-gaining (e.g.
setuid) program. To do this, we need to know the results of the
bprm_secureexec hook before memory layouts. As it turns out, this
can be made _mostly_ trivial by collapsing bprm_secureexec into
bprm_set_creds.
The LSMs using bprm_secureexec nearly always save state between
bprm_set_creds and bprm_secureexec. In the face of multiple calls to
bprm_set_creds (via prepare_binprm() calls from binfmt_script, etc),
all LSMs except commoncap only pay attention to the first call, so
that aligns well with collapsing bprm_secureexec into bprm_set_creds.
The commoncaps, though, needs to check the _last_ bprm_set_creds, so
this series just swaps one bprm flag for another (cap_effective is no
longer needed to save state between bprm_set_creds and bprm_secureexec,
but we do need to keep a separate state, so we add the cap_elevated flag).
Once secureexec is available to setup_new_exec() before the memory
layout, we can add an rlimit sanity-check for setuid execs. (With no
need to clean up since we're past the point of no return.)
Along the way, this fixes comments, renames a variable, and consolidates
dumpability and pdeath_signal clearing, which includes some commit log
archeology to examine the subtle differences between what we had and
what we need.
I'd appreciate some extra eyes on this to make sure this isn't broken
in some special way. Looking at the diffstat, even after all my long
comments, this is a net reduction in lines. :)
Given this crosses a bunch of areas, I think this is likely best to
go via the -mm tree, which is where nearly all of my prior exec work
has lived too.
Thanks!
-Kees
----------------------------------------------------------------
Kees Cook (15):
binfmt: Introduce secureexec flag
exec: Rename bprm->cred_prepared to called_set_creds
apparmor: Refactor to remove bprm_secureexec hook
selinux: Refactor to remove bprm_secureexec hook
smack: Refactor to remove bprm_secureexec hook
commoncap: Refactor to remove bprm_secureexec hook
commoncap: Move cap_elevated calculation into bprm_set_creds
LSM: drop bprm_secureexec hook
exec: Correct comments about "point of no return"
exec: Use secureexec for setting dumpability
exec: Use secureexec for clearing pdeath_signal
smack: Remove redundant pdeath_signal clearing
exec: Consolidate dumpability logic
exec: Use sane stack rlimit under secureexec
exec: Consolidate pdeath_signal clearing
Thanks, the set looks good to me,
Acked-by: Serge Hallyn <serge@hallyn.com>
Have you had a chance to run the ltp caps tests against this?
-serge
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Jul 18, 2017 at 6:06 PM, Andy Lutomirski [off-list ref] wrote:
On Tue, Jul 18, 2017 at 3:25 PM, Kees Cook [off-list ref] wrote:
quoted
The cred_prepared bprm flag has a misleading name. It has nothing to do
with the bprm_prepare_cred hook, and actually tracks if bprm_set_creds has
been called. Rename this flag and improve its comment.
Cc: David Howells <dhowells@redhat.com>
Cc: John Johansen <john.johansen@canonical.com>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Stephen Smalley <redacted>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: James Morris <redacted>
Signed-off-by: Kees Cook <redacted>
---
fs/binfmt_flat.c | 2 +-
fs/exec.c | 2 +-
include/linux/binfmts.h | 8 ++++++--
security/apparmor/domain.c | 2 +-
security/selinux/hooks.c | 2 +-
security/smack/smack_lsm.c | 2 +-
security/tomoyo/tomoyo.c | 2 +-
7 files changed, 12 insertions(+), 8 deletions(-)
WTF is this? It's not, strictly speaking, a bug in this patch, but
it's nonsensical. Is it fixed (presuably deleted) later?
binfmt_flat looks crazy, but I haven't seen any distros that enable it.
Otherwise looks good.
Thanks!
-Kees
--
Kees Cook
Pixel Security
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Jul 18, 2017 at 6:10 PM, Andy Lutomirski [off-list ref] wrote:
On Tue, Jul 18, 2017 at 3:25 PM, Kees Cook [off-list ref] wrote:
quoted
The commoncap implementation of the bprm_secureexec hook is the only LSM
that depends on the final call to its bprm_set_creds hook (since it may
be called for multiple files, it ignores bprm->called_set_creds). As a
result, it cannot safely _clear_ bprm->secureexec since other LSMs may
have set it. Instead, remove the bprm_secureexec hook by introducing a
new flag to bprm specific to commoncap: cap_elevated. This is similar to
cap_effective, but that is used for a specific subset of elevated
privileges, and exists solely to track state from bprm_set_creds to
bprm_secureexec. As such, it will be removed in the next patch.
Here, set the new bprm->cap_elevated flag when setuid/setgid has happened
from bprm_fill_uid() or fscapabilities have been prepared. This temporarily
moves the bprm_secureexec hook to a static inline. The helper will be
removed in the next patch; this makes the step easier to review and bisect,
since this does not introduce any changes to inputs nor outputs to the
"elevated privileges" calculation.
The new flag is merged with the bprm->secureexec flag in setup_new_exec()
since this marks the end of any further prepare_binprm() calls.
Reviewed-by: Andy Lutomirski <luto@kernel.org>
with the redundant caveat that...
...the weird placement of the other assignments to bprm->secureexec
makes this exceedingly confusing.
Any thoughts on how I could improve this? The main take-away is that
commoncap's secureexec is special, and this was the cleanest way I
could find to deal with it...
-Kees
--
Kees Cook
Pixel Security
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Jul 18, 2017 at 8:22 PM, Serge E. Hallyn [off-list ref] wrote:
On Tue, Jul 18, 2017 at 03:25:21PM -0700, Kees Cook wrote:
quoted
This series has grown... :P
As discussed with Linus and Andy, we need to reset the stack rlimit
before we do memory layouts when execing a privilege-gaining (e.g.
setuid) program. To do this, we need to know the results of the
bprm_secureexec hook before memory layouts. As it turns out, this
can be made _mostly_ trivial by collapsing bprm_secureexec into
bprm_set_creds.
The LSMs using bprm_secureexec nearly always save state between
bprm_set_creds and bprm_secureexec. In the face of multiple calls to
bprm_set_creds (via prepare_binprm() calls from binfmt_script, etc),
all LSMs except commoncap only pay attention to the first call, so
that aligns well with collapsing bprm_secureexec into bprm_set_creds.
The commoncaps, though, needs to check the _last_ bprm_set_creds, so
this series just swaps one bprm flag for another (cap_effective is no
longer needed to save state between bprm_set_creds and bprm_secureexec,
but we do need to keep a separate state, so we add the cap_elevated flag).
Once secureexec is available to setup_new_exec() before the memory
layout, we can add an rlimit sanity-check for setuid execs. (With no
need to clean up since we're past the point of no return.)
Along the way, this fixes comments, renames a variable, and consolidates
dumpability and pdeath_signal clearing, which includes some commit log
archeology to examine the subtle differences between what we had and
what we need.
I'd appreciate some extra eyes on this to make sure this isn't broken
in some special way. Looking at the diffstat, even after all my long
comments, this is a net reduction in lines. :)
Given this crosses a bunch of areas, I think this is likely best to
go via the -mm tree, which is where nearly all of my prior exec work
has lived too.
Thanks!
-Kees
----------------------------------------------------------------
Kees Cook (15):
binfmt: Introduce secureexec flag
exec: Rename bprm->cred_prepared to called_set_creds
apparmor: Refactor to remove bprm_secureexec hook
selinux: Refactor to remove bprm_secureexec hook
smack: Refactor to remove bprm_secureexec hook
commoncap: Refactor to remove bprm_secureexec hook
commoncap: Move cap_elevated calculation into bprm_set_creds
LSM: drop bprm_secureexec hook
exec: Correct comments about "point of no return"
exec: Use secureexec for setting dumpability
exec: Use secureexec for clearing pdeath_signal
smack: Remove redundant pdeath_signal clearing
exec: Consolidate dumpability logic
exec: Use sane stack rlimit under secureexec
exec: Consolidate pdeath_signal clearing
Thanks, the set looks good to me,
Thanks!
Acked-by: Serge Hallyn <serge@hallyn.com>
Have you had a chance to run the ltp caps tests against this?
The LTP caps tests I could find are these:
sudo ./runltp -f syscalls -s cap
sudo ./runltp -f securebits
sudo ./runltp -f cap_bounds
sudo ./runltp -f filecaps
They all run successfully. Was there other stuff from LTP?
And, FWIW, the kernel selftests for capabilities and exec continue to pass too.
-Kees
--
Kees Cook
Pixel Security
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: James Morris <jmorris@namei.org> Date: 2017-07-19 09:20:08
On Tue, 18 Jul 2017, Kees Cook wrote:
The cred_prepared bprm flag has a misleading name. It has nothing to do
with the bprm_prepare_cred hook, and actually tracks if bprm_set_creds has
been called. Rename this flag and improve its comment.
Cc: David Howells <dhowells@redhat.com>
Cc: John Johansen <john.johansen@canonical.com>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Stephen Smalley <redacted>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: James Morris <redacted>
Signed-off-by: Kees Cook <redacted>
Acked-by: James Morris <redacted>
--
James Morris
[off-list ref]
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: James Morris <jmorris@namei.org> Date: 2017-07-19 09:22:21
On Tue, 18 Jul 2017, Kees Cook wrote:
The AppArmor bprm_secureexec hook can be merged with the bprm_set_creds
hook since it's dealing with the same information, and all of the details
are finalized during the first call to the bprm_set_creds hook via
prepare_binprm() (subsequent calls due to binfmt_script, etc, are ignored
via bprm->called_set_creds).
Here, all the comments describe how secureexec is actually calculated
during bprm_set_creds, so this actually does it, drops the bprm flag that
was being used internally by AppArmor, and drops the bprm_secureexec hook.
Cc: John Johansen <john.johansen@canonical.com>
Signed-off-by: Kees Cook <redacted>
Reviewed-by: James Morris <redacted>
--
James Morris
[off-list ref]
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: James Morris <jmorris@namei.org> Date: 2017-07-19 09:26:49
On Tue, 18 Jul 2017, Kees Cook wrote:
The commoncap implementation of the bprm_secureexec hook is the only LSM
that depends on the final call to its bprm_set_creds hook (since it may
be called for multiple files, it ignores bprm->called_set_creds). As a
result, it cannot safely _clear_ bprm->secureexec since other LSMs may
have set it. Instead, remove the bprm_secureexec hook by introducing a
new flag to bprm specific to commoncap: cap_elevated. This is similar to
cap_effective, but that is used for a specific subset of elevated
privileges, and exists solely to track state from bprm_set_creds to
bprm_secureexec. As such, it will be removed in the next patch.
Here, set the new bprm->cap_elevated flag when setuid/setgid has happened
from bprm_fill_uid() or fscapabilities have been prepared. This temporarily
moves the bprm_secureexec hook to a static inline. The helper will be
removed in the next patch; this makes the step easier to review and bisect,
since this does not introduce any changes to inputs nor outputs to the
"elevated privileges" calculation.
The new flag is merged with the bprm->secureexec flag in setup_new_exec()
since this marks the end of any further prepare_binprm() calls.
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Kees Cook <redacted>
Acked-by: James Morris <redacted>
--
James Morris
[off-list ref]
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: James Morris <jmorris@namei.org> Date: 2017-07-19 09:28:56
On Tue, 18 Jul 2017, Kees Cook wrote:
Instead of a separate function, open-code the cap_elevated test, which
lets us entirely remove bprm->cap_effective (to use the local "effective"
variable instead), and more accurately examine euid/egid changes via the
existing local "is_setid".
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Kees Cook <redacted>
Reviewed-by: James Morris <redacted>
--
James Morris
[off-list ref]
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: James Morris <jmorris@namei.org> Date: 2017-07-19 09:29:46
On Tue, 18 Jul 2017, Kees Cook wrote:
This removes the bprm_secureexec hook since the logic has been folded into
the bprm_set_creds hook for all LSMs now.
Cc: James Morris <redacted>
Cc: Eric W. Biederman <redacted>
Signed-off-by: Kees Cook <redacted>
---
fs/binfmt_elf.c | 1 -
fs/binfmt_elf_fdpic.c | 1 -
include/linux/lsm_hooks.h | 14 +++++---------
include/linux/security.h | 7 -------
security/security.c | 5 -----
5 files changed, 5 insertions(+), 23 deletions(-)
Acked-by: James Morris <redacted>
--
James Morris
[off-list ref]
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: James Morris <jmorris@namei.org> Date: 2017-07-19 09:43:13
On Tue, 18 Jul 2017, Kees Cook wrote:
For a secureexec, before memory layout selection has happened, reset the
stack rlimit to something sane to avoid the caller having control over
the resulting layouts.
$ ulimit -s
8192
$ ulimit -s unlimited
$ /bin/sh -c 'ulimit -s'
unlimited
$ sudo /bin/sh -c 'ulimit -s'
8192
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Kees Cook <redacted>
Reviewed-by: James Morris <redacted>
--
James Morris
[off-list ref]
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Paul Moore <paul@paul-moore.com> Date: 2017-07-19 23:56:48
On Tue, Jul 18, 2017 at 6:25 PM, Kees Cook [off-list ref] wrote:
The cred_prepared bprm flag has a misleading name. It has nothing to do
with the bprm_prepare_cred hook, and actually tracks if bprm_set_creds has
been called. Rename this flag and improve its comment.
Cc: David Howells <dhowells@redhat.com>
Cc: John Johansen <john.johansen@canonical.com>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Stephen Smalley <redacted>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: James Morris <redacted>
Signed-off-by: Kees Cook <redacted>
---
fs/binfmt_flat.c | 2 +-
fs/exec.c | 2 +-
include/linux/binfmts.h | 8 ++++++--
security/apparmor/domain.c | 2 +-
security/selinux/hooks.c | 2 +-
security/smack/smack_lsm.c | 2 +-
security/tomoyo/tomoyo.c | 2 +-
7 files changed, 12 insertions(+), 8 deletions(-)
Acked-by: Paul Moore <paul@paul-moore.com>
--
paul moore
www.paul-moore.com
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Paul Moore <paul@paul-moore.com> Date: 2017-07-20 00:03:30
On Tue, Jul 18, 2017 at 6:25 PM, Kees Cook [off-list ref] wrote:
The SELinux bprm_secureexec hook can be merged with the bprm_set_creds
hook since it's dealing with the same information, and all of the details
are finalized during the first call to the bprm_set_creds hook via
prepare_binprm() (subsequent calls due to binfmt_script, etc, are ignored
via bprm->called_set_creds).
Here, the test can just happen at the end of the bprm_set_creds hook,
and the bprm_secureexec hook can be dropped.
Cc: Paul Moore <paul@paul-moore.com>
Cc: Stephen Smalley <redacted>
Signed-off-by: Kees Cook <redacted>
---
security/selinux/hooks.c | 24 +++++-------------------
1 file changed, 5 insertions(+), 19 deletions(-)
This seems reasonable in the context of the other changes.
Stephen just posted an AT_SECURE test for the selinux-testsuite on the
SELinux mailing list, it would be nice to ensure that this patchset
doesn't run afoul of that.
Acked-by: Paul Moore <paul@paul-moore.com>
--
paul moore
www.paul-moore.com
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Paul Moore <paul@paul-moore.com> Date: 2017-07-20 00:19:35
On Wed, Jul 19, 2017 at 8:03 PM, Paul Moore [off-list ref] wrote:
On Tue, Jul 18, 2017 at 6:25 PM, Kees Cook [off-list ref] wrote:
quoted
The SELinux bprm_secureexec hook can be merged with the bprm_set_creds
hook since it's dealing with the same information, and all of the details
are finalized during the first call to the bprm_set_creds hook via
prepare_binprm() (subsequent calls due to binfmt_script, etc, are ignored
via bprm->called_set_creds).
Here, the test can just happen at the end of the bprm_set_creds hook,
and the bprm_secureexec hook can be dropped.
Cc: Paul Moore <paul@paul-moore.com>
Cc: Stephen Smalley <redacted>
Signed-off-by: Kees Cook <redacted>
---
security/selinux/hooks.c | 24 +++++-------------------
1 file changed, 5 insertions(+), 19 deletions(-)
This seems reasonable in the context of the other changes.
Stephen just posted an AT_SECURE test for the selinux-testsuite on the
SELinux mailing list, it would be nice to ensure that this patchset
doesn't run afoul of that.
--
paul moore
www.paul-moore.com
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, Jul 19, 2017 at 5:19 PM, Paul Moore [off-list ref] wrote:
On Wed, Jul 19, 2017 at 8:03 PM, Paul Moore [off-list ref] wrote:
quoted
On Tue, Jul 18, 2017 at 6:25 PM, Kees Cook [off-list ref] wrote:
quoted
The SELinux bprm_secureexec hook can be merged with the bprm_set_creds
hook since it's dealing with the same information, and all of the details
are finalized during the first call to the bprm_set_creds hook via
prepare_binprm() (subsequent calls due to binfmt_script, etc, are ignored
via bprm->called_set_creds).
Here, the test can just happen at the end of the bprm_set_creds hook,
and the bprm_secureexec hook can be dropped.
Cc: Paul Moore <paul@paul-moore.com>
Cc: Stephen Smalley <redacted>
Signed-off-by: Kees Cook <redacted>
---
security/selinux/hooks.c | 24 +++++-------------------
1 file changed, 5 insertions(+), 19 deletions(-)
This seems reasonable in the context of the other changes.
Stephen just posted an AT_SECURE test for the selinux-testsuite on the
SELinux mailing list, it would be nice to ensure that this patchset
doesn't run afoul of that.
Is there a quick how-to on just running the AT_SECURE test?
-Kees
--
Kees Cook
Pixel Security
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Andy Lutomirski <luto@kernel.org> Date: 2017-07-20 04:54:01
On Tue, Jul 18, 2017 at 6:10 PM, Andy Lutomirski [off-list ref] wrote:
On Tue, Jul 18, 2017 at 3:25 PM, Kees Cook [off-list ref] wrote:
quoted
The commoncap implementation of the bprm_secureexec hook is the only LSM
that depends on the final call to its bprm_set_creds hook (since it may
be called for multiple files, it ignores bprm->called_set_creds). As a
result, it cannot safely _clear_ bprm->secureexec since other LSMs may
have set it. Instead, remove the bprm_secureexec hook by introducing a
new flag to bprm specific to commoncap: cap_elevated. This is similar to
cap_effective, but that is used for a specific subset of elevated
privileges, and exists solely to track state from bprm_set_creds to
bprm_secureexec. As such, it will be removed in the next patch.
Here, set the new bprm->cap_elevated flag when setuid/setgid has happened
from bprm_fill_uid() or fscapabilities have been prepared. This temporarily
moves the bprm_secureexec hook to a static inline. The helper will be
removed in the next patch; this makes the step easier to review and bisect,
since this does not introduce any changes to inputs nor outputs to the
"elevated privileges" calculation.
The new flag is merged with the bprm->secureexec flag in setup_new_exec()
since this marks the end of any further prepare_binprm() calls.
Reviewed-by: Andy Lutomirski <luto@kernel.org>
with the redundant caveat that...
...the weird placement of the other assignments to bprm->secureexec
makes this exceedingly confusing.
Can you just put the bprm->secureexec |=
security_bprm_secureexec(bprm); assignment in prepare_binprm() right
after security_bprm_set_creds()? This would make patch 1 make sense
and make this make sense too, I think. Or is there some reason why it
wouldn't work? If the latter, I think the patch descriptions and
comments should maybe be fixed up.
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Paul Moore <paul@paul-moore.com> Date: 2017-07-20 13:42:11
On Wed, Jul 19, 2017 at 9:37 PM, Kees Cook [off-list ref] wrote:
On Wed, Jul 19, 2017 at 5:19 PM, Paul Moore [off-list ref] wrote:
quoted
On Wed, Jul 19, 2017 at 8:03 PM, Paul Moore [off-list ref] wrote:
quoted
On Tue, Jul 18, 2017 at 6:25 PM, Kees Cook [off-list ref] wrote:
quoted
The SELinux bprm_secureexec hook can be merged with the bprm_set_creds
hook since it's dealing with the same information, and all of the details
are finalized during the first call to the bprm_set_creds hook via
prepare_binprm() (subsequent calls due to binfmt_script, etc, are ignored
via bprm->called_set_creds).
Here, the test can just happen at the end of the bprm_set_creds hook,
and the bprm_secureexec hook can be dropped.
Cc: Paul Moore <paul@paul-moore.com>
Cc: Stephen Smalley <redacted>
Signed-off-by: Kees Cook <redacted>
---
security/selinux/hooks.c | 24 +++++-------------------
1 file changed, 5 insertions(+), 19 deletions(-)
This seems reasonable in the context of the other changes.
Stephen just posted an AT_SECURE test for the selinux-testsuite on the
SELinux mailing list, it would be nice to ensure that this patchset
doesn't run afoul of that.
Is there a quick how-to on just running the AT_SECURE test?
You'll need a functional SELinux system to start, I run it against
Fedora Rawhide regularly* with various development kernels, but recent
stable Fedora releases should work too. Occasionally I hear of people
running it on Debian, but I haven't had a Debian SELinux system in
some time so I can't say for certain everything is 100% working there.
Once you've gotten a working system in enforcing mode, read the README
file in the test suite to install the necessary dependencies (look in
the "Userland and Base Policy" section), then build the tests/policy
(you should be able to skip this step, as the make dependencies will
handle it, but it is nice to do it separately to make sure you have
the build dependencies sorted):
# make
... load the test policy
# make -C policy load
... run the tests:
# cd tests/atsecure
# ./test
... optionally uninstall the test policy:
# make -C policy unload
In some ways it is easier to just run the entire test suite:
# make
# make test
Alternatively, if you've got a fairly recent git repo with all the
patches merged I can build a test kernel and give it a shot for you,
although fair warning it may take a day or two for me to get to it.
* It is worth noting that the current 4.13-rcX releases have two bugs
that affect the selinux-testsuite. The worst is a kernel panic due to
a bug in overlayfs' xattr code, there is a patch available to fix it,
but as of yesterday it hadn't yet hit Linus tree (I can dig it up if
you need it). The second issue related to IPsec and getting peer
label information over UDP connections, I haven't had a chance to sort
that out yet, but at least it isn't a kernel panic.
--
paul moore
www.paul-moore.com
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, Jul 20, 2017 at 6:42 AM, Paul Moore [off-list ref] wrote:
Alternatively, if you've got a fairly recent git repo with all the
patches merged I can build a test kernel and give it a shot for you,
although fair warning it may take a day or two for me to get to it.
Hurm, I think this will take quite a bit of time for me to set up. :P
If you have a chance, I'd appreciate it if you could test the series.
It's currently based on v4.12:
https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/log/?h=kspp/setuid-rlimits/secureexec-no-hook
If it doesn't work out or takes too much time I can work on setting up
the test environment next week (travelling at the moment).
Thanks for the details!
-Kees
--
Kees Cook
Pixel Security
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Paul Moore <paul@paul-moore.com> Date: 2017-07-20 20:42:11
On Thu, Jul 20, 2017 at 1:06 PM, Kees Cook [off-list ref] wrote:
On Thu, Jul 20, 2017 at 6:42 AM, Paul Moore [off-list ref] wrote:
quoted
Alternatively, if you've got a fairly recent git repo with all the
patches merged I can build a test kernel and give it a shot for you,
although fair warning it may take a day or two for me to get to it.
From: Paul Moore <paul@paul-moore.com> Date: 2017-07-21 15:40:31
On Thu, Jul 20, 2017 at 4:42 PM, Paul Moore [off-list ref] wrote:
On Thu, Jul 20, 2017 at 1:06 PM, Kees Cook [off-list ref] wrote:
quoted
On Thu, Jul 20, 2017 at 6:42 AM, Paul Moore [off-list ref] wrote:
quoted
Alternatively, if you've got a fairly recent git repo with all the
patches merged I can build a test kernel and give it a shot for you,
although fair warning it may take a day or two for me to get to it.
Quick follow up, the kernel above passes the selinux-testsuite atsecure test.
--
paul moore
www.paul-moore.com
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Fri, Jul 21, 2017 at 8:40 AM, Paul Moore [off-list ref] wrote:
On Thu, Jul 20, 2017 at 4:42 PM, Paul Moore [off-list ref] wrote:
quoted
On Thu, Jul 20, 2017 at 1:06 PM, Kees Cook [off-list ref] wrote:
quoted
On Thu, Jul 20, 2017 at 6:42 AM, Paul Moore [off-list ref] wrote:
quoted
Alternatively, if you've got a fairly recent git repo with all the
patches merged I can build a test kernel and give it a shot for you,
although fair warning it may take a day or two for me to get to it.
Quick follow up, the kernel above passes the selinux-testsuite atsecure test.
Awesome, thanks for taking the time to test it. :) Can I add your Tested-by?
-Kees
--
Kees Cook
Pixel Security
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Paul Moore <paul@paul-moore.com> Date: 2017-07-21 19:16:26
On Fri, Jul 21, 2017 at 1:37 PM, Kees Cook [off-list ref] wrote:
On Fri, Jul 21, 2017 at 8:40 AM, Paul Moore [off-list ref] wrote:
quoted
On Thu, Jul 20, 2017 at 4:42 PM, Paul Moore [off-list ref] wrote:
quoted
On Thu, Jul 20, 2017 at 1:06 PM, Kees Cook [off-list ref] wrote:
quoted
On Thu, Jul 20, 2017 at 6:42 AM, Paul Moore [off-list ref] wrote:
quoted
Alternatively, if you've got a fairly recent git repo with all the
patches merged I can build a test kernel and give it a shot for you,
although fair warning it may take a day or two for me to get to it.
Quick follow up, the kernel above passes the selinux-testsuite atsecure test.
Awesome, thanks for taking the time to test it. :) Can I add your Tested-by?
Sorry, I should have included that, here ya go:
Tested-by: Paul Moore <paul@paul-moore.com>
--
paul moore
www.paul-moore.com
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Jul 18, 2017 at 3:25 PM, Kees Cook [off-list ref] wrote:
The Smack bprm_secureexec hook can be merged with the bprm_set_creds
hook since it's dealing with the same information, and all of the details
are finalized during the first call to the bprm_set_creds hook via
prepare_binprm() (subsequent calls due to binfmt_script, etc, are ignored
via bprm->called_set_creds).
Here, the test can just happen at the end of the bprm_set_creds hook,
and the bprm_secureexec hook can be dropped.
Cc: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Kees Cook <redacted>
How does this look to you, Casey? I've only got a few unreviewed
patches in this series. Two touch Smack. :)
Thanks!
-Kees
@@ -950,6 +950,10 @@ static int smack_bprm_set_creds(struct linux_binprm *bprm)bsp->smk_task=isp->smk_task;bprm->per_clear|=PER_CLEAR_ON_SETID;+/* Decide if this is a secure exec. */+if(bsp->smk_task!=bsp->smk_forked)+bprm->secureexec=1;+return0;}
--
Kees Cook
Pixel Security
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Jul 18, 2017 at 3:25 PM, Kees Cook [off-list ref] wrote:
The examination of "current" to decide dumpability is wrong. This was a
check of and euid/uid (or egid/gid) mismatch in the existing process,
not the newly created one. This appears to stretch back into even the
"history.git" tree. Luckily, dumpability is later set in commit_creds().
In earlier kernel versions before creds existed, similar checks also
existed late in the exec flow, covering up the mistake as far back as I
could find.
Note that because the commit_creds() check examines differences of euid,
uid, egid, gid, and capabilities between the old and new creds, it would
look like the setup_new_exec() dumpability test could be entirely removed.
However, the secureexec test may cover a different set of tests (specific
to the LSMs) than what commit_creds() checks for. So, fix this test to
use secureexec (the removed euid tests are redundant to the commoncap
secureexec checks now).
Cc: David Howells <dhowells@redhat.com>
Signed-off-by: Kees Cook <redacted>
David (or anyone else), how does this (and the following undiscussed
patches) look? I only have a few unreviewed patches in this series,
and I'd like to get some more eyes on it.
Thanks!
-Kees
--
Kees Cook
Pixel Security
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Jul 18, 2017 at 3:25 PM, Kees Cook [off-list ref] wrote:
quoted
The Smack bprm_secureexec hook can be merged with the bprm_set_creds
hook since it's dealing with the same information, and all of the details
are finalized during the first call to the bprm_set_creds hook via
prepare_binprm() (subsequent calls due to binfmt_script, etc, are ignored
via bprm->called_set_creds).
Here, the test can just happen at the end of the bprm_set_creds hook,
and the bprm_secureexec hook can be dropped.
Cc: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Kees Cook <redacted>
How does this look to you, Casey? I've only got a few unreviewed
patches in this series. Two touch Smack. :)
The eyes don't see any problems, but I haven't had a chance
to try it out.
@@ -950,6 +950,10 @@ static int smack_bprm_set_creds(struct linux_binprm *bprm)bsp->smk_task=isp->smk_task;bprm->per_clear|=PER_CLEAR_ON_SETID;+/* Decide if this is a secure exec. */+if(bsp->smk_task!=bsp->smk_forked)+bprm->secureexec=1;+return0;}
.
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, Jul 19, 2017 at 9:53 PM, Andy Lutomirski [off-list ref] wrote:
On Tue, Jul 18, 2017 at 6:10 PM, Andy Lutomirski [off-list ref] wrote:
quoted
On Tue, Jul 18, 2017 at 3:25 PM, Kees Cook [off-list ref] wrote:
quoted
The commoncap implementation of the bprm_secureexec hook is the only LSM
that depends on the final call to its bprm_set_creds hook (since it may
be called for multiple files, it ignores bprm->called_set_creds). As a
result, it cannot safely _clear_ bprm->secureexec since other LSMs may
have set it. Instead, remove the bprm_secureexec hook by introducing a
new flag to bprm specific to commoncap: cap_elevated. This is similar to
cap_effective, but that is used for a specific subset of elevated
privileges, and exists solely to track state from bprm_set_creds to
bprm_secureexec. As such, it will be removed in the next patch.
Here, set the new bprm->cap_elevated flag when setuid/setgid has happened
from bprm_fill_uid() or fscapabilities have been prepared. This temporarily
moves the bprm_secureexec hook to a static inline. The helper will be
removed in the next patch; this makes the step easier to review and bisect,
since this does not introduce any changes to inputs nor outputs to the
"elevated privileges" calculation.
The new flag is merged with the bprm->secureexec flag in setup_new_exec()
since this marks the end of any further prepare_binprm() calls.
Reviewed-by: Andy Lutomirski <luto@kernel.org>
with the redundant caveat that...
...the weird placement of the other assignments to bprm->secureexec
makes this exceedingly confusing.
Can you just put the bprm->secureexec |=
security_bprm_secureexec(bprm); assignment in prepare_binprm() right
after security_bprm_set_creds()? This would make patch 1 make sense
and make this make sense too, I think. Or is there some reason why it
wouldn't work? If the latter, I think the patch descriptions and
comments should maybe be fixed up.
Yeah, I'll make this change for the next version. It makes things a
little less ugly in the series. In this version I was trying to focus
on eliminating the LSM hook instead of first moving it (to
setup_new_exec()) and then moving it a second time (to the
bprm_set_creds() hook).
Have you had a chance to review the later consolidation patches? So
far no one else has reviewed those. (David, any chance you have some
time too?) I'd love to get at least some Reviewed-bys for them...
-Kees
--
Kees Cook
Pixel Security
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Andy Lutomirski <luto@kernel.org> Date: 2017-08-01 13:12:53
On Mon, Jul 31, 2017 at 3:43 PM, Kees Cook [off-list ref] wrote:
On Wed, Jul 19, 2017 at 9:53 PM, Andy Lutomirski [off-list ref] wrote:
quoted
On Tue, Jul 18, 2017 at 6:10 PM, Andy Lutomirski [off-list ref] wrote:
quoted
On Tue, Jul 18, 2017 at 3:25 PM, Kees Cook [off-list ref] wrote:
quoted
The commoncap implementation of the bprm_secureexec hook is the only LSM
that depends on the final call to its bprm_set_creds hook (since it may
be called for multiple files, it ignores bprm->called_set_creds). As a
result, it cannot safely _clear_ bprm->secureexec since other LSMs may
have set it. Instead, remove the bprm_secureexec hook by introducing a
new flag to bprm specific to commoncap: cap_elevated. This is similar to
cap_effective, but that is used for a specific subset of elevated
privileges, and exists solely to track state from bprm_set_creds to
bprm_secureexec. As such, it will be removed in the next patch.
Here, set the new bprm->cap_elevated flag when setuid/setgid has happened
from bprm_fill_uid() or fscapabilities have been prepared. This temporarily
moves the bprm_secureexec hook to a static inline. The helper will be
removed in the next patch; this makes the step easier to review and bisect,
since this does not introduce any changes to inputs nor outputs to the
"elevated privileges" calculation.
The new flag is merged with the bprm->secureexec flag in setup_new_exec()
since this marks the end of any further prepare_binprm() calls.
Reviewed-by: Andy Lutomirski <luto@kernel.org>
with the redundant caveat that...
...the weird placement of the other assignments to bprm->secureexec
makes this exceedingly confusing.
Can you just put the bprm->secureexec |=
security_bprm_secureexec(bprm); assignment in prepare_binprm() right
after security_bprm_set_creds()? This would make patch 1 make sense
and make this make sense too, I think. Or is there some reason why it
wouldn't work? If the latter, I think the patch descriptions and
comments should maybe be fixed up.
Yeah, I'll make this change for the next version. It makes things a
little less ugly in the series. In this version I was trying to focus
on eliminating the LSM hook instead of first moving it (to
setup_new_exec()) and then moving it a second time (to the
bprm_set_creds() hook).
Have you had a chance to review the later consolidation patches? So
far no one else has reviewed those. (David, any chance you have some
time too?) I'd love to get at least some Reviewed-bys for them...
I looked briefly. I'll try to look more closely tomorrow.
--Andy
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html