Skip to content

Commit 1880eff

Browse files
committed
Smack: onlycap limits on CAP_MAC_ADMIN
Smack is integrated with the POSIX capabilities scheme, using the capabilities CAP_MAC_OVERRIDE and CAP_MAC_ADMIN to determine if a process is allowed to ignore Smack checks or change Smack related data respectively. Smack provides an additional restriction that if an onlycap value is set by writing to /smack/onlycap only tasks with that Smack label are allowed to use CAP_MAC_OVERRIDE. This change adds CAP_MAC_ADMIN as a capability that is affected by the onlycap mechanism. Targeted for git://git.gitorious.org/smack-next/kernel.git Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
1 parent eb982cb commit 1880eff

4 files changed

Lines changed: 34 additions & 26 deletions

File tree

‎security/smack/smack.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,19 @@ static inline char *smk_of_current(void)
282282
return smk_of_task(current_security());
283283
}
284284

285+
/*
286+
* Is the task privileged and allowed to be privileged
287+
* by the onlycap rule.
288+
*/
289+
static inline int smack_privileged(int cap)
290+
{
291+
if (!capable(cap))
292+
return 0;
293+
if (smack_onlycap == NULL || smack_onlycap == smk_of_current())
294+
return 1;
295+
return 0;
296+
}
297+
285298
/*
286299
* logging functions
287300
*/

‎security/smack/smack_access.c‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,9 @@ int smk_curacc(char *obj_label, u32 mode, struct smk_audit_info *a)
220220
}
221221

222222
/*
223-
* Return if a specific label has been designated as the
224-
* only one that gets privilege and current does not
225-
* have that label.
223+
* Allow for priviliged to override policy.
226224
*/
227-
if (smack_onlycap != NULL && smack_onlycap != sp)
228-
goto out_audit;
229-
230-
if (capable(CAP_MAC_OVERRIDE))
225+
if (rc != 0 && smack_privileged(CAP_MAC_OVERRIDE))
231226
rc = 0;
232227

233228
out_audit:

‎security/smack/smack_lsm.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ static int smack_syslog(int typefrom_file)
217217
int rc = 0;
218218
char *sp = smk_of_current();
219219

220-
if (capable(CAP_MAC_OVERRIDE))
220+
if (smack_privileged(CAP_MAC_OVERRIDE))
221221
return 0;
222222

223223
if (sp != smack_known_floor.smk_known)
@@ -821,7 +821,7 @@ static int smack_inode_setxattr(struct dentry *dentry, const char *name,
821821
strcmp(name, XATTR_NAME_SMACKIPOUT) == 0 ||
822822
strcmp(name, XATTR_NAME_SMACKEXEC) == 0 ||
823823
strcmp(name, XATTR_NAME_SMACKMMAP) == 0) {
824-
if (!capable(CAP_MAC_ADMIN))
824+
if (!smack_privileged(CAP_MAC_ADMIN))
825825
rc = -EPERM;
826826
/*
827827
* check label validity here so import wont fail on
@@ -831,7 +831,7 @@ static int smack_inode_setxattr(struct dentry *dentry, const char *name,
831831
smk_import(value, size) == NULL)
832832
rc = -EINVAL;
833833
} else if (strcmp(name, XATTR_NAME_SMACKTRANSMUTE) == 0) {
834-
if (!capable(CAP_MAC_ADMIN))
834+
if (!smack_privileged(CAP_MAC_ADMIN))
835835
rc = -EPERM;
836836
if (size != TRANS_TRUE_SIZE ||
837837
strncmp(value, TRANS_TRUE, TRANS_TRUE_SIZE) != 0)
@@ -927,7 +927,7 @@ static int smack_inode_removexattr(struct dentry *dentry, const char *name)
927927
strcmp(name, XATTR_NAME_SMACKEXEC) == 0 ||
928928
strcmp(name, XATTR_NAME_SMACKTRANSMUTE) == 0 ||
929929
strcmp(name, XATTR_NAME_SMACKMMAP)) {
930-
if (!capable(CAP_MAC_ADMIN))
930+
if (!smack_privileged(CAP_MAC_ADMIN))
931931
rc = -EPERM;
932932
} else
933933
rc = cap_inode_removexattr(dentry, name);
@@ -1716,7 +1716,8 @@ static int smack_task_wait(struct task_struct *p)
17161716
* state into account in the decision as well as
17171717
* the smack value.
17181718
*/
1719-
if (capable(CAP_MAC_OVERRIDE) || has_capability(p, CAP_MAC_OVERRIDE))
1719+
if (smack_privileged(CAP_MAC_OVERRIDE) ||
1720+
has_capability(p, CAP_MAC_OVERRIDE))
17201721
rc = 0;
17211722
/* we log only if we didn't get overriden */
17221723
out_log:
@@ -2717,7 +2718,7 @@ static int smack_setprocattr(struct task_struct *p, char *name,
27172718
if (p != current)
27182719
return -EPERM;
27192720

2720-
if (!capable(CAP_MAC_ADMIN))
2721+
if (!smack_privileged(CAP_MAC_ADMIN))
27212722
return -EPERM;
27222723

27232724
if (value == NULL || size == 0 || size >= SMK_LONGLABEL)
@@ -2780,7 +2781,7 @@ static int smack_unix_stream_connect(struct sock *sock,
27802781
smk_ad_setfield_u_net_sk(&ad, other);
27812782
#endif
27822783

2783-
if (!capable(CAP_MAC_OVERRIDE))
2784+
if (!smack_privileged(CAP_MAC_OVERRIDE))
27842785
rc = smk_access(ssp->smk_out, osp->smk_in, MAY_WRITE, &ad);
27852786

27862787
/*
@@ -2816,7 +2817,7 @@ static int smack_unix_may_send(struct socket *sock, struct socket *other)
28162817
smk_ad_setfield_u_net_sk(&ad, other->sk);
28172818
#endif
28182819

2819-
if (!capable(CAP_MAC_OVERRIDE))
2820+
if (!smack_privileged(CAP_MAC_OVERRIDE))
28202821
rc = smk_access(ssp->smk_out, osp->smk_in, MAY_WRITE, &ad);
28212822

28222823
return rc;

‎security/smack/smackfs.c‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -595,13 +595,12 @@ static int smk_open_load(struct inode *inode, struct file *file)
595595
static ssize_t smk_write_load(struct file *file, const char __user *buf,
596596
size_t count, loff_t *ppos)
597597
{
598-
599598
/*
600599
* Must have privilege.
601600
* No partial writes.
602601
* Enough data must be present.
603602
*/
604-
if (!capable(CAP_MAC_ADMIN))
603+
if (!smack_privileged(CAP_MAC_ADMIN))
605604
return -EPERM;
606605

607606
return smk_write_rules_list(file, buf, count, ppos, NULL, NULL,
@@ -787,7 +786,7 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
787786
* No partial writes.
788787
* Enough data must be present.
789788
*/
790-
if (!capable(CAP_MAC_ADMIN))
789+
if (!smack_privileged(CAP_MAC_ADMIN))
791790
return -EPERM;
792791
if (*ppos != 0)
793792
return -EINVAL;
@@ -1090,7 +1089,7 @@ static ssize_t smk_write_netlbladdr(struct file *file, const char __user *buf,
10901089
* "<addr/mask, as a.b.c.d/e><space><label>"
10911090
* "<addr, as a.b.c.d><space><label>"
10921091
*/
1093-
if (!capable(CAP_MAC_ADMIN))
1092+
if (!smack_privileged(CAP_MAC_ADMIN))
10941093
return -EPERM;
10951094
if (*ppos != 0)
10961095
return -EINVAL;
@@ -1267,7 +1266,7 @@ static ssize_t smk_write_doi(struct file *file, const char __user *buf,
12671266
char temp[80];
12681267
int i;
12691268

1270-
if (!capable(CAP_MAC_ADMIN))
1269+
if (!smack_privileged(CAP_MAC_ADMIN))
12711270
return -EPERM;
12721271

12731272
if (count >= sizeof(temp) || count == 0)
@@ -1334,7 +1333,7 @@ static ssize_t smk_write_direct(struct file *file, const char __user *buf,
13341333
char temp[80];
13351334
int i;
13361335

1337-
if (!capable(CAP_MAC_ADMIN))
1336+
if (!smack_privileged(CAP_MAC_ADMIN))
13381337
return -EPERM;
13391338

13401339
if (count >= sizeof(temp) || count == 0)
@@ -1412,7 +1411,7 @@ static ssize_t smk_write_mapped(struct file *file, const char __user *buf,
14121411
char temp[80];
14131412
int i;
14141413

1415-
if (!capable(CAP_MAC_ADMIN))
1414+
if (!smack_privileged(CAP_MAC_ADMIN))
14161415
return -EPERM;
14171416

14181417
if (count >= sizeof(temp) || count == 0)
@@ -1503,7 +1502,7 @@ static ssize_t smk_write_ambient(struct file *file, const char __user *buf,
15031502
char *data;
15041503
int rc = count;
15051504

1506-
if (!capable(CAP_MAC_ADMIN))
1505+
if (!smack_privileged(CAP_MAC_ADMIN))
15071506
return -EPERM;
15081507

15091508
data = kzalloc(count + 1, GFP_KERNEL);
@@ -1586,7 +1585,7 @@ static ssize_t smk_write_onlycap(struct file *file, const char __user *buf,
15861585
char *sp = smk_of_task(current->cred->security);
15871586
int rc = count;
15881587

1589-
if (!capable(CAP_MAC_ADMIN))
1588+
if (!smack_privileged(CAP_MAC_ADMIN))
15901589
return -EPERM;
15911590

15921591
/*
@@ -1664,7 +1663,7 @@ static ssize_t smk_write_logging(struct file *file, const char __user *buf,
16641663
char temp[32];
16651664
int i;
16661665

1667-
if (!capable(CAP_MAC_ADMIN))
1666+
if (!smack_privileged(CAP_MAC_ADMIN))
16681667
return -EPERM;
16691668

16701669
if (count >= sizeof(temp) || count == 0)
@@ -1885,7 +1884,7 @@ static ssize_t smk_write_load2(struct file *file, const char __user *buf,
18851884
/*
18861885
* Must have privilege.
18871886
*/
1888-
if (!capable(CAP_MAC_ADMIN))
1887+
if (!smack_privileged(CAP_MAC_ADMIN))
18891888
return -EPERM;
18901889

18911890
return smk_write_rules_list(file, buf, count, ppos, NULL, NULL,

0 commit comments

Comments
 (0)