Skip to content

Commit f28e783

Browse files
committed
Smack: Use cap_capable in privilege check
Use cap_capable() rather than capable() in the Smack privilege check as the former does not invoke other security module privilege check, while the later does. This becomes important when stacking. It may be a problem even with minor modules. Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
1 parent 51d59af commit f28e783

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

‎security/smack/smack.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ int smk_netlbl_mls(int, char *, struct netlbl_lsm_secattr *, int);
320320
struct smack_known *smk_import_entry(const char *, int);
321321
void smk_insert_entry(struct smack_known *skp);
322322
struct smack_known *smk_find_entry(const char *);
323-
int smack_privileged(int cap);
323+
bool smack_privileged(int cap);
324324
void smk_destroy_label_list(struct list_head *list);
325325

326326
/*

‎security/smack/smack_access.c‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -627,35 +627,38 @@ DEFINE_MUTEX(smack_onlycap_lock);
627627
* Is the task privileged and allowed to be privileged
628628
* by the onlycap rule.
629629
*
630-
* Returns 1 if the task is allowed to be privileged, 0 if it's not.
630+
* Returns true if the task is allowed to be privileged, false if it's not.
631631
*/
632-
int smack_privileged(int cap)
632+
bool smack_privileged(int cap)
633633
{
634634
struct smack_known *skp = smk_of_current();
635635
struct smack_known_list_elem *sklep;
636+
int rc;
636637

637638
/*
638639
* All kernel tasks are privileged
639640
*/
640641
if (unlikely(current->flags & PF_KTHREAD))
641-
return 1;
642+
return true;
642643

643-
if (!capable(cap))
644-
return 0;
644+
rc = cap_capable(current_cred(), &init_user_ns, cap,
645+
SECURITY_CAP_AUDIT);
646+
if (rc)
647+
return false;
645648

646649
rcu_read_lock();
647650
if (list_empty(&smack_onlycap_list)) {
648651
rcu_read_unlock();
649-
return 1;
652+
return true;
650653
}
651654

652655
list_for_each_entry_rcu(sklep, &smack_onlycap_list, list) {
653656
if (sklep->smk_label == skp) {
654657
rcu_read_unlock();
655-
return 1;
658+
return true;
656659
}
657660
}
658661
rcu_read_unlock();
659662

660-
return 0;
663+
return false;
661664
}

0 commit comments

Comments
 (0)