Skip to contentSkip to conversation

"star -xattr" in SELinux enabled system

DISCUSSION Nagendra Tomar 3 participants 10 messages Jun 7, 2007 – Jun 12, 2007 SELinux security module

lore
Share & tools
lore
#0 lore raw

Resending after subscribing to the SELinux mailing list

Nagendra Tomar <[email protected]> wrote: Date: Thu, 7 Jun 2007 23:47:40 +0100 (BST)
From: Nagendra Tomar <[email protected]>
Subject: "star -xattr" in SELinux enabled system
To: [email protected]

When I try to unpack a star tarball which was packed with the xattr option (to retain the selinux file contexts), I get a lot of "denied" errors. These errors are not unexpected, as star tries to set the extended attributes of each of the component file in the tarball as it extracts them.
Since, I've not given the relabelfrom/relabelto permissions for those combinations of file contexts, the errors are expected. Apart from the relabel from/to errors, there are also mkdir/create file errors as start tries to create directories and files inside directories with contexts which the star process' domain has not been authorized to. Nothing wrong in this, as this is what SELinux is supposed to do.
I'm running a modified ref policy where my goal is to be very restrictive in what I allow.
My question is:
Can it be inferred that star (or tar for that matter) is best avoided if we want to make a very secure/restrictive SELinux policy ? O/w the policy has to be modified for any star tarball that we may want to extract.
I'm running star from the rc scripts (with initrc_t) domain. Everytime I allow initrc_t domain some create/write/relabelto/relabelfrom permission, I feel that I am allowing more than what I should. Will it be a good idea to assign a different domain to the star process and allow that domain all these permissions (the problem of future star tarballs failing to extract is still there though)

Regds,
Tomar

---------------------------------
Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for your free account today.

---------------------------------
Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for your freeaccount today.

#1 lore raw
Quoted 2 lines · Nagendra Tomar

Can it be inferred that star (or tar for that matter)  is best avoided if we want to make a very  secure/restrictive SELinux policy?

No. Just that you have to make sure that the combination of the contexts in the file and the context of the process that calls star is suitable to permit extraction.

Quoted 2 lines

O/w the policy
has to be modified for any star tarball that we may want to extract.

If you have to extract an arbitrary tarball (IE restore from backup) then you need to do so from a domain that has few restrictions. If you have a limited scope of operation for star then you have to make sure that the source archive matches this.

Also in some situations extracting the files to a temporary directory without applying contexts and then copying some files and running chcon on them (either manually or through a script) will be the correct thing to do.

Quoted 7 lines

I'm
running star from the rc scripts (with initrc_t) domain. Everytime I allow initrc_t domain some create/write/relabelto/relabelfrom permission, I feel that I am allowing more than what I should. Will it be a good idea to assign a different domain to the star process and allow that domain all these permissions (the problem of future star tarballs failing to extract is still there though)

Why do you need to extract many security contexts from a tar file in a rc script?

Signature · 11 lines
[email protected]
http://etbe.coker.com.au/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development



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

Russell Coker <[email protected]> wrote:Why do you need to extract many security contexts from a tar file in a rc script?

I need to add files from an archive stored on flash to my RFS. This has to happen during boot.
I have resolved this issue by extracting the required archives, before the SELinux policy is loaded, i.e from the initramfs' init script and not from the rc script as I mentioned before.

Thanx for your comments.

- Tomar

Signature · 14 lines
[email protected]
http://etbe.coker.com.au/          My Blog
-- 
[email protected]
http://etbe.coker.com.au/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development
http://www.coker.com.au/sponsorship.html Sponsoring Free Software development



       
---------------------------------
 Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for your freeaccount today.
#3 lore raw
Quoted 7 lines · Nagendra Tomar

Russell Coker <[email protected]> wrote:Why do you need to extract many security contexts from a tar file in a rc script?

I need to add files from an archive stored on flash to my RFS. This has to happen during boot. I have resolved this issue by extracting the required archives, before the SELinux policy is loaded, i.e from the initramfs' init script and not from the rc script as I mentioned before.

If you are going to run the script in question without confinement, then why not use an unconfined domain after the policy is loaded instead of doing it before policy load?

Setting contexts before the policy load means that the contexts can't be validated, and I can't think of any benefits to doing it in the initramfs.

Signature · 9 lines
[email protected]
http://etbe.coker.com.au/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development

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

Russel,
Thanx for your inputs.

As fas as I understand (pls correct me if I am wrong) putting an app in unconfined domain is only a temporary measure till we have a
complete policy for that app. Ideally we should not be allowing any
app in unconfined domain. Is it not against the SELinux principle
of "least privelege".

When would we want to run an app in unconfined domain, keeping aside the fact that we do not have a completed policy
for that app. It is something that was introduced for convenience
in the dekstop case where there are so many apps to be run.
For an embedded box, where there are only a few apps, running in controlled conditions, is it not adivisable to do away completely with the unconfined domain ?

Regding you concern for the contexts not being validated, I understand that it might allow certain files to be labelled with contexts which the policy does not understand. Did you mean anything else by validation ?

The way I take care of this is by labelling the starball with setfiles using the same policy (contexts/files/file_contexts file) as the complete root filesystem. This is done during the build process. I believe setfiles can do the validation against the policy.

Thanx,
Tomar

Quoted 7 lines · Nagendra Tomar

Russell Coker wrote:Why do you need to extract many security contexts from a tar file in a rc script?

I need to add files from an archive stored on flash to my RFS. This has to happen during boot. I have resolved this issue by extracting the required archives, before the SELinux policy is loaded, i.e from the initramfs' init script and not from the rc script as I mentioned before.

If you are going to run the script in question without confinement, then why not use an unconfined domain after the policy is loaded instead of doing it before policy load?

Setting contexts before the policy load means that the contexts can't be validated, and I can't think of any benefits to doing it in the initramfs.

Signature · 14 lines
[email protected]
http://etbe.coker.com.au/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development

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


       
---------------------------------
 Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for your freeaccount today.
#5 lore raw
Quoted 5 lines · Nagendra Tomar

As fas as I understand (pls correct me if I am wrong) putting an
app in unconfined domain is only a temporary measure till we have a complete policy for that app. Ideally we should not be allowing any app in unconfined domain. Is it not against the SELinux principle
of "least privelege".

Sometimes the "least privilege" for an application is to allow it to do almost anything.

I agree that using minimum privs is a good thing, for example init_t and initrc_t could be used to remove SE Linux and Unix access controls in most cases but it is possible that an exploit developed for such programs would only allow certain access and that if that access was blocked then the exploit would not function. There has been at least one report of a kernel exploit not working as unconfined_t!

Quoted 7 lines

When would we want to run an app in unconfined domain, keeping
aside the fact that we do not have a completed policy for that app. It is something that was introduced for convenience
in the dekstop case where there are so many apps to be run. For an embedded box, where there are only a few apps, running in controlled conditions, is it not adivisable to do away completely with the unconfined domain ?

I agree that it makes sense to restrict things as much as possible. But when you have data coming from a trusted source the benefits are minimal. You could of course have a domain that has minimal access to other processes but full access to all files on disk.

Quoted 3 lines

Regding you concern for the contexts not being validated, I understand
that it might allow certain files to be labelled with contexts which the policy does not understand. Did you mean anything else by validation ?

That's what I mean.

Quoted 4 lines

The way I take care of this is by labelling the starball with
setfiles using the same policy (contexts/files/file_contexts file) as the complete root filesystem. This is done during the build process. I believe setfiles can do the validation against the policy.

That's the right thing to do. But if you make a mistake or if the file is corrupted it would be good to have SE Linux check the context and give you a useful error message rather than working and giving you an AVC about unlabeled_t later on.

Signature · 9 lines
[email protected]
http://etbe.coker.com.au/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development

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

There has been at least one report of a kernel exploit not working as unconfined_t!

http://www.redhat.com/archives/fedora-selinux-list/2006-July/msg00071.html

Above is the reference to an exploit stopped by targeted policy. It doesn't mean much as a.out support (not provided by default in any of the tested distributions) is required for the exploit. So the people who tested this had to go out of their way to make their machine vulnerable to see that SE Linux protected it. But it does suggest that the same thing could happen again.

It has been mentioned on this before, but it's worth mentioning again.

Signature · 9 lines
[email protected]
http://etbe.coker.com.au/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development

--
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
In reply to Russell Coker
Quoted 5 lines · Nagendra Tomar

As fas as I understand (pls correct me if I am wrong) putting an
app in unconfined domain is only a temporary measure till we have a complete policy for that app. Ideally we should not be allowing any app in unconfined domain. Is it not against the SELinux principle
of "least privelege".

Sometimes the "least privilege" for an application is to allow it to do almost anything.

???? Can you pls explain this ?

I agree that using minimum privs is a good thing, for example init_t and initrc_t could be used to remove SE Linux and Unix access controls in most cases but it is possible that an exploit developed for such programs would only allow certain access and that if that access was blocked then the exploit would not function. There has been at least one report of a kernel exploit not working as unconfined_t!

Thanx for the pointer.

Quoted 7 lines

When would we want to run an app in unconfined domain, keeping
aside the fact that we do not have a completed policy for that app. It is something that was introduced for convenience
in the dekstop case where there are so many apps to be run. For an embedded box, where there are only a few apps, running in controlled conditions, is it not adivisable to do away completely with the unconfined domain ?

I agree that it makes sense to restrict things as much as possible. But when you have data coming from a trusted source the benefits are minimal. You could of course have a domain that has minimal access to other processes but full access to all files on disk.

Is that not as bad as it can get ? If a domain is allowed to do anything with all files on the filesystem, it can craft a file with the right context which can then lead it to other domains (on execution). I understand that SELinux can disallow this by blocking the exec rights for the unconfined domain (for that particular context), but will it not be more prone to errors to ensure that for all possible contexts.

Quoted 3 lines

Regding you concern for the contexts not being validated, I understand
that it might allow certain files to be labelled with contexts which the policy does not understand. Did you mean anything else by validation ?

That's what I mean.

Quoted 4 lines

The way I take care of this is by labelling the starball with
setfiles using the same policy (contexts/files/file_contexts file) as the complete root filesystem. This is done during the build process. I believe setfiles can do the validation against the policy.

That's the right thing to do. But if you make a mistake or if the file is corrupted it would be good to have SE Linux check the context and give you a useful error message rather than working and giving you an AVC about unlabeled_t later on.

Signature · 9 lines
[email protected]
http://etbe.coker.com.au/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development


 		
---------------------------------
 What kind of emailer are you? Find out today - get a free analysis of your email personality. Take the quiz at the Yahoo! Mail Championship.
#8 lore raw
Quoted 4 lines · Nagendra Tomar
Quoted 2 lines

Sometimes the "least privilege" for an application is to allow it to do almost anything.

???? Can you pls explain this ?

For example sysadm_t in the strict policy. The range of tasks performed by the sys-admin in regular operation includes everything that a hostile process might want to do.

BTW Please make sure you clearly indicate who wrote each piece of text. Failing to do so confuses people who are trying to follow the discussion, is a copyright violation, and may be considered to be libel.

It is easies for you to correctly indicate the level of quoting when replying to me as it is for me to fix things up when replying to your message.

Quoted 8 lines
Quoted 4 lines

I agree that it makes sense to restrict things as much as possible. But when you have data coming from a trusted source the benefits are minimal. You could of course have a domain that has minimal access to other processes but full access to all files on disk.

Is that not as bad as it can get ? If a domain is allowed to do anything with all files on the filesystem, it can craft a file with the right context which can then lead it to other domains (on execution). I

This is your scenario! You presented me with a requirement and I suggested how you could solve it. If the process does not need to create arbitrary files but instead needs to create files from a small list of types that are known in advance then modifying the policy to cope with it is easy.

Signature · 9 lines
[email protected]
http://etbe.coker.com.au/          My Blog

http://www.coker.com.au/sponsorship.html Sponsoring Free Software development

--
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.
#9 lore raw
In reply to Nagendra Tomar
Quoted 27 lines · Nagendra Tomar

Resending after subscribing to the SELinux mailing list

Nagendra Tomar <[email protected]> wrote:
Date: Thu, 7 Jun 2007 23:47:40 +0100 (BST)
From: Nagendra Tomar <[email protected]>
Subject: "star -xattr" in SELinux enabled system
To: [email protected]

When I try to unpack a star tarball which was packed with the xattr option (to retain the selinux file contexts), I get a lot of "denied" errors. These errors are not unexpected, as star tries to set the extended attributes of each of the component file in the tarball as it extracts them.
Since, I've not given the relabelfrom/relabelto
permissions for those combinations of file contexts, the errors are expected. Apart from the relabel from/to errors, there are also mkdir/create file errors as start tries to create directories and files inside directories with contexts which the star process' domain has not been authorized to. Nothing wrong in this, as this is what SELinux is supposed to do.
I'm running a modified ref policy where my goal is to be very
restrictive in what I allow.
My question is:
Can it be inferred that star (or tar for that matter) is best avoided if we want to make a very secure/restrictive SELinux policy ? O/w the policy has to be modified for any star

Quoted 8 lines

tarball that we may want to extract.
I'm running star from the rc scripts (with initrc_t)
domain. Everytime I allow initrc_t domain some create/write/relabelto/relabelfrom permission, I feel that I am allowing more than what I should. Will it be a good idea to assign a different domain to the star process and allow that domain all these permissions (the problem of future star tarballs failing to extract is still there though)

This is somewhat similar to the question of how cp -p should handle the situation when it cannot preserve the file security context of the original due to a permissions issue. My view is that such applications should by default fall back to creating the file in the default file creation context of the process if they are not permitted to preserve the context of the original file unless the user specified an explicit option indicating that the operation should abort if it cannot preserve context. The application should never assume that it will always be allowed to preserve the context of the original, as many policies won't permit that to happen even for legitimate use.

Running star in a distinct domain from initrc_t may make sense just from the perspective that it likely requires different permissions from the rest of initrc_t, but granting that domain the ability to extract all file contexts is not likely what you truly want (e.g. I wouldn't want it to be able to replace /sbin/init).

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.