Skip to contentSkip to conversation

pam_namespace is broken from an SELinux perspective.

redhat-lspp Stephen Smalley 2 participants 7 messages Dec 7, 2006 4 messages not in the archive SELinux security module

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 10 lines · Daniel J Walsh

I am trying to fix the problems with polyinstatiation and SELinux Policy in MLS.

I have found that the way pam_namespace works is broken from an SELinux point of view.

If I setup the /tmp directory to polyinstatiate and I log in as a staff_t, I end up with /tmp mounted as staff_tmp_t instead of tmp_t. This is wrong, since confined apps that I run as a user expect tmp_t.

Quoted 7 lines

Similarly /home/dwalsh gets mounted as staff_home_t instead of staff_home_dir_t. This causes all of the transitions to fail.

The problem is the pam_namespace is asking the system if staff_t creates a directory in tmp_t how should it be created. The system responds staff_tmp_t. What pam_namespace should be doing is taking the directory tmp_t and replacing it's MLS level with the level of the user. That is all.

security_compute_member() and the type_member rules in the policy configuration are supposed to provide the policy decision for polyinstantiation rather than a hardcoded policy in pam_namespace. Depending on your goal, you might want per-role instantiation of a directory as well and take away the ability to directly write to e.g. tmp_t from all user domains, only letting them write to their own xxx_tmp_t type.

Part of the problem is that type_member rules currently only trigger level instantiation if the new type differs from the old, so you can't just say type_member staff_t tmp_t:dir tmp_t; That could be changed, but requires a (trivial) kernel patch.

You could work around it by labeling the top-level directories like /tmp and /home/dwalsh with other types (e.g. poly_tmp_t, poly_home_t) distinct for polyinstantiated directories, and then define type_member rules on those, e.g. type_member staff_t poly_tmp_t:dir tmp_t; type_member staff_t poly_home_t:dir staff_home_dir_t;

Quoted 11 lines

So staff_t loging in as s0:c1
will end up with /tmp being
system_u:object_r:tmp_t:s0:c1
And /home/dwalsh
system_u:object_r:staff_home_dir_t:s0:c1

I am trying out a patched version of pam_namespace to see if this fixes the problem.

Am I makeing the correct assumption.

If I read it correctly, the patch completely removes the use of security_compute_member, and hardcodes per-level instantiation. So that limits its usefulness to MLS.

Other comments:
- Need to check return codes from context_new, context_range_set, context_str, strdup and handle appropriately,
- I don't think you want the full range from scontext - just the low level (aka current/sensitivity level).

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#5 lore raw
Quoted 54 lines · Stephen Smalley
Quoted 10 lines · Daniel J Walsh

I am trying to fix the problems with polyinstatiation and SELinux Policy in MLS.

I have found that the way pam_namespace works is broken from an SELinux point of view.

If I setup the /tmp directory to polyinstatiate and I log in as a staff_t, I end up with /tmp mounted as staff_tmp_t instead of tmp_t. This is wrong, since confined apps that I run as a user expect tmp_t.

Quoted 7 lines

Similarly /home/dwalsh gets mounted as staff_home_t instead of staff_home_dir_t. This causes all of the transitions to fail.

The problem is the pam_namespace is asking the system if staff_t creates a directory in tmp_t how should it be created. The system responds staff_tmp_t. What pam_namespace should be doing is taking the directory tmp_t and replacing it's MLS level with the level of the user. That is all.

security_compute_member() and the type_member rules in the policy configuration are supposed to provide the policy decision for polyinstantiation rather than a hardcoded policy in pam_namespace. Depending on your goal, you might want per-role instantiation of a directory as well and take away the ability to directly write to e.g. tmp_t from all user domains, only letting them write to their own xxx_tmp_t type.

Part of the problem is that type_member rules currently only trigger level instantiation if the new type differs from the old, so you can't just say type_member staff_t tmp_t:dir tmp_t; That could be changed, but requires a (trivial) kernel patch.

You could work around it by labeling the top-level directories like /tmp and /home/dwalsh with other types (e.g. poly_tmp_t, poly_home_t) distinct for polyinstantiated directories, and then define type_member rules on those, e.g. type_member staff_t poly_tmp_t:dir tmp_t; type_member staff_t poly_home_t:dir staff_home_dir_t;

Quoted 11 lines

So staff_t loging in as s0:c1
will end up with /tmp being
system_u:object_r:tmp_t:s0:c1
And /home/dwalsh
system_u:object_r:staff_home_dir_t:s0:c1

I am trying out a patched version of pam_namespace to see if this fixes the problem.

Am I makeing the correct assumption.

If I read it correctly, the patch completely removes the use of security_compute_member, and hardcodes per-level instantiation. So that limits its usefulness to MLS.

Quoted 5 lines

Other comments:
- Need to check return codes from context_new, context_range_set, context_str, strdup and handle appropriately,
- I don't think you want the full range from scontext - just the low level (aka current/sensitivity level).

Oh, and you either need to check whether MLS is enabled or gracefully handle a NULL result from context_range_get in case MLS is disabled.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#6 lore raw
In reply to Stephen Smalley
Quoted 5 lines · Stephen Smalley

You could work around it by labeling the top-level directories like /tmp and /home/dwalsh with other types (e.g. poly_tmp_t, poly_home_t) distinct for polyinstantiated directories, and then define type_member rules on those, e.g. type_member staff_t poly_tmp_t:dir tmp_t; type_member staff_t poly_home_t:dir staff_home_dir_t;

The problem with this is that it makes installation of poly-instantiated directories more difficult.

I would like to see the installation process be as easy as possible to encourage people who aren't the most capable sys-admins to do it.

Signature · 9 lines
[email protected]
http://etbe.blogspot.com/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#7 lore raw
Quoted 7 lines · Russell Coker
Quoted 5 lines · Stephen Smalley

You could work around it by labeling the top-level directories like /tmp and /home/dwalsh with other types (e.g. poly_tmp_t, poly_home_t) distinct for polyinstantiated directories, and then define type_member rules on those, e.g. type_member staff_t poly_tmp_t:dir tmp_t; type_member staff_t poly_home_t:dir staff_home_dir_t;

Quoted 5 lines

The problem with this is that it makes installation of poly-instantiated directories more difficult.

I would like to see the installation process be as easy as possible to encourage people who aren't the most capable sys-admins to do it.

The alternative, as I said, is a simple kernel patch to trigger level instantiations even if the new type is the same as the old in the type_member rule. Then you can have type_member staff_t tmp_t:dir tmp_t; if you don't want per-role instantiation of /tmp or type_member staff_t tmp_t:dir staff_tmp_t; plus additional policy to enable applications expecting /tmp to be tmp_t to continue working if you want per-role instantiation. And you would be able to have type_member staff_t staff_home_dir_t:dir staff_home_dir_t;.

Such a patch has been floated previously but it never reached a conclusion. Re-basing, it looks something like this (un-tested, may not even compile):

security/selinux/ss/mls.c +3 -2
index b4f682d..d3d8ebd 100644
@@ -529,6 +529,7 @@ int mls_compute_sid(struct context *scon
 		    struct context *tcontext,
 		    u16 tclass,
 		    u32 specified,
+		    unsigned int type_rule,
 		    struct context *newcontext)
 {
 	struct range_trans *rtr;
@@ -558,8 +559,8 @@ int mls_compute_sid(struct context *scon
 			return mls_scopy_context(newcontext, scontext);
 	case AVTAB_MEMBER:
 		/* Only polyinstantiate the MLS attributes if
-		   the type is being polyinstantiated */
-		if (newcontext->type != tcontext->type) {
+		   a type_member rule was specified for the type. */
+		if (type_rule) {
 			/* Use the process effective MLS attributes. */
 			return mls_scopy_context(newcontext, scontext);
 		} else {
security/selinux/ss/mls.h +1 -0
index 661d6fc..6f4dec3 100644
@@ -64,6 +64,7 @@ int mls_compute_sid(struct context *scon
 		    struct context *tcontext,
 		    u16 tclass,
 		    u32 specified,
+		    unsigned int type_rule,
 		    struct context *newcontext);
 
 int mls_setup_user_range(struct context *fromcon, struct user_datum *user,
security/selinux/ss/services.c +1 -1
index bdb7070..1757275 100644
@@ -945,7 +945,7 @@ static int security_compute_sid(u32 ssid
 
 	/* Set the MLS attributes.
 	   This is done last because it may allocate memory. */
-	rc = mls_compute_sid(scontext, tcontext, tclass, specified, &newcontext);
+	rc = mls_compute_sid(scontext, tcontext, tclass, specified, (avdatum!=NULL), &newcontext);
 	if (rc)
 		goto out_unlock;
 
Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#8 lore raw
Quoted 14 lines · Stephen Smalley
Quoted 7 lines · Russell Coker
Quoted 5 lines · Stephen Smalley

You could work around it by labeling the top-level directories like /tmp and /home/dwalsh with other types (e.g. poly_tmp_t, poly_home_t) distinct for polyinstantiated directories, and then define type_member rules on those, e.g. type_member staff_t poly_tmp_t:dir tmp_t; type_member staff_t poly_home_t:dir staff_home_dir_t;

Quoted 5 lines

The problem with this is that it makes installation of poly-instantiated directories more difficult.

I would like to see the installation process be as easy as possible to encourage people who aren't the most capable sys-admins to do it.

Quoted 8 lines

The alternative, as I said, is a simple kernel patch to trigger level instantiations even if the new type is the same as the old in the type_member rule. Then you can have type_member staff_t tmp_t:dir tmp_t; if you don't want per-role instantiation of /tmp or type_member staff_t tmp_t:dir staff_tmp_t; plus additional policy to enable applications expecting /tmp to be tmp_t to continue working if you want per-role instantiation. And you would be able to have type_member staff_t staff_home_dir_t:dir staff_home_dir_t;.

Note however that the parallel thread on redhat-lspp has proposed using Dan's patch (with fixes) for now to get the desired behavior for MLS, renaming the current "context" option in namespace.conf to "level" to be specific to level instantiation, and later introduce "role" or "context" for role-based and/or full context instantiation when/if such support exists in the kernel and/or policy.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#9 lore raw
Quoted 6 lines · Stephen Smalley

Note however that the parallel thread on redhat-lspp has proposed using Dan's patch (with fixes) for now to get the desired behavior for MLS, renaming the current "context" option in namespace.conf to "level" to be specific to level instantiation, and later introduce "role" or "context" for role-based and/or full context instantiation when/if such support exists in the kernel and/or policy.

Having the choice of instantiating by level, role, or by full context seems like a useful feature to me.

Signature · 9 lines
[email protected]
http://etbe.blogspot.com/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#10 lore raw
Quoted 10 lines · Russell Coker
Quoted 6 lines · Stephen Smalley

Note however that the parallel thread on redhat-lspp has proposed using Dan's patch (with fixes) for now to get the desired behavior for MLS, renaming the current "context" option in namespace.conf to "level" to be specific to level instantiation, and later introduce "role" or "context" for role-based and/or full context instantiation when/if such support exists in the kernel and/or policy.

Having the choice of instantiating by level, role, or by full context seems like a useful feature to me.

Yes, although it somewhat breaks the intended encapsulation of the context and security_compute_member interface. At that point the level returned by security_compute_member becomes rather irrelevant - it would always be overridden by the logic in pam_namespace itself based on whether "level" was specified.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.