Skip to content

Commit 02ebbaf

Browse files
rgbriggsJames Morris
authored andcommitted
capabilities: remove a layer of conditional logic
Remove a layer of conditional logic to make the use of conditions easier to read and analyse. 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 9fbc2c7 commit 02ebbaf

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

‎security/commoncap.c‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -781,13 +781,12 @@ static inline bool nonroot_raised_pE(struct cred *cred, kuid_t root)
781781
{
782782
bool ret = false;
783783

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-
}
784+
if (__cap_grew(effective, ambient, cred) &&
785+
(!__cap_full(effective, cred) ||
786+
!__is_eff(root, cred) ||
787+
!__is_real(root, cred) ||
788+
!root_privileged()))
789+
ret = true;
791790
return ret;
792791
}
793792

@@ -880,13 +879,11 @@ int cap_bprm_set_creds(struct linux_binprm *bprm)
880879

881880
/* Check for privilege-elevated exec. */
882881
bprm->cap_elevated = 0;
883-
if (is_setid) {
882+
if (is_setid ||
883+
(!__is_real(root_uid, new) &&
884+
(effective ||
885+
__cap_grew(permitted, ambient, new))))
884886
bprm->cap_elevated = 1;
885-
} else if (!__is_real(root_uid, new)) {
886-
if (effective ||
887-
__cap_grew(permitted, ambient, new))
888-
bprm->cap_elevated = 1;
889-
}
890887

891888
return 0;
892889
}

0 commit comments

Comments
 (0)