don't relabel sub-subdirectories of /mnt, /media by default
PATCH 1/1 don't relabel sub-subdirectories of /mnt, /media by default
Hi,
The attached patch ensures we don't try to relabel files from arbitrary mounts, like /media/usbkey/*. One person pointed out on fedora-devel that setting extended attributes on ext3 causes older kernels not to be able to mount them. It seems safest to have the default behavior be the least invasive. People who want to label their mount points can do so manually.
One thing that might be nice is to have a "removable_context" config file. Then we modify HAL to automatically mount removable media with -o context=$(cat $SELINUXROOT/contexts/removable_context). (Really getting the context via libselinux of course). People who want to override that behavior can simply add the device manually to fstab, that will cause HAL not to create a new entry.
file_contexts/types.fc renamed from file_contexts/types.fc~ +7 -3
@@ -55,10 +55,14 @@ HOME_DIR/.+ system_u:object_r:ROLE_home_t /root/.default_contexts -- system_u:object_r:default_context_t + # -# A common mount point -/mnt(/.*)? -d system_u:object_r:mnt_t -/media(/.*)? -d system_u:object_r:mnt_t +# Mount points; do not relabel subdirectories, since +# we don't want to change any removable media by default. +/mnt(/[^/]*)? -d system_u:object_r:mnt_t +/mnt/[^/]*/.* <<none>> +/media(/[^/]*)? -d system_u:object_r:mnt_t +/media/[^/]*/.* <<none>> # # /var
Merged.
Quoted 16 lines · Colin Walters
Hi,
The attached patch ensures we don't try to relabel files from arbitrary mounts, like /media/usbkey/*. One person pointed out on fedora-devel that setting extended attributes on ext3 causes older kernels not to be able to mount them. It seems safest to have the default behavior be the least invasive. People who want to label their mount points can do so manually.
One thing that might be nice is to have a "
removable_context" config file. Then we modify HAL to automatically mount removable media with -o context=$(cat $SELINUXROOT/contexts/removable_context). (Really getting the context via libselinux of course). People who want to override that behavior can simply add the device manually to fstab, that will cause HAL not to create a new entry.
Signature · 7 lines
James Carter <[email protected]> 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 9 lines · Colin Walters
Quoted 7 lines
One thing that might be nice is to have a "
removable_context" config file. Then we modify HAL to automatically mount removable media with -o context=$(cat $SELINUXROOT/contexts/removable_context). (Really getting the context via libselinux of course). People who want to override that behavior can simply add the device manually to fstab, that will cause HAL not to create a new entry.
GREAT idea, because i am having the same difficulty with usbmount + autofs.
yes, this is essential.
colin, what do you propose _be_ in the removable_context because i guessed about putting {username}:object_r:home_dir_t in there, where {username} is determined by who owns /dev/console or simply by an over-ride in /etc/usb-mount.conf.
obviously, if it's say a usb hard drive that has ext2 / ext3 partitions on it.... something that is likely to become increasingly common with the introduction of SATA ... my hacked-up idea ain't gonna cut it.
l.
--
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 9 lines · Luke Kenneth Casson Leighton
GREAT idea, because i am having the same difficulty with usbmount + autofs.
yes, this is essential.
colin, what do you propose _be_ in the
removable_contextbecause i guessed about putting {username}:object_r:home_dir_t in there, where {username} is determined by who owns/dev/consoleor simply by an over-ride in/etc/usb-mount.conf.
Dan, John Palmieri and I talked about this, and we agreed that it is bad that currently file contexts on removable ext3 media is trusted.
Right now when a device is inserted HAL generates an fstab entry for it, and includes "nosuid, noexec, nodev" (actually these are implied by the "user" option).
So I think what we want is a single context for all removable media by default. Previously I suggested HAL could grab the context from a policy config file, and add that to the fstab entry for it, similarly to how it adds nosuid. Let's say it's system_u:object_r:removable_content_t by default. Then we'd want a boolean for whether users can read it or not. At this point we don't need the "noexattrfile" attribute anymore.
However, this doesn't give an easy solution for someone who does want to use the contexts on removable media, because then you get into the very thorny issue of identifying removable media. One idea John suggested during the discussion was for the removable media to have an identifying cryptographic key on it, and HAL could verify this key, and then use it with a policy config file to map to either a particular context, or "trusted".
I don't think the cryptographic key is doable anytime soon, so I suggest for now we simply go with a single config file with a single context in it, and patch HAL.
So to summarize, what we need from SELinux is a new libselinux function:
const char * get_media_type (void)
which would just read from a config file like initrc_context.
Luke: I'm not sure how this would fit in your usbmount+autofs setup. But if you figure out which component is mounting the device, you can modify that in the same way we'll modify HAL. Then you could simply modify your policy to allow users access to removable_content_t.
Quoted 6 lines · Colin Walters
Dan, John Palmieri and I talked about this, and we agreed that it is bad that currently file contexts on removable ext3 media is trusted.
Right now when a device is inserted HAL generates an fstab entry for it, and includes "nosuid, noexec, nodev" (actually these are implied by the "user" option).
Just as a side note, nosuid also disables domain transitions for any programs on the filesystem, so at least you can't provide arbitrary entrypoint programs on the removable media. I suppose the noexec makes this moot anyway.
Signature · 8 lines
Stephen Smalley <[email protected]> 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 11 lines · Stephen Smalley
Quoted 6 lines · Colin Walters
Dan, John Palmieri and I talked about this, and we agreed that it is bad that currently file contexts on removable ext3 media is trusted.
Right now when a device is inserted HAL generates an fstab entry for it, and includes "nosuid, noexec, nodev" (actually these are implied by the "user" option).
Just as a side note, nosuid also disables domain transitions for any programs on the filesystem, so at least you can't provide arbitrary entrypoint programs on the removable media.
I didn't know that; that certainly helps.
Ok, well we still have the other problems of the varied genfs types for removable media, and that removable media which does have filesystems that support xattrs but which may not be labeled, and we don't want to relabel it.
Quoted 6 lines · Colin Walters
On Tue, 2004-09-14 at 00:28 +0100, Luke Kenneth Casson Leighton wrote:
However, this doesn't give an easy solution for someone who does want to use the contexts on removable media, because then you get into the very thorny issue of identifying removable media. One idea John suggested during the discussion was for the removable media to have an identifying cryptographic key on it,
unless you actually digitally sign the content of the drive in some way, or tie it somehow to the actual hardware, a cryptographic key is of absolutely no use to you: it can be copied.
if the drive and its contents are copied, verbatim (including selinux attributes): fine, great.
[you're not trying to stop people _copying_ the data, you're trying
to stop them _modifying_ it.]
your simple options are:
* for those that don't care, use as you suggest removable_content_t:
you don't care what's on it, users just have access to it.
[for now i am using mount -ocontext={theuser}:object_r:user_home_t
but of course that means that i must add allow rules to vfat, msdos and all other potential types of mountable/removable filesystems - it's a bit yuk. ]
* for the ultra-paranoid, place an encrypted (or even just digitally signed - if that's possible) filesystem on the removable media.
this could be done "on top of" the filesystem which is mounted as removable_content_t.
the more complex option is:
- digitally sign the contents of the entire drive - every file, every directory, every extented attribute - everything.
- keep a copy of that digital signature securely on the host. what you MUST NOT allow is people to arbitrarily modify that signature.
- if you put the media in another machine, and modify it, then put the media back into the original machine, you will need to "update" the digital signatures in some secure fashion.
Quoted 1 line
Luke: I'm not sure how this would fit in your usbmount+autofs setup.
fairly easy.
it's a pretty straightforward shell script run from autofs (like the knoppix live cd does) to cover /media, and a hacked-up entry in /etc/hotplug/usb.agent to run a script (usbmount) that creates an icon on the desktop which links to /media/sda1 (or whatever hotplug says the new device is).
Quoted 3 lines
But if you figure out which component is mounting the device, you can modify that in the same way we'll modify HAL. Then you could simply modify your policy to allow users access to
removable_content_t.
ack!
and at some point i will investigate HAL and use it [if it's entirely gnome-free and gnome-session-free as well].
ta colin,
l.
Signature · 13 lines
-- Truth, honesty and respect are rare commodities that all spring from the same well: Love. If you love yourself and everyone and everything around you, funnily and coincidentally enough, life gets a lot better. -- <a href="http://lkcl.net"> lkcl.net </a> <br /> <a href="mailto:[email protected]"> [email protected] </a> <br /> -- 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.