aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux/ss/services.c
diff options
context:
space:
mode:
authorEric Paris <eparis@redhat.com>2012-03-20 14:35:12 -0400
committerEric Paris <eparis@redhat.com>2012-04-09 12:22:47 -0400
commitaa893269de6277b44be88e25dcd5331c934c29c4 (patch)
treef994e023f787c1665b65725f2c009a9f5a021be7 /security/selinux/ss/services.c
parent6ce74ec75ca690c4fb3a3c5f8b7767d094d93215 (diff)
SELinux: allow default source/target selectors for user/role/range
When new objects are created we have great and flexible rules to determine the type of the new object. We aren't quite as flexible or mature when it comes to determining the user, role, and range. This patch adds a new ability to specify the place a new objects user, role, and range should come from. For users and roles it can come from either the source or the target of the operation. aka for files the user can either come from the source (the running process and todays default) or it can come from the target (aka the parent directory of the new file) examples always are done with directory context: system_u:object_r:mnt_t:s0-s0:c0.c512 process context: unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 [no rule] unconfined_u:object_r:mnt_t:s0 test_none [default user source] unconfined_u:object_r:mnt_t:s0 test_user_source [default user target] system_u:object_r:mnt_t:s0 test_user_target [default role source] unconfined_u:unconfined_r:mnt_t:s0 test_role_source [default role target] unconfined_u:object_r:mnt_t:s0 test_role_target [default range source low] unconfined_u:object_r:mnt_t:s0 test_range_source_low [default range source high] unconfined_u:object_r:mnt_t:s0:c0.c1023 test_range_source_high [default range source low-high] unconfined_u:object_r:mnt_t:s0-s0:c0.c1023 test_range_source_low-high [default range target low] unconfined_u:object_r:mnt_t:s0 test_range_target_low [default range target high] unconfined_u:object_r:mnt_t:s0:c0.c512 test_range_target_high [default range target low-high] unconfined_u:object_r:mnt_t:s0-s0:c0.c512 test_range_target_low-high Signed-off-by: Eric Paris <eparis@redhat.com>
Diffstat (limited to 'security/selinux/ss/services.c')
-rw-r--r--security/selinux/ss/services.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index 185f849a26f6..2ea108c2c048 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -1389,6 +1389,7 @@ static int security_compute_sid(u32 ssid,
1389 u32 *out_sid, 1389 u32 *out_sid,
1390 bool kern) 1390 bool kern)
1391{ 1391{
1392 struct class_datum *cladatum = NULL;
1392 struct context *scontext = NULL, *tcontext = NULL, newcontext; 1393 struct context *scontext = NULL, *tcontext = NULL, newcontext;
1393 struct role_trans *roletr = NULL; 1394 struct role_trans *roletr = NULL;
1394 struct avtab_key avkey; 1395 struct avtab_key avkey;
@@ -1437,12 +1438,20 @@ static int security_compute_sid(u32 ssid,
1437 goto out_unlock; 1438 goto out_unlock;
1438 } 1439 }
1439 1440
1441 if (tclass && tclass <= policydb.p_classes.nprim)
1442 cladatum = policydb.class_val_to_struct[tclass - 1];
1443
1440 /* Set the user identity. */ 1444 /* Set the user identity. */
1441 switch (specified) { 1445 switch (specified) {
1442 case AVTAB_TRANSITION: 1446 case AVTAB_TRANSITION:
1443 case AVTAB_CHANGE: 1447 case AVTAB_CHANGE:
1444 /* Use the process user identity. */ 1448 if (cladatum && cladatum->default_user == DEFAULT_TARGET) {
1445 newcontext.user = scontext->user; 1449 newcontext.user = tcontext->user;
1450 } else {
1451 /* notice this gets both DEFAULT_SOURCE and unset */
1452 /* Use the process user identity. */
1453 newcontext.user = scontext->user;
1454 }
1446 break; 1455 break;
1447 case AVTAB_MEMBER: 1456 case AVTAB_MEMBER:
1448 /* Use the related object owner. */ 1457 /* Use the related object owner. */
@@ -1450,14 +1459,23 @@ static int security_compute_sid(u32 ssid,
1450 break; 1459 break;
1451 } 1460 }
1452 1461
1453 /* Set the role and type to default values. */ 1462 /* Set the role to default values. */
1454 if ((tclass == policydb.process_class) || (sock == true)) { 1463 if (cladatum && cladatum->default_role == DEFAULT_SOURCE) {
1455 /* Use the current role and type of process. */
1456 newcontext.role = scontext->role; 1464 newcontext.role = scontext->role;
1465 } else if (cladatum && cladatum->default_role == DEFAULT_TARGET) {
1466 newcontext.role = tcontext->role;
1467 } else {
1468 if ((tclass == policydb.process_class) || (sock == true))
1469 newcontext.role = scontext->role;
1470 else
1471 newcontext.role = OBJECT_R_VAL;
1472 }
1473
1474 /* Set the type to default values. */
1475 if ((tclass == policydb.process_class) || (sock == true)) {
1476 /* Use the type of process. */
1457 newcontext.type = scontext->type; 1477 newcontext.type = scontext->type;
1458 } else { 1478 } else {
1459 /* Use the well-defined object role. */
1460 newcontext.role = OBJECT_R_VAL;
1461 /* Use the type of the related object. */ 1479 /* Use the type of the related object. */
1462 newcontext.type = tcontext->type; 1480 newcontext.type = tcontext->type;
1463 } 1481 }