Skip to content

Commit dbbbe11

Browse files
rgbriggsJames Morris
authored andcommitted
capabilities: audit log other surprising conditions
The existing condition tested for process effective capabilities set by file attributes but intended to ignore the change if the result was unsurprisingly an effective full set in the case root is special with a setuid root executable file and we are root. Stated again: - When you execute a setuid root application, it is no surprise and expected that it got all capabilities, so we do not want capabilities recorded. if (pE_grew && !(pE_fullset && (eff_root || real_root) && root_priveleged) ) Now make sure we cover other cases: - If something prevented a setuid root app getting all capabilities and it wound up with one capability only, then it is a surprise and should be logged. When it is a setuid root file, we only want capabilities when the process does not get full capabilities.. root_priveleged && setuid_root && !pE_fullset - Similarly if a non-setuid program does pick up capabilities due to file system based capabilities, then we want to know what capabilities were picked up. When it has file system based capabilities we want the capabilities. !is_setuid && (has_fcap && pP_gained) - If it is a non-setuid file and it gets ambient capabilities, we want the capabilities. !is_setuid && pA_gained - These last two are combined into one due to the common first parameter. Related: linux-audit/audit-kernel#16 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> Acked-by: Paul Moore <paul@paul-moore.com> Signed-off-by: James Morris <james.l.morris@oracle.com>
1 parent 588fb2c commit dbbbe11

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

‎security/commoncap.c‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ static inline bool __is_setgid(struct cred *new, const struct cred *old)
766766
{ return !gid_eq(new->egid, old->gid); }
767767

768768
/*
769-
* Audit candidate if current->cap_effective is set
769+
* 1) Audit candidate if current->cap_effective is set
770770
*
771771
* We do not bother to audit if 3 things are true:
772772
* 1) cap_effective has all caps
@@ -776,16 +776,31 @@ static inline bool __is_setgid(struct cred *new, const struct cred *old)
776776
*
777777
* Number 1 above might fail if you don't have a full bset, but I think
778778
* that is interesting information to audit.
779+
*
780+
* A number of other conditions require logging:
781+
* 2) something prevented setuid root getting all caps
782+
* 3) non-setuid root gets fcaps
783+
* 4) non-setuid root gets ambient
779784
*/
780-
static inline bool nonroot_raised_pE(struct cred *cred, kuid_t root)
785+
static inline bool nonroot_raised_pE(struct cred *new, const struct cred *old,
786+
kuid_t root, bool has_fcap)
781787
{
782788
bool ret = false;
783789

784-
if (__cap_grew(effective, ambient, cred) &&
785-
!(__cap_full(effective, cred) &&
786-
(__is_eff(root, cred) || __is_real(root, cred)) &&
787-
root_privileged()))
790+
if ((__cap_grew(effective, ambient, new) &&
791+
!(__cap_full(effective, new) &&
792+
(__is_eff(root, new) || __is_real(root, new)) &&
793+
root_privileged())) ||
794+
(root_privileged() &&
795+
__is_suid(root, new) &&
796+
!__cap_full(effective, new)) ||
797+
(!__is_setuid(new, old) &&
798+
((has_fcap &&
799+
__cap_gained(permitted, new, old)) ||
800+
__cap_gained(ambient, new, old))))
801+
788802
ret = true;
803+
789804
return ret;
790805
}
791806

@@ -865,7 +880,7 @@ int cap_bprm_set_creds(struct linux_binprm *bprm)
865880
if (WARN_ON(!cap_ambient_invariant_ok(new)))
866881
return -EPERM;
867882

868-
if (nonroot_raised_pE(new, root_uid)) {
883+
if (nonroot_raised_pE(new, old, root_uid, has_fcap)) {
869884
ret = audit_log_bprm_fcaps(bprm, new, old);
870885
if (ret < 0)
871886
return ret;

0 commit comments

Comments
 (0)