Skip to contentSkip to conversation

ls -Z on non-SE machine

DISCUSSION Russell Coker 4 participants 9 messages May 15, 2005 – May 16, 2005 SELinux security module

lore
Share & tools
lore
#0 lore raw

Currently "ls -Z" refuses to operate if it detects that SE Linux is not enabled on the machine.

This makes no sense to me. Files that are labelled when running SE Linux keep their labels (and the values of such labels may still be read) when not running SE Linux. It seems quite reasonable to me that an administrator may want to take a disk out of a SE Linux machine and mount it on a non-SE machine for debugging problems or forensics. The current behavior of ls works against such operations.

I believe that the best thing to do is to have ls not be linked against libselinux and instead just call the XATTR api for reading the file contexts. Ideally I think that such functionality should be enabled unconditionally so that any administrator who receives a disk that was used on a SE Linux system will have the ability to conveniently view all the data on it.

Signature · 9 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page

--
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.
#1 lore raw

how about just silently ignoring the -Z option if selinux is detected to not be enabled?

or placing dummy information in its place which any selinux-aware shell scripts can pick up on.

Quoted 26 lines · Russell Coker

Currently "ls -Z" refuses to operate if it detects that SE Linux is not enabled on the machine.

This makes no sense to me. Files that are labelled when running SE Linux keep their labels (and the values of such labels may still be read) when not running SE Linux. It seems quite reasonable to me that an administrator may want to take a disk out of a SE Linux machine and mount it on a non-SE machine for debugging problems or forensics. The current behavior of ls works against such operations.

I believe that the best thing to do is to have ls not be linked against libselinux and instead just call the XATTR api for reading the file contexts. Ideally I think that such functionality should be enabled unconditionally so that any administrator who receives a disk that was used on a SE Linux system will have the ability to conveniently view all the data on it.

Signature · 9 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page

--
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.
Signature · 8 lines
--
<a href="http://lkcl.net">http://lkcl.net</a>
--

--
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.
#2 lore raw
Quoted 2 lines · Luke Kenneth Casson Leighton

how about just silently ignoring the -Z option if selinux is detected to not be enabled?

I believe that's what it does right now, and Russell's arguing against that behavior - he's saying you should be able to view the contexts, whether or not SELinux is running (unless I am misunderstanding).

Quoted 3 lines
Quoted 3 lines

I believe that the best thing to do is to have ls not be linked against libselinux and instead just call the XATTR api for reading the file contexts. Ideally I think that such functionality should be enabled unconditionally

Signature · 8 lines
Ivan Gyurdiev <[email protected]>
Cornell University


--
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.
#3 lore raw
Quoted 7 lines · Ivan Gyurdiev
Quoted 2 lines · Luke Kenneth Casson Leighton

how about just silently ignoring the -Z option if selinux is detected to not be enabled?

I believe that's what it does right now, and Russell's arguing against that behavior - he's saying you should be able to view the contexts, whether or not SELinux is running (unless I am misunderstanding).

no, it doesn't. an error is generated saying that the "-Z" argument is not understood.

the resultant error (non-zero exit code) causes, for example, initialisation scripts to fail.

the behaviour is also different: an error code is printed out on stderr.

that's _not_ silent behaviour :)

yes, i am running my laptop with debian / selinux disabled, with the se-aware coreutils package still installed on it.

every time i boot up, i get a "ls -Z" error in one of the key initialisation scripts.

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.

#4 lore raw
In reply to Luke Kenneth Casson Leighton
Quoted 5 lines · Luke Kenneth Casson Leighton

how about just silently ignoring the -Z option if selinux is detected to not be enabled?

or placing dummy information in its place which any selinux-aware shell scripts can pick up on.

You appear to have totally ignored my points about analysis of SE Linux disks in non-SE machines and recovery of SE Linux systems from non-SE rescue disks.

We could just not use the -Z option if we don't want the security contexts to be displayed. But the entire point here is to have them available.

Quoted 28 lines · Russell Coker
Quoted 27 lines

Currently "ls -Z" refuses to operate if it detects that SE Linux is not enabled on the machine.

This makes no sense to me. Files that are labelled when running SE Linux keep their labels (and the values of such labels may still be read) when not running SE Linux. It seems quite reasonable to me that an administrator may want to take a disk out of a SE Linux machine and mount it on a non-SE machine for debugging problems or forensics. The current behavior of ls works against such operations.

I believe that the best thing to do is to have ls not be linked against libselinux and instead just call the XATTR api for reading the file contexts. Ideally I think that such functionality should be enabled unconditionally so that any administrator who receives a disk that was used on a SE Linux system will have the ability to conveniently view all the data on it.

--
http://www.coker.com.au/selinux/ My NSA Security Enhanced Linux
packages http://www.coker.com.au/bonnie++/ Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/ Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/ My home page

--
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.

Signature · 9 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page

--
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 10 lines · Russell Coker
Quoted 5 lines · Luke Kenneth Casson Leighton

how about just silently ignoring the -Z option if selinux is detected to not be enabled?

or placing dummy information in its place which any selinux-aware shell scripts can pick up on.

You appear to have totally ignored my points about analysis of SE Linux disks in non-SE machines and recovery of SE Linux systems from non-SE rescue disks.

.... ignored, no.

implications-of: hadn't sunk in.

yep - i get it now.

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.

#6 lore raw
In reply to Russell Coker
Quoted 2 lines · Russell Coker

Currently "ls -Z" refuses to operate if it detects that SE Linux is not enabled on the machine.

This is a historical artifact of the time when ls --context relied on the SELinux API, which was only present in SELinux-patched and enabled kernels (prior to the 2.6 SELinux).

Quoted 6 lines

This makes no sense to me. Files that are labelled when running SE Linux keep their labels (and the values of such labels may still be read) when not running SE Linux. It seems quite reasonable to me that an administrator may want to take a disk out of a SE Linux machine and mount it on a non-SE machine for debugging problems or forensics. The current behavior of ls works against such operations.

I agree; this is just a historical artifact, although an admin can use getfattr and similar utilities at present to get this information when SELinux is disabled.

Quoted 5 lines

I believe that the best thing to do is to have ls not be linked against libselinux and instead just call the XATTR api for reading the file contexts. Ideally I think that such functionality should be enabled unconditionally so that any administrator who receives a disk that was used on a SE Linux system will have the ability to conveniently view all the data on it.

I disagree with this. ls can be linked against libselinux and use getfilecon and friends and still work fine on a non-SELinux enabled system. If you look at getfilecon's implementation in libselinux, you'll see that it will work on fine on any kernel that provides the xattr API and includes the security namespace for xattrs. Using the libselinux getfilecon(3) function has the following advantages:
1) It internally handles allocation of the context buffers, simplifying the application code, unlike getxattr.
2) It encapsulates the attribute name (security.selinux),
3) It allows the introduction of a transparent translation layer within libselinux to translate MLS labels, as discussed previously (I have some concerns with this, but it is the current approach by TCS and does save a lot of engineering time on the individual utilities).

Instead of changing ls to use getxattr, we should just remove the is_selinux_enabled() check from ls and allow use of -Z at any time (worst case is that we'll end up with an error return from getfilecon, which is possible anyway and already being handled for the case where the filesystem doesn't support xattrs).

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.
#7 lore raw
Quoted 10 lines · Stephen Smalley
Quoted 6 lines

I believe that the best thing to do is to have ls not be linked against libselinux and instead just call the XATTR api for reading the file contexts. Ideally I think that such functionality should be enabled unconditionally so that any administrator who receives a disk that was used on a SE Linux system will have the ability to conveniently view all the data on it.

I disagree with this. ls can be linked against libselinux and use getfilecon and friends and still work fine on a non-SELinux enabled system.

It's true that libselinux functionality required by ls can work on a non-SE machine. However in that case when coreutils is compiled for non-SE systems ls will not have such functionality. I believe that it would be best to have the "ls -Z" functionality on systems without libselinux.

Quoted 6 lines

If you look at getfilecon's implementation in libselinux, you'll see that it will work on fine on any kernel that provides the xattr API and includes the security namespace for xattrs. Using the libselinux getfilecon(3) function has the following advantages:
1) It internally handles allocation of the context buffers, simplifying the application code, unlike getxattr.

There is already code in coreutils to manage xattrs, can some of that be re-used?

Quoted 5 lines

Instead of changing ls to use getxattr, we should just remove the is_selinux_enabled() check from ls and allow use of -Z at any time (worst case is that we'll end up with an error return from getfilecon, which is possible anyway and already being handled for the case where the filesystem doesn't support xattrs).

The MLS issue is compelling, this change will do.

Signature · 9 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page

--
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 4 lines · Russell Coker

It's true that libselinux functionality required by ls can work on a non-SE machine. However in that case when coreutils is compiled for non-SE systems ls will not have such functionality. I believe that it would be best to have the "ls -Z" functionality on systems without libselinux.

Not sure that this is a real issue; distros have seemed willing to accept libselinux as part of the base system, much like libattr/libacl. If they weren't, then we'd have to revisit the patches anyway to allow dlopen'ing of libselinux so that they could ship a single coreutils binary package that could support either SELinux or non-SELinux, as noted previously by Luke.

Quoted 2 lines

There is already code in coreutils to manage xattrs, can some of that be re-used?

I think that there is code for preserving attributes, and in the case of ls, code for indicating whether the file has attributes via a simple flag in the mode string, but I don't think they include code for displaying attributes in ls - I think they require you to run a separate utility to display the attributes like getfattr or getfacl. SELinux is distinctive in the level of direct integration. And in the case of preserving attributes, SELinux tends to do it differently (via setfscreatecon) so that the attributes are set down when the file is created rather than later.

Quoted 1 line

The MLS issue is compelling, this change will do.

Yes, I think just removing the is_selinux_enabled() test is sane in the
case of ls. Might be more problematic for programs like cp where they
are using SELinux-specific interfaces like setfscreatecon.

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.