Question on type_member rule
I'm trying to understand precisely how a type_member rule specifies the context to place on an instance of a polyinstantiated directory when it's done by context.
type_member <source_type> <target_type>:dir <member_type>;
What exactly will be the context placed on the instance of the directory created by a process? Will this context be the same as the context passed to setexeccon ? Is the <member_type> placed in the context of the instance directory ? Does running in permissive mode result in a different context ?
I have experimented with this, and I seem to always get instance directories created with the same context as that of the base directory (the one being polyinstantiated.)
Thanks,
Rosalie
--
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.
Quoted 12 lines · Rosalie Hiebel
I'm trying to understand precisely how a
type_memberrule specifies the context to place on an instance of a polyinstantiated directory when it's done by context.type_member <source_type> <target_type>:dir <member_type>;What exactly will be the context placed on the instance of the
directory created by a process? Will this context be the same as
the context passed to setexeccon ? Is the <member_type> placed in
the context of the instance directory ? Does running in permissive
mode result in a different context ?
Quoted 3 lines
I have experimented with this, and I seem to always get instance directories created with the same context as that of the base directory (the one being polyinstantiated.)
Let's distinguish between what security_compute_member() computes, and how pam_namespace calls and uses it.
Further, before we delve too deep here, I have to ask: Does your application truly require polyinstantiated directories? From what you've described thus far, it sounds as though the application is already security-aware and multi-level, so what does it gain from polyinstantiation vs. explicit directory/file management? Polyinstantiation is more oriented toward providing compatibility for security-unaware applications when accessing a shared resource like /tmp that must be partitioned in a multi-level environment without having to modify those applications to know about per-level instances. But if the application already knows that it is operating in a multi-level environment and even knows what level it needs to operate in, why does it need polyinstantiation vs. just accessing the right subdir directly? (I'd also be interested in exploring the architecture of your application and whether it can be decomposed to minimize trust, but that is another topic.)
Going back now to your questions, security_compute_member() is a function to compute a member/instance context for a given polyinstantiated object based on three inputs:
1) a source context, typically the context of the process that will be accessing the instance,
2) a target context, typically the context of the polyinstantiated object, and
3) the class of the object, so that we can distinguish different kinds of polyinstantiated objects that might ultimately exist beyond just directories.
The function itself has no knowledge of how these inputs are determined; they are provided by the caller (pam_namespace in this case). The function computes a member context from these inputs based on its internal rules, which are:
1) Look for a type_member rule that matches the type from the source context (source_type), the type from the target context (target_type), and the class.
2) If no such rule exists, then the function just returns a member context equal to the target context (no instantiation).
3) If a rule exists, then use the member_type from the rule as the type in the member context. Further, if that member_type differs from the target_type (*), use the level of the source context as the level in the member context.
(*) Implementation artifact: In concept, the type_member rule indicates when to polyinstantiate an object, and it was assumed that one would always want to polyinstantiate by type as well as level in such cases, so member_type != target_type is used as the test in the MLS component to determine whether it should polyinstantiate levels. That could be changed (in fact, there was some discussion of it in the past), but until such a change occurs, you need to use member_type != target_type in the rule to cause instantiation to occur.
pam_namespace uses security_compute_member() to get the member context. It passes the following as inputs:
1) the exec context as the source context,
2) the context of the directory to be polyinstantiated as the target context.
3) the directory class.
The use of the exec context is because we want to instantiate based on the context of the process that will be accessing the member, which is typically _not_ the current process. Instead, it is typically a user shell or other program executed by the current process (or a child) that will run in the exec context rather than the current one. This is the case for e.g. login and newrole. If your application doesn't follow such a model, we need to talk about your application's architecture.
Examples of type_member rules from the refpolicy:
type_member user_t tmp_t:dir user_tmp_t; type_member staff_t tmp_t:dir staff_tmp_t;
Then, if pam_namespace is configured to polyinstantiate /tmp by context and the user is not in the list of excluded uids, it would call security_compute_member with the exec context (set by the caller of pam_namespace, e.g. sds:staff_r:staff_t:s3) and the context of the /tmp directory (e.g. system_u:object_r:tmp_t:s0). security_compute_member() would find the matching type_member rule for (staff_t, tmp_t) and should return the context system_u:object_r:staff_tmp_t:s3 as the member/instance context.
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.
Thanks very much for the explanation of how the context of instance directories is computed. Once I added the proper type_member rule, it was working as you described. (When I first tried this, I had assumed that the context of the instance directory would be that of the process and did not understand the point of the type_member rule.)
Quoted 5 lines · Rosalie Hiebel
Quoted 3 lines
I'm trying to understand precisely how a
type_memberrule specifies the context to place on an instance of a polyinstantiated directory
when it's done by context.
...snip...
Quoted 5 lines
Let's distinguish between what
security_compute_member()computes, and howpam_namespacecalls and uses it.Further, before we delve too deep here, I have to ask: Does your application truly require polyinstantiated directories?
I want an application which runs at various MLS levels to see only the instance whose MLS level matches the process's MLS level; I thought polyinstantiation by context would easily provide this. We also would occasionally like certain processes to be able to see all instances of it at or below the MLS level of the process. Is this possible with polyinstantiation? (Would the user being in the list of excluded uids be required?)
Quoted 25 lines
From what
you've described thus far, it sounds as though the application is already security-aware and multi-level, so what does it gain from polyinstantiation vs. explicit directory/file management? Polyinstantiation is more oriented toward providing compatibility for security-unaware applications when accessing a shared resource like /tmp that must be partitioned in a multi-level environment without having to modify those applications to know about per-level instances. But if the application already knows that it is operating in a multi-level environment and even knows what level it needs to operate in, why does it need polyinstantiation vs. just accessing the right subdir directly? (I'd also be interested in exploring the architecture of your application and whether it can be decomposed to minimize trust, but that is another topic.)Going back now to your questions,
security_compute_member()is a function to compute a member/instance context for a given polyinstantiated object based on three inputs:
1) a source context, typically the context of the process that will be accessing the instance,
2) a target context, typically the context of the polyinstantiated object, and
3) the class of the object, so that we can distinguish different kinds of polyinstantiated objects that might ultimately exist beyond just directories.
...snip...
Quoted 21 lines
The use of the exec context is because we want to instantiate based on the context of the process that will be accessing the member, which is typically _not_ the current process. Instead, it is typically a user shell or other program executed by the current process (or a child) that will run in the exec context rather than the current one. This is the case for e.g. login and newrole. If your application doesn't follow such a model, we need to talk about your application's architecture.
Examples of
type_memberrules from the refpolicy:type_member user_t tmp_t:dir user_tmp_t; type_member staff_t tmp_t:dir staff_tmp_t;Then, if
pam_namespaceis configured to polyinstantiate /tmp by context and the user is not in the list of excluded uids, it would callsecurity_compute_memberwith the exec context (set by the caller ofpam_namespace, e.g. sds:staff_r:staff_t:s3) and the context of the /tmp directory (e.g. system_u:object_r:tmp_t:s0).security_compute_member()would find the matchingtype_memberrule for (staff_t,tmp_t) and should return the context system_u:object_r:staff_tmp_t:s3 as the member/instance context.
Quoted 3 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.
Quoted 3 lines · Rosalie Hiebel
Thanks very much for the explanation of how the context of instance directories is computed. Once I added the proper
type_memberrule, it was working as you described.
Ok, good.
Quoted 3 lines
I want an application which runs at various MLS levels to see only the instance whose MLS level matches the process's MLS level; I thought polyinstantiation by context would easily provide this.
If the application is security-aware and knows what level it is operating in, it could just directly manage and access the proper per-level instance directories. No need to have it transparently created and mounted in that situation.
Now, if the main application itself is security-aware, but you want it to launch sub-applications that are untrusted and security-unaware, then the main application could very well use pam_namespace to set up the namespace in the child process prior to exec'ing the sub-application in the desired level. That would provide transparency to the sub-applications as well as providing stronger isolation than doing everything in the main application.
Quoted 5 lines
We
also would occasionally like certain processes to be able to see all instances of it at or below the MLS level of the process. Is this possible with polyinstantiation? (Would the user being in the list of excluded uids be required?)
I think there are different options here, e.g.:
- put the user in the exclusion list to avoid creating a separate namespace altogether, or
- directly access the instance directories if they live outside of the polyinstantiated directory (as per namespace.conf), or
- unmount any bind mounts from the current namespace in order to see the instance directories if they live within the polyinstantiated directory.
Or just create the process outside of anything that uses pam_namespace.
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.