All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC]{Patch 0/5] Polyinstantation
@ 2005-05-11 15:28 Chad Sellers
  2005-05-11 17:41 ` Casey Schaufler
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Chad Sellers @ 2005-05-11 15:28 UTC (permalink / raw)
  To: selinux

This patch us a userspace patch to provide polyinstantiation support in
SELinux.  I am including a patch to libselinux to provide this, as well
as patches to login, su, gdm, and policy to make this work.  These
patches will follow in separate emails.  Comments are appreciated
(usually, at least).

OVERVIEW
This code provides polyinstantiation support for directories in SELinux
systems.  It creates multiple instances of a directory as dictated by
policy.  These instances are actually subdirectories, named using a MD5
hash of the context of the member directory, that are used in place of
the parent directory.  To interface with policy, the code utilizes
the /selinux/member interface to read how directories should be
polyinstantiated according to policy.

In order to specify how directories should be instantiated in type
enforcement policy, a type_member rule is used.  MLS polyinstantiation
policy is implicit (i.e. the directory should be polyinstantiated to the
level of the user).  This code queries the /selinux/member interface to
see what member of a polyinstantiated directory should be used for a
given subject context.

To replace the original directory with the appropriate member directory,
per-process namespaces and bind mounts are used.  More specifically, an
entrypoint program (say login) calls this library to see if any
polyinstantiation is necessary.  If so, it calls clone() instead of fork
with the CLONE_NEWNS flag to get a new namespace.  Then, the library can
bind mount member directories over the originals.  Additionally, the
library remounts the original directory elsewhere (e.g. /tmp is
remounted to /.tmp-poly-orig) for security-aware (and allowed) programs
to utilize it.

USING THE LIBRARY
The library exports 2 functions, security_setupns(), the main function,
and security_set_setupns_printf(), a support function to change where
printf's go. security_setupns() sets up a namespace for the user being
processed.  It takes one argument - commit, which is an integer that can
be 0 or 1.  If commit=0, the function does not actually set up the
namespace, but just checks to see if any modifications to the namespace
are necessary.  If commit=1, those modifications are actually made.  The
function returns the number of changes (i.e. directories needing
polyinstantiation).  security_set_setupns_printf is used to replace the
printf function (which defaults to logging to stderr) the same way that
set_matchpathcon_printf() does.

CONFIG FILE
There is one config file, which is stored in /etc/selinux/polydirs.  The
first line contains the default context to use for directories that
originals are remounted to (e.g. /.tmp-poly-orig), which only matters
before the bind mount happens.  The rest of the file is a newline-
delimited list of candidate directories to be polyinstantiated.  Each of
these directories will be checked to see if polyinstantiation is
necessary according to the policy.  Additionally, the library supports
the special directory $HOME to indicate the home directory of the user
who's environment we're setting up.

POLICY
Policy is fairly straightforward.  Just write a type_member rule.  The
syntax is:
type_member <source type> <target type>:<target class> <member type>
<source type> is the type of the user logging in, <target type> is the
type of the directory being polyinstantiated, <target class> is dir
(since this patch only works for directories), and <member type> is what
you want the member directory context to be.  So, the rule
type_member user_t tmp_t:dir user_tmp_t
says use member directory user_tmp_t for a directory labeled tmp_t for
user_t.  Of course, for this query to take place at all, you have to
have a directory in the config file that is labeled tmp_t.
Note that you also need appropriate policy (TE allow rules and mls
priveleges) to allow programs such as login, su, and gdm to perform the
appropriate functions.  I've included a patch to policy to provide this.

BUILDING AND INSTALLING
The code is in the form of patches to the current cvs libselinux
(1.23.10-1), and the current rpms found in rawhide.  I've enclosed both
patches to source and patches to the spec files.  So, the easiest way to
install them, is to
1) Patch and rebuild your libselinux.
Build and install the SRPM -or-
tar xzf libselinux-x.y.z.tgz
cd libselinux-x.y.z
patch -p1 < libselinux-x.y.z-poly.patch
make install relabel

2) Apply the provided patch to your policy, build, and load it.
cd /etc/selinux/(strict|targeted|mls)/src/policy
patch -p1 < policy.diff
make load
Note:  This includes domains/misc/test.te, which has example type member
rules.  You may want to customize these to rules appropriate to your
install.

3) Install polydirs configuration file and edit for desired
configuration (which should match up with the type member rules above).
cp polydirs /etc/selinux/polydirs

4) Verify basic operation via setupns test utility (part of libselinux
patch).
su -
ls -al /tmp /home/<username>
setupns <username> <usercontext>
	e.g. setupns jdoe user_u:user_r:user_t
ls -al /tmp /home/<username>
cat /proc/mounts
exit
setupns -X <username> <usercontext>
ls -al /tmp /home/<username>

5) Build and install the modified util-linux, coreutils, and gdm
Build and install the SRPMs -or-
Try applying patches to source from somewhere else.  I have only tested
these patches with rawhide srpms, but they should be fairly easy to
apply to other source assuming that source already has the appropriate
SELinux patches.

6) Try logging into different roles at the console, via gdm, and using
su to switch between different users/roles, looking at your /tmp and
$HOME before and after, as well as /proc/mounts.


-- 
Chad Sellers
cdselle@tycho.nsa.gov


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: [RFC]{Patch 0/5] Polyinstantation
@ 2005-05-11 18:37 Casey Schaufler
  0 siblings, 0 replies; 18+ messages in thread
From: Casey Schaufler @ 2005-05-11 18:37 UTC (permalink / raw)
  To: Chad Sellers; +Cc: selinux


--- Chad Sellers <cdselle@tycho.nsa.gov> wrote:

> The two instances of /tmp/foo have different
> contexts (that's the
> reason /tmp was polyinstantiated in the first
> place).  Any audit
> messages (avc messages do this now) should include
> the context of the
> file (as well as device and inode), not just the
> filename.  So, the two
> instances can be differentiated.  Additionally,
> auditing based on
> filename is unreliable to begin with.

So long as the mapping from context to pathname
(via the mountpoint) can be reconstructed at a
later date this ought to work fine.


> I agree that this is a bad practice, but these
> programs could move to my
> scheme.  MLS applications that use "label flipping"
> have to be security
> aware in order to perform that flipping (meaning
> they have to call
> security functions to flip their label).  So, they
> could include a call
> to my library function to modify their namespace
> appropriately when
> flipping labels.

Hum. Yes, they could do that. I don't see
such a requirement being very popular.

> Of course, this requires the
> entrypoint program
> starting the application to have setup a new
> namespace for the
> application in the first place.  If the application
> flips so frequently
> that this affects performance, then I'd say the
> application is flipping
> labels a little too frequently.

Consider a MLS version of sendmail as your worst
case scenario.



Casey Schaufler
casey@schaufler-ca.com


		
__________________________________ 
Do you Yahoo!? 
Take Yahoo! Mail with you! Get it on your mobile phone. 
http://mobile.yahoo.com/maildemo 

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: [RFC]{Patch 0/5] Polyinstantation
@ 2005-05-11 19:02 Casey Schaufler
  0 siblings, 0 replies; 18+ messages in thread
From: Casey Schaufler @ 2005-05-11 19:02 UTC (permalink / raw)
  To: Timothy R. Chavez, selinux


--- "Timothy R. Chavez" <tinytim@us.ibm.com> wrote:

> I'm not too familiar with MLS, but is it really
> necessary to audit every thing 
> the user is  accessing?

In the usual case accessing files in /tmp
will be completely uninteresting to any
sane security officer. In unusual cases,
or in the presence of an insane security
officer it must be possible to do so.
Polyinstantiated directories have driven
any number of otherwise rational admins
over the edge.

> What if /tmp/foo maps to
> something uninteresting in 
> both SECRET and UNCLASSIFIED, do we really care?

Nope. We don't care. The user who is being watched
may care a lot if difficulty in differentiation
lands her in jail. It can happen.

> If
> /tmp/foo maps to 
> something security-critical and interesting, I'd
> suspect it will be audited 
> (irrespective of namespace, at the inode level), in
> which case a record will 
> be generated with a security context, loginuid, etc.

This is only going to be true if it's known in
advance by the admins that /tmp/foo will contain
important stuff, and which /tmp/foo that's going
to be.


Unix MLS systems address polyinstantiated
directories in the pathname resolution code
rather than remapping process mount spaces.


Casey Schaufler
casey@schaufler-ca.com


		
__________________________________ 
Yahoo! Mail Mobile 
Take Yahoo! Mail with you! Check email on your mobile phone. 
http://mobile.yahoo.com/learn/mail 

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2005-05-19 20:20 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-11 15:28 [RFC]{Patch 0/5] Polyinstantation Chad Sellers
2005-05-11 17:41 ` Casey Schaufler
2005-05-11 18:11   ` Janak Desai
2005-05-11 18:16   ` Chad Sellers
2005-05-11 18:48   ` Timothy R. Chavez
2005-05-11 20:13 ` Daniel J Walsh
2005-05-11 20:40   ` Chad Sellers
2005-05-12  1:30     ` Daniel J Walsh
2005-05-12 11:22       ` Stephen Smalley
2005-05-12 13:22         ` Chad Sellers
2005-05-13  4:40           ` Russell Coker
2005-05-13  5:53             ` Valdis.Kletnieks
2005-05-13 11:15               ` Daniel J Walsh
2005-05-13 11:30             ` Stephen Smalley
2005-05-19 20:17               ` Chad Sellers
2005-05-12  9:35 ` [selinux] " Magosányi Árpád
  -- strict thread matches above, loose matches on Subject: below --
2005-05-11 18:37 Casey Schaufler
2005-05-11 19:02 Casey Schaufler

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.