aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCasey Schaufler <casey@schaufler-ca.com>2018-01-08 13:25:32 -0500
committerCasey Schaufler <casey@schaufler-ca.com>2018-01-10 12:29:14 -0500
commitd19dfe58b7ecbef3bd0c403c650200c57913ba1b (patch)
tree59ab1001fe590143cda52657a71b5d3087ae6b91
parentda49b5dad18aad357ab8841ee65d415f683efc6f (diff)
Smack: Privilege check on key operations
Smack: Privilege check on key operations Operations on key objects are subjected to Smack policy even if the process is privileged. This is inconsistent with the general behavior of Smack and may cause issues with authentication by privileged daemons. This patch allows processes with CAP_MAC_OVERRIDE to access keys even if the Smack rules indicate otherwise. Reported-by: Jose Bollo <jobol@nonadev.net> Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
-rw-r--r--security/smack/smack.h1
-rw-r--r--security/smack/smack_access.c40
-rw-r--r--security/smack/smack_lsm.c4
3 files changed, 34 insertions, 11 deletions
diff --git a/security/smack/smack.h b/security/smack/smack.h
index 6a71fc7831ab..f7db791fb566 100644
--- a/security/smack/smack.h
+++ b/security/smack/smack.h
@@ -321,6 +321,7 @@ struct smack_known *smk_import_entry(const char *, int);
321void smk_insert_entry(struct smack_known *skp); 321void smk_insert_entry(struct smack_known *skp);
322struct smack_known *smk_find_entry(const char *); 322struct smack_known *smk_find_entry(const char *);
323bool smack_privileged(int cap); 323bool smack_privileged(int cap);
324bool smack_privileged_cred(int cap, const struct cred *cred);
324void smk_destroy_label_list(struct list_head *list); 325void smk_destroy_label_list(struct list_head *list);
325 326
326/* 327/*
diff --git a/security/smack/smack_access.c b/security/smack/smack_access.c
index 1a3004189447..9a4c0ad46518 100644
--- a/security/smack/smack_access.c
+++ b/security/smack/smack_access.c
@@ -623,26 +623,24 @@ struct smack_known *smack_from_secid(const u32 secid)
623LIST_HEAD(smack_onlycap_list); 623LIST_HEAD(smack_onlycap_list);
624DEFINE_MUTEX(smack_onlycap_lock); 624DEFINE_MUTEX(smack_onlycap_lock);
625 625
626/* 626/**
627 * smack_privileged_cred - are all privilege requirements met by cred
628 * @cap: The requested capability
629 * @cred: the credential to use
630 *
627 * Is the task privileged and allowed to be privileged 631 * Is the task privileged and allowed to be privileged
628 * by the onlycap rule. 632 * by the onlycap rule.
629 * 633 *
630 * Returns true if the task is allowed to be privileged, false if it's not. 634 * Returns true if the task is allowed to be privileged, false if it's not.
631 */ 635 */
632bool smack_privileged(int cap) 636bool smack_privileged_cred(int cap, const struct cred *cred)
633{ 637{
634 struct smack_known *skp = smk_of_current(); 638 struct task_smack *tsp = cred->security;
639 struct smack_known *skp = tsp->smk_task;
635 struct smack_known_list_elem *sklep; 640 struct smack_known_list_elem *sklep;
636 int rc; 641 int rc;
637 642
638 /* 643 rc = cap_capable(cred, &init_user_ns, cap, SECURITY_CAP_AUDIT);
639 * All kernel tasks are privileged
640 */
641 if (unlikely(current->flags & PF_KTHREAD))
642 return true;
643
644 rc = cap_capable(current_cred(), &init_user_ns, cap,
645 SECURITY_CAP_AUDIT);
646 if (rc) 644 if (rc)
647 return false; 645 return false;
648 646
@@ -662,3 +660,23 @@ bool smack_privileged(int cap)
662 660
663 return false; 661 return false;
664} 662}
663
664/**
665 * smack_privileged - are all privilege requirements met
666 * @cap: The requested capability
667 *
668 * Is the task privileged and allowed to be privileged
669 * by the onlycap rule.
670 *
671 * Returns true if the task is allowed to be privileged, false if it's not.
672 */
673bool smack_privileged(int cap)
674{
675 /*
676 * All kernel tasks are privileged
677 */
678 if (unlikely(current->flags & PF_KTHREAD))
679 return true;
680
681 return smack_privileged_cred(cap, current_cred());
682}
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 30f2c3d1c11c..03fdecba93bb 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -4369,6 +4369,10 @@ static int smack_key_permission(key_ref_t key_ref,
4369 */ 4369 */
4370 if (tkp == NULL) 4370 if (tkp == NULL)
4371 return -EACCES; 4371 return -EACCES;
4372
4373 if (smack_privileged_cred(CAP_MAC_OVERRIDE, cred))
4374 return 0;
4375
4372#ifdef CONFIG_AUDIT 4376#ifdef CONFIG_AUDIT
4373 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_KEY); 4377 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_KEY);
4374 ad.a.u.key_struct.key = keyp->serial; 4378 ad.a.u.key_struct.key = keyp->serial;