Skip to content

Commit 9fbc2c7

Browse files
rgbriggsJames Morris
authored andcommitted
capabilities: move audit log decision to function
Move the audit log decision logic to its own function to isolate the complexity in one place. Suggested-by: Serge Hallyn <serge@hallyn.com> Signed-off-by: Richard Guy Briggs <rgb@redhat.com> Reviewed-by: Serge Hallyn <serge@hallyn.com> Acked-by: James Morris <james.l.morris@oracle.com> Acked-by: Kees Cook <keescook@chromium.org> Okay-ished-by: Paul Moore <paul@paul-moore.com> Signed-off-by: James Morris <james.l.morris@oracle.com>
1 parent 81a6a01 commit 9fbc2c7

1 file changed

Lines changed: 30 additions & 20 deletions

File tree

‎security/commoncap.c‎

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,32 @@ static inline bool __is_setuid(struct cred *new, const struct cred *old)
765765
static inline bool __is_setgid(struct cred *new, const struct cred *old)
766766
{ return !gid_eq(new->egid, old->gid); }
767767

768+
/*
769+
* Audit candidate if current->cap_effective is set
770+
*
771+
* We do not bother to audit if 3 things are true:
772+
* 1) cap_effective has all caps
773+
* 2) we are root
774+
* 3) root is supposed to have all caps (SECURE_NOROOT)
775+
* Since this is just a normal root execing a process.
776+
*
777+
* Number 1 above might fail if you don't have a full bset, but I think
778+
* that is interesting information to audit.
779+
*/
780+
static inline bool nonroot_raised_pE(struct cred *cred, kuid_t root)
781+
{
782+
bool ret = false;
783+
784+
if (__cap_grew(effective, ambient, cred)) {
785+
if (!__cap_full(effective, cred) ||
786+
!__is_eff(root, cred) || !__is_real(root, cred) ||
787+
!root_privileged()) {
788+
ret = true;
789+
}
790+
}
791+
return ret;
792+
}
793+
768794
/**
769795
* cap_bprm_set_creds - Set up the proposed credentials for execve().
770796
* @bprm: The execution parameters, including the proposed creds
@@ -841,26 +867,10 @@ int cap_bprm_set_creds(struct linux_binprm *bprm)
841867
if (WARN_ON(!cap_ambient_invariant_ok(new)))
842868
return -EPERM;
843869

844-
/*
845-
* Audit candidate if current->cap_effective is set
846-
*
847-
* We do not bother to audit if 3 things are true:
848-
* 1) cap_effective has all caps
849-
* 2) we are root
850-
* 3) root is supposed to have all caps (SECURE_NOROOT)
851-
* Since this is just a normal root execing a process.
852-
*
853-
* Number 1 above might fail if you don't have a full bset, but I think
854-
* that is interesting information to audit.
855-
*/
856-
if (__cap_grew(effective, ambient, new)) {
857-
if (!__cap_full(effective, new) ||
858-
!__is_eff(root_uid, new) || !__is_real(root_uid, new) ||
859-
!root_privileged()) {
860-
ret = audit_log_bprm_fcaps(bprm, new, old);
861-
if (ret < 0)
862-
return ret;
863-
}
870+
if (nonroot_raised_pE(new, root_uid)) {
871+
ret = audit_log_bprm_fcaps(bprm, new, old);
872+
if (ret < 0)
873+
return ret;
864874
}
865875

866876
new->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);

0 commit comments

Comments
 (0)