aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux/ss/services.c
diff options
context:
space:
mode:
authorEric Paris <eparis@redhat.com>2011-02-01 11:05:40 -0500
committerEric Paris <eparis@redhat.com>2011-02-01 11:12:30 -0500
commit652bb9b0d6ce007f37c098947b2cc0c45efa3f66 (patch)
tree7bf76f04a1fcaa401761a9a734b94682e2ac8b8c /security/selinux/ss/services.c
parent2a7dba391e5628ad665ce84ef9a6648da541ebab (diff)
SELinux: Use dentry name in new object labeling
Currently SELinux has rules which label new objects according to 3 criteria. The label of the process creating the object, the label of the parent directory, and the type of object (reg, dir, char, block, etc.) This patch adds a 4th criteria, the dentry name, thus we can distinguish between creating a file in an etc_t directory called shadow and one called motd. There is no file globbing, regex parsing, or anything mystical. Either the policy exactly (strcmp) matches the dentry name of the object or it doesn't. This patch has no changes from today if policy does not implement the new rules. Signed-off-by: Eric Paris <eparis@redhat.com>
Diffstat (limited to 'security/selinux/ss/services.c')
-rw-r--r--security/selinux/ss/services.c45
1 files changed, 31 insertions, 14 deletions
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index a03cfaf0ee07..2e36e03c21f2 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -1343,10 +1343,27 @@ out:
1343 return -EACCES; 1343 return -EACCES;
1344} 1344}
1345 1345
1346static void filename_compute_type(struct policydb *p, struct context *newcontext,
1347 u32 scon, u32 tcon, u16 tclass,
1348 const struct qstr *qstr)
1349{
1350 struct filename_trans *ft;
1351 for (ft = p->filename_trans; ft; ft = ft->next) {
1352 if (ft->stype == scon &&
1353 ft->ttype == tcon &&
1354 ft->tclass == tclass &&
1355 !strcmp(ft->name, qstr->name)) {
1356 newcontext->type = ft->otype;
1357 return;
1358 }
1359 }
1360}
1361
1346static int security_compute_sid(u32 ssid, 1362static int security_compute_sid(u32 ssid,
1347 u32 tsid, 1363 u32 tsid,
1348 u16 orig_tclass, 1364 u16 orig_tclass,
1349 u32 specified, 1365 u32 specified,
1366 const struct qstr *qstr,
1350 u32 *out_sid, 1367 u32 *out_sid,
1351 bool kern) 1368 bool kern)
1352{ 1369{
@@ -1442,6 +1459,11 @@ static int security_compute_sid(u32 ssid,
1442 newcontext.type = avdatum->data; 1459 newcontext.type = avdatum->data;
1443 } 1460 }
1444 1461
1462 /* if we have a qstr this is a file trans check so check those rules */
1463 if (qstr)
1464 filename_compute_type(&policydb, &newcontext, scontext->type,
1465 tcontext->type, tclass, qstr);
1466
1445 /* Check for class-specific changes. */ 1467 /* Check for class-specific changes. */
1446 if (tclass == policydb.process_class) { 1468 if (tclass == policydb.process_class) {
1447 if (specified & AVTAB_TRANSITION) { 1469 if (specified & AVTAB_TRANSITION) {
@@ -1495,22 +1517,17 @@ out:
1495 * if insufficient memory is available, or %0 if the new SID was 1517 * if insufficient memory is available, or %0 if the new SID was
1496 * computed successfully. 1518 * computed successfully.
1497 */ 1519 */
1498int security_transition_sid(u32 ssid, 1520int security_transition_sid(u32 ssid, u32 tsid, u16 tclass,
1499 u32 tsid, 1521 const struct qstr *qstr, u32 *out_sid)
1500 u16 tclass,
1501 u32 *out_sid)
1502{ 1522{
1503 return security_compute_sid(ssid, tsid, tclass, AVTAB_TRANSITION, 1523 return security_compute_sid(ssid, tsid, tclass, AVTAB_TRANSITION,
1504 out_sid, true); 1524 qstr, out_sid, true);
1505} 1525}
1506 1526
1507int security_transition_sid_user(u32 ssid, 1527int security_transition_sid_user(u32 ssid, u32 tsid, u16 tclass, u32 *out_sid)
1508 u32 tsid,
1509 u16 tclass,
1510 u32 *out_sid)
1511{ 1528{
1512 return security_compute_sid(ssid, tsid, tclass, AVTAB_TRANSITION, 1529 return security_compute_sid(ssid, tsid, tclass, AVTAB_TRANSITION,
1513 out_sid, false); 1530 NULL, out_sid, false);
1514} 1531}
1515 1532
1516/** 1533/**
@@ -1531,8 +1548,8 @@ int security_member_sid(u32 ssid,
1531 u16 tclass, 1548 u16 tclass,
1532 u32 *out_sid) 1549 u32 *out_sid)
1533{ 1550{
1534 return security_compute_sid(ssid, tsid, tclass, AVTAB_MEMBER, out_sid, 1551 return security_compute_sid(ssid, tsid, tclass, AVTAB_MEMBER, NULL,
1535 false); 1552 out_sid, false);
1536} 1553}
1537 1554
1538/** 1555/**
@@ -1553,8 +1570,8 @@ int security_change_sid(u32 ssid,
1553 u16 tclass, 1570 u16 tclass,
1554 u32 *out_sid) 1571 u32 *out_sid)
1555{ 1572{
1556 return security_compute_sid(ssid, tsid, tclass, AVTAB_CHANGE, out_sid, 1573 return security_compute_sid(ssid, tsid, tclass, AVTAB_CHANGE, NULL,
1557 false); 1574 out_sid, false);
1558} 1575}
1559 1576
1560/* Clone the SID into the new SID table. */ 1577/* Clone the SID into the new SID table. */