Polyinstantiation based on context with MLS
We're trying to understand the policy rules in relation to how instance directories of polyinstantiated directories get created when polyinstantiation is done by context.
My goal is to have a different instance directory created/mounted for each different context in which an application is running when it accesses this directory. For example, if running in a context with MLS level s1-s1, I would expect to see a different instance than when running in that same context but whose MLS level is s2-s2.
The problem is that I cannot get a different instance set up in these 2 cases; whether running at s1 or s2, the instance directory has a context with an MLS level of SystemLow-SystemHigh. This is the MLS range I had set up for the polyinstantiated dir (/var/poly) and the directory which contains the instances (/var/poly/poly-inst).
I added an entry to /etc/security/namespace.conf which contained "context"
/var/poly /var/poly/poly-inst context root,adm
My understanding was that the actual instance directory creation and mounting for a process was done through the pam_namespace module. Also, if my application called these pam session routines to set up instance directories, it would have to first call setexeccon prior to setting up a pam session. (Otherwise, pam would override the "context" setting in namespace.conf and create/mount an instance based on user instead of context.)
To have instance directories actually created by context, I had my test program obtain its current context, set the mls level in this context to either "s1-s1" or "s2-s2", and then pass this context to both setcon and setexeccon. It then calls the pam routines pam_start() and pam_open_session(). (I had set up a dummy "test" service in /etc/pam.d, and I passed this service name to pam_start along with a "conversation" routine which simply returned PAM_SUCCESS.)
When I ran my test program, I looked at /var/log/secure, and pam_namespace indicated it had successfully set up and mounted the instance directory.
It appears that pam_namespace calls security_compute_member to obtain the context which it sets the newly created instance directory to after creating it. Does the policy decide this based on the "type_member" rules ? If this is the case, then this rule seems to state only what the type is, and the remaining part of the context seems to always be the context of my /var/poly directory. If this is true, then how can it ever achieve having a different instance based on any component of the context (such as the MLS level) being different ?
I'd appreciate any suggestions.
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 40 lines · Rosalie Hiebel
We're trying to understand the policy rules in relation to how instance directories of polyinstantiated directories get created when polyinstantiation is done by context.
My goal is to have a different instance directory created/mounted for each different context in which an application is running when it accesses this directory. For example, if running in a context with MLS level s1-s1, I would expect to see a different instance than when running in that same context but whose MLS level is s2-s2.
The problem is that I cannot get a different instance set up in these 2 cases; whether running at s1 or s2, the instance directory has a context with an MLS level of SystemLow-SystemHigh. This is the MLS range I had set up for the polyinstantiated dir (
/var/poly) and the directory which contains the instances (/var/poly/poly-inst).I added an entry to
/etc/security/namespace.confwhich contained "context"
/var/poly/var/poly/poly-instcontext root,admMy understanding was that the actual instance directory creation and mounting for a process was done through the
pam_namespacemodule. Also, if my application called these pam session routines to set up instance directories, it would have to first call setexeccon prior to setting up a pam session. (Otherwise, pam would override the "context" setting in namespace.conf and create/mount an instance based on user instead of context.)To have instance directories actually created by context, I had my test program obtain its current context, set the mls level in this context to either "s1-s1" or "s2-s2", and then pass this context to both setcon and setexeccon. It then calls the pam routines
pam_start()andpam_open_session(). (I had set up a dummy "test" service in/etc/pam.d, and I passed this service name topam_startalong with a "conversation" routine which simply returnedPAM_SUCCESS.)When I ran my test program, I looked at
/var/log/secure, andpam_namespaceindicated it had successfully set up and mounted the instance directory.
Quoted 9 lines
It appears that
pam_namespacecallssecurity_compute_memberto obtain the context which it sets the newly created instance directory to after creating it. Does the policy decide this based on the "type_member" rules ? If this is the case, then this rule seems to state only what the type is, and the remaining part of the context seems to always be the context of my/var/polydirectory. If this is true, then how can it ever achieve having a different instance based on any component of the context (such as the MLS level) being different ?
If there is a matching type_member rule (with a type that differs from the base dir), then it should return a context with the new type and the low level from the source context (which in this case would be the exec context previously set).
As a side bar, it looks like there is an error in the build of the -mls policy that is leaving the usual polyinstantiation-related rules disabled (controlled by the POLY= build option).
If possible, you should consider decomposing your application and running separate instances for the different levels to improve separation and reduce the trust required in the application itself.
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.
Quoted 4 lines · Stephen Smalley
As a side bar, it looks like there is an error in the build of the -mls policy that is leaving the usual polyinstantiation-related rules disabled (controlled by the POLY= build option).
I think this spec file change will fix the error
selinux-policy.spec 2006-09-14 08:46:59.000000000 -0500 renamed from selinux-policy.spec.orig 2006-09-14 08:46:07.000000000 -0500 +0 -0
@@ -73,8 +73,8 @@ SELinux Policy development package
%dir %{_usr}/share/selinux/mls
%define setupCmds() \
-make NAME=%1 TYPE=%2 DISTRO=%{distro} DIRECT_INITRC=%3 MONOLITHIC=%{monolithic} POLY=%3 bare \
-make NAME=%1 TYPE=%2 DISTRO=%{distro} DIRECT_INITRC=%3 MONOLITHIC=%{monolithic} POLY=%3 conf \
+make NAME=%1 TYPE=%2 DISTRO=%{distro} DIRECT_INITRC=%3 MONOLITHIC=%{monolithic} POLY=%4 bare \
+make NAME=%1 TYPE=%2 DISTRO=%{distro} DIRECT_INITRC=%3 MONOLITHIC=%{monolithic} POLY=%4 conf \
cp -f ${RPM_SOURCE_DIR}/modules-%1.conf ./policy/modules.conf \
cp -f ${RPM_SOURCE_DIR}/booleans-%1.conf ./policy/booleans.conf \
@@ -82,18 +82,18 @@ cp -f ${RPM_SOURCE_DIR}/booleans-%1.conf
awk '$1 !~ "/^#/" && $2 == "=" && $3 == "module" { printf "-i %%s.pp ", $1 }' %{_sourcedir}/modules-%{1}.conf )
%define installCmds() \
-make NAME=%1 TYPE=%2 DISTRO=%{distro} DIRECT_INITRC=%3 MONOLITHIC=%{monolithic} POLY=%3 base.pp \
-make NAME=%1 TYPE=%2 DISTRO=%{distro} DIRECT_INITRC=%3 MONOLITHIC=%{monolithic} POLY=%3 modules \
-make NAME=%1 TYPE=%2 DISTRO=%{distro} DIRECT_INITRC=%3 MONOLITHIC=%{monolithic} DESTDIR=%{buildroot} POLY=%3 install \
-make NAME=%1 TYPE=%2 DISTRO=%{distro} DIRECT_INITRC=%3 MONOLITHIC=%{monolithic} DESTDIR=%{buildroot} POLY=%3 install-appconfig \
+make NAME=%1 TYPE=%2 DISTRO=%{distro} DIRECT_INITRC=%3 MONOLITHIC=%{monolithic} POLY=%4 base.pp \
+make NAME=%1 TYPE=%2 DISTRO=%{distro} DIRECT_INITRC=%3 MONOLITHIC=%{monolithic} POLY=%4 modules \
+make NAME=%1 TYPE=%2 DISTRO=%{distro} DIRECT_INITRC=%3 MONOLITHIC=%{monolithic} DESTDIR=%{buildroot} POLY=%4 install \
+make NAME=%1 TYPE=%2 DISTRO=%{distro} DIRECT_INITRC=%3 MONOLITHIC=%{monolithic} DESTDIR=%{buildroot} POLY=%4 install-appconfig \
#%{__cp} *.pp %{buildroot}/%{_usr}/share/selinux/%1/ \
%{__mkdir} -p %{buildroot}/%{_sysconfdir}/selinux/%1/policy \
%{__mkdir} -p %{buildroot}/%{_sysconfdir}/selinux/%1/modules/active \
%{__mkdir} -p %{buildroot}/%{_sysconfdir}/selinux/%1/contexts/files \
touch %{buildroot}/%{_sysconfdir}/selinux/%1/modules/semanage.read.LOCK \
touch %{buildroot}/%{_sysconfdir}/selinux/%1/modules/semanage.trans.LOCK \
-make NAME=%1 TYPE=%2 DISTRO=%{distro} DIRECT_INITRC=%3 MONOLITHIC=%{monolithic} POLY=%3 enableaudit \
-make -W base.conf NAME=%1 TYPE=%2 DISTRO=%{distro} DIRECT_INITRC=%3 MONOLITHIC=%{monolithic} POLY=%3 base.pp \
+make NAME=%1 TYPE=%2 DISTRO=%{distro} DIRECT_INITRC=%3 MONOLITHIC=%{monolithic} POLY=%4 enableaudit \
+make -W base.conf NAME=%1 TYPE=%2 DISTRO=%{distro} DIRECT_INITRC=%3 MONOLITHIC=%{monolithic} POLY=%4 base.pp \
install -m0644 base.pp %{buildroot}%{_usr}/share/selinux/%1/enableaudit.pp \
rm -rf %{buildroot}%{_sysconfdir}/selinux/%1/booleans \
touch %{buildroot}%{_sysconfdir}/selinux/%1/seusers \
@@ -179,7 +179,7 @@ mkdir -p %{buildroot}%{_usr}/share/selin
# Install devel
make clean
-make NAME=targeted TYPE=targeted-mcs DISTRO=%{distro} DIRECT_INITRC=y MONOLITHIC=%{monolithic} DESTDIR=%{buildroot} PKGNAME=%{name}-%{version} POLY=%3 install-headers install-docs +make NAME=targeted TYPE=targeted-mcs DISTRO=%{distro} DIRECT_INITRC=y MONOLITHIC=%{monolithic} DESTDIR=%{buildroot} PKGNAME=%{name}-%{version} POLY=n install-headers install-docs mkdir %{buildroot}%{_usr}/share/selinux/devel/
mv %{buildroot}%{_usr}/share/selinux/targeted/include %{buildroot}%{_usr}/share/selinux/devel/include
install -m 755 ${RPM_SOURCE_DIR}/policygentool %{buildroot}%{_usr}/share/selinux/devel/
--
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.