aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Guy Briggs <rgb@redhat.com>2017-10-11 20:57:06 -0400
committerJames Morris <james.l.morris@oracle.com>2017-10-20 00:22:43 -0400
commit4c7e715fc87b6f8b652363b3515b48b3822c5b5f (patch)
treedd6a8ec6b79721e30d0f867ccd207b9836a6de9b
parentdb1a8922cf3f0b936595ba41774fe4b66adf091a (diff)
capabilities: intuitive names for cap gain status
Introduce macros cap_gained, cap_grew, cap_full to make the use of the negation of is_subset() 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>
-rw-r--r--security/commoncap.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/security/commoncap.c b/security/commoncap.c
index be9bca50c312..4c9af6ef24b6 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -741,6 +741,12 @@ static void handle_privileged_root(struct linux_binprm *bprm, bool has_cap,
741 *effective = true; 741 *effective = true;
742} 742}
743 743
744#define __cap_gained(field, target, source) \
745 !cap_issubset(target->cap_##field, source->cap_##field)
746#define __cap_grew(target, source, cred) \
747 !cap_issubset(cred->cap_##target, cred->cap_##source)
748#define __cap_full(field, cred) \
749 cap_issubset(CAP_FULL_SET, cred->cap_##field)
744/** 750/**
745 * cap_bprm_set_creds - Set up the proposed credentials for execve(). 751 * cap_bprm_set_creds - Set up the proposed credentials for execve().
746 * @bprm: The execution parameters, including the proposed creds 752 * @bprm: The execution parameters, including the proposed creds
@@ -769,10 +775,9 @@ int cap_bprm_set_creds(struct linux_binprm *bprm)
769 handle_privileged_root(bprm, has_cap, &effective, root_uid); 775 handle_privileged_root(bprm, has_cap, &effective, root_uid);
770 776
771 /* if we have fs caps, clear dangerous personality flags */ 777 /* if we have fs caps, clear dangerous personality flags */
772 if (!cap_issubset(new->cap_permitted, old->cap_permitted)) 778 if (__cap_gained(permitted, new, old))
773 bprm->per_clear |= PER_CLEAR_ON_SETID; 779 bprm->per_clear |= PER_CLEAR_ON_SETID;
774 780
775
776 /* Don't let someone trace a set[ug]id/setpcap binary with the revised 781 /* Don't let someone trace a set[ug]id/setpcap binary with the revised
777 * credentials unless they have the appropriate permit. 782 * credentials unless they have the appropriate permit.
778 * 783 *
@@ -780,8 +785,7 @@ int cap_bprm_set_creds(struct linux_binprm *bprm)
780 */ 785 */
781 is_setid = !uid_eq(new->euid, old->uid) || !gid_eq(new->egid, old->gid); 786 is_setid = !uid_eq(new->euid, old->uid) || !gid_eq(new->egid, old->gid);
782 787
783 if ((is_setid || 788 if ((is_setid || __cap_gained(permitted, new, old)) &&
784 !cap_issubset(new->cap_permitted, old->cap_permitted)) &&
785 ((bprm->unsafe & ~LSM_UNSAFE_PTRACE) || 789 ((bprm->unsafe & ~LSM_UNSAFE_PTRACE) ||
786 !ptracer_capable(current, new->user_ns))) { 790 !ptracer_capable(current, new->user_ns))) {
787 /* downgrade; they get no more than they had, and maybe less */ 791 /* downgrade; they get no more than they had, and maybe less */
@@ -831,8 +835,8 @@ int cap_bprm_set_creds(struct linux_binprm *bprm)
831 * Number 1 above might fail if you don't have a full bset, but I think 835 * Number 1 above might fail if you don't have a full bset, but I think
832 * that is interesting information to audit. 836 * that is interesting information to audit.
833 */ 837 */
834 if (!cap_issubset(new->cap_effective, new->cap_ambient)) { 838 if (__cap_grew(effective, ambient, new)) {
835 if (!cap_issubset(CAP_FULL_SET, new->cap_effective) || 839 if (!__cap_full(effective, new) ||
836 !uid_eq(new->euid, root_uid) || !uid_eq(new->uid, root_uid) || 840 !uid_eq(new->euid, root_uid) || !uid_eq(new->uid, root_uid) ||
837 issecure(SECURE_NOROOT)) { 841 issecure(SECURE_NOROOT)) {
838 ret = audit_log_bprm_fcaps(bprm, new, old); 842 ret = audit_log_bprm_fcaps(bprm, new, old);
@@ -852,7 +856,7 @@ int cap_bprm_set_creds(struct linux_binprm *bprm)
852 bprm->cap_elevated = 1; 856 bprm->cap_elevated = 1;
853 } else if (!uid_eq(new->uid, root_uid)) { 857 } else if (!uid_eq(new->uid, root_uid)) {
854 if (effective || 858 if (effective ||
855 !cap_issubset(new->cap_permitted, new->cap_ambient)) 859 __cap_grew(permitted, ambient, new))
856 bprm->cap_elevated = 1; 860 bprm->cap_elevated = 1;
857 } 861 }
858 862