Skip to contentSkip to conversation

Failed write to /selinux/context in selinux_trans_to_raw_contex()

DISCUSSION Ryan Bradetich 4 participants 15 messages Mar 1, 2007 – Mar 5, 2007 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hello all,

I have tracked down a problem that prevents me from logging into my system when I build a policy that only has the base modules defined. All the notes below are using revision 2202 of the reference policy (sorry for the length of the email, these are my notes while tracking down the problem... hopefully something in them will offer some
insight to the problem). This problem is very reproducible for me:

base-only policy:
1. make bare
2. make conf
3. vi policy/modules.conf (:1,$s/= module/= off/g)
4. make policy
5. make load
6. sync
7. reboot

everything policy:
1. make bare
2. make conf
3. make policy
4. make load
5. sync
6. reboot

kernel version: 2.6.20

I am really hoping for a description of what is supposed to happen, so
I better understand how the security server works. My end goal is to
continue stripping down the reference policy to the bare minimum so I can build a custom security policy for my embedded research project.

The problem I am seeing now is when I attempt to log into the system with SELinux enabled, but in permissive mode the get_default_context() in libselinux1 returns an error. This error prevents me for logging into the system, but when I boot the system with the selinux=0 kernel parameter I am able to log into the system fine.

Here are my notes:

1. The login busybox applet makes a call to get_default_context() in the libselinux1 library. It passes the following arguments:

     user: "root"
     fromcon:  NULL,
     newcon: &user_sid;

2. get_default_context() calls the get_ordered_context_list(), also in the libselinux1 library. This function returns -1.

3. get_ordered_context_list() calls the security_compute_user(), also in the libselinux1
library. This function returns 0.

4. In security_compute_user()
The following check is passed: selinux_trans_to_raw_context()

5. check_compute_user() calls the security_compute_user_raw() function. The selinux_mnt is defined.
Was able to open /selinux/user
Was able to allocate memory.
Was able to write to /selinux/user
Was able to read from /selinux/user
nel = 0

At this point the security_compute_user_raw() and check_compute_user() both fall through and drop back to the get_ordered_context_list(). The nreach variable is calculated and ends up 0, where it goes jumps to the failsafe label.

[NOTE: why are we in the failsafe? Seems like I am missing something that would avoid this step].

Tracing down into the failsafe label I found the following:

6. Makes a call to the get_failsafe_context. Open the selinux_failsafe_context_path() Perform a fgets_unlocked from the file descriptor Allocate a new conn using information from the
selinux_failsafe_context_path.
Call the security_check_context()

7. The security_check_context() calls the selinux_trans_to_raw_context().

8. The selinux_trans_to_raw_context does the following:
opens /selinux/context
writes to /selinux/context

This write system call is the difference between the everything policy
and the base-only policy files. With the everything policy, this
write command successfully writes 23 bytes. In the base-only policy,
the write command fails and sets errno to 22.

Thanks!

- Ryan

--
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
Quoted 9 lines · Ryan Bradetich

Hello all,

I have tracked down a problem that prevents me from logging into my system when I build a policy that only has the base modules defined. All the notes below are using revision 2202 of the reference policy (sorry for the length of the email, these are my notes while tracking down the problem... hopefully something in them will offer some
insight to the problem). This problem is very reproducible for me:

Quoted 4 lines

base-only policy:
1. make bare
2. make conf
3. vi policy/modules.conf (:1,$s/= module/= off/g)

Um, why do you expect this to work? Looking at a modules.conf here, that would exclude userdomain from the build, and thus no user domains at all. Which is fine from a dependency view (hence not in base) but not if you want users to login...

Quoted 52 lines

4. make policy
5. make load
6. sync
7. reboot

everything policy:
1. make bare
2. make conf
3. make policy
4. make load
5. sync
6. reboot

kernel version: 2.6.20

I am really hoping for a description of what is supposed to happen, so
I better understand how the security server works. My end goal is to
continue stripping down the reference policy to the bare minimum so I can build a custom security policy for my embedded research project.

The problem I am seeing now is when I attempt to log into the system with SELinux enabled, but in permissive mode the get_default_context() in libselinux1 returns an error. This error prevents me for logging into the system, but when I boot the system with the selinux=0 kernel parameter I am able to log into the system fine.

Here are my notes:

1. The login busybox applet makes a call to get_default_context() in the libselinux1 library. It passes the following arguments:

      user: "root"
      fromcon:  NULL,
      newcon: &user_sid;

2. get_default_context() calls the get_ordered_context_list(), also in the libselinux1 library. This function returns -1.

3. get_ordered_context_list() calls the security_compute_user(), also in the libselinux1
library. This function returns 0.

4. In security_compute_user()
The following check is passed: selinux_trans_to_raw_context()

5. check_compute_user() calls the security_compute_user_raw() function. The selinux_mnt is defined.
Was able to open /selinux/user
Was able to allocate memory.
Was able to write to /selinux/user
Was able to read from /selinux/user
nel = 0

Quoted 7 lines

At this point the security_compute_user_raw() and check_compute_user() both fall through and drop back to the get_ordered_context_list(). The nreach variable is calculated and ends up 0, where it goes jumps to the failsafe label.

[NOTE: why are we in the failsafe? Seems like I am missing something that would avoid this step].

Yes, this means that there were no reachable contexts for the user from the login app's context in the policy. Or no defined contexts for the user at all in the policy. So it bails and tries the failsafe one as a fallback for recovery.

Quoted 16 lines

Tracing down into the failsafe label I found the following:

6. Makes a call to the get_failsafe_context. Open the selinux_failsafe_context_path() Perform a fgets_unlocked from the file descriptor Allocate a new conn using information from the
selinux_failsafe_context_path.
Call the security_check_context()

7. The security_check_context() calls the selinux_trans_to_raw_context().

8. The selinux_trans_to_raw_context does the following:
opens /selinux/context
writes to /selinux/context

Quoted 4 lines

This write system call is the difference between the everything policy
and the base-only policy files. With the everything policy, this
write command successfully writes 23 bytes. In the base-only policy,
the write command fails and sets errno to 22.

Yes, because even the failsafe context wouldn't be defined if you excluded userdomain.

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

Stephen,

Thanks for your time and reply!
My answers are in-lined below.

- Ryan

Quoted 1 line · Stephen Smalley

On Wed, 2007-02-28 at 23:57 -0800, Ryan Bradetich wrote:

[snip]

Quoted 6 lines
Quoted 1 line

3. vi policy/modules.conf (:1,$s/= module/= off/g)

Um, why do you expect this to work? Looking at a modules.conf here, that would exclude userdomain from the build, and thus no user domains at all. Which is fine from a dependency view (hence not in base) but not if you want users to login...

I understand and that was my first thought when I got the login error. In the SELinux by example book it does talk about this in section 6.3.2. And there is a note in the book that matches my error
condition: If the generic user_u or the Linux user is not explicitly defined in the SELinux policy, logins will be denied ... even in permissive mode. I did the following comparisons between the policies before I started debugging the libselinux1 library. I apologize, I did not put this information in my email notes.

  # grep '^[ \t]*user ' policy.conf.base
    user system_u roles { system_r };
    user user_u roles { user_r };
    user staff_u roles { staff_r sysadm_r  };
    user sysadm_u roles { sysadm_r };
  # grep '^[ \t]*user ' policy.conf.all
    user system_u roles { system_r };
    user user_u roles { user_r };
    user staff_u roles { staff_r sysadm_r  };
    user sysadm_u roles { sysadm_r };

Is my understanding correct that if these users are defined in the policy.conf file and it successfully compiles into the binary policy, then the user contexts should be available to the policy (even though the userdomain module was not included?).

At this point, I am not sure why or how the user and role information is getting added to the policy.conf file when only the base modules
are defined. I found then when I went to add the users manually. I
did not dig into the how part, I was more interested in why it was not working. I will need to understand the how part later as I continue to strip down the base policies.

[snip]

Quoted 7 lines
Quoted 2 lines

[NOTE: why are we in the failsafe? Seems like I am missing something that would avoid this step].

Yes, this means that there were no reachable contexts for the user from the login app's context in the policy. Or no defined contexts for the user at all in the policy. So it bails and tries the failsafe one as a fallback for recovery.

But in this case, there was no reachable contexts for the full policy or the base-only policy. In both cases I was always hitting the
failsafe context. The only difference between the full-policy and
the base-only policy is the base-only policy failed to write to /selinux/context. Does this mean I have something configured improperly on my system?

[snip]

Quoted 7 lines
Quoted 4 lines

This write system call is the difference between the everything policy
and the base-only policy files. With the everything policy, this
write command successfully writes 23 bytes. In the base-only policy,
the write command fails and sets errno to 22.

Yes, because even the failsafe context wouldn't be defined if you excluded userdomain.

I did try to add the userdomain module as a stand-alone module, but it requires the use of several other modules such as init, etc. I can go back and re-construct the list of required modules I needed to include the userdomain module if this is of interest. [NOTE: When I did have the userdomain + required modules in place, I was able to login successfully].

I understand I will need these modules eventually, but I am really trying to get my head around how these modules work. I will need this detailed information since I plan to write a busybox SELinux policy module which also implements the system functions like: init, loginutils, logging, etc.

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

#3 lore raw
Quoted 12 lines · Ryan Bradetich
   # grep '^[ \t]*user ' policy.conf.base
     user system_u roles { system_r };
     user user_u roles { user_r };
     user staff_u roles { staff_r sysadm_r  };
     user sysadm_u roles { sysadm_r };
   # grep '^[ \t]*user ' policy.conf.all
     user system_u roles { system_r };
     user user_u roles { user_r };
     user staff_u roles { staff_r sysadm_r  };
     user sysadm_u roles { sysadm_r };
Quoted 4 lines

Is my understanding correct that if these users are defined in the policy.conf file and it successfully compiles into the binary policy, then the user contexts should be available to the policy (even though the userdomain module was not included?).

No. For the context to be valid and reachable, you need:
- the user identity defined and authorized for a role (as above),
- the role defined and authorized for a domain/type,
- the domain/type defined, including transitions into it.

The statements above only do the first part.

Quoted 6 lines

At this point, I am not sure why or how the user and role information is getting added to the policy.conf file when only the base modules
are defined. I found then when I went to add the users manually. I
did not dig into the how part, I was more interested in why it was not working. I will need to understand the how part later as I continue to strip down the base policies.

User identities are defined by policy/users, not in the individual policy modules.

Quoted 3 lines

But in this case, there was no reachable contexts for the full policy or the base-only policy. In both cases I was always hitting the failsafe context.

That suggests that the login app wasn't running in the right context, in which case the context would be valid, but not reachable per policy.

Quoted 4 lines

The only difference between the full-policy and
the base-only policy is the base-only policy failed to write to /selinux/context. Does this mean I have something configured improperly on my system?

It didn't fail to write, but the write reported invalid argument, i.e. the context written was not valid per policy. That's the point of writing it to /selinux/context - to check its validity against policy.

Quoted 6 lines

I did try to add the userdomain module as a stand-alone module, but it requires the use of several other modules such as init, etc. I can go back and re-construct the list of required modules I needed to include the userdomain module if this is of interest. [NOTE: When I did have the userdomain + required modules in place, I was able to login successfully].

Naturally userdomain has dependencies; that isn't a surprise.

Quoted 5 lines

I understand I will need these modules eventually, but I am really trying to get my head around how these modules work. I will need this detailed information since I plan to write a busybox SELinux policy module which also implements the system functions like: init, loginutils, logging, etc.

I assume you are leveraging the sebusybox work then...

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

Hello Stephen,

Thanks again for your time and answers!

Quoted 18 lines · Stephen Smalley
Quoted 12 lines · Ryan Bradetich
   # grep '^[ \t]*user ' policy.conf.base
     user system_u roles { system_r };
     user user_u roles { user_r };
     user staff_u roles { staff_r sysadm_r  };
     user sysadm_u roles { sysadm_r };
   # grep '^[ \t]*user ' policy.conf.all
     user system_u roles { system_r };
     user user_u roles { user_r };
     user staff_u roles { staff_r sysadm_r  };
     user sysadm_u roles { sysadm_r };
Quoted 4 lines

Is my understanding correct that if these users are defined in the policy.conf file and it successfully compiles into the binary policy, then the user contexts should be available to the policy (even though the userdomain module was not included?).

Quoted 6 lines

No. For the context to be valid and reachable, you need:
- the user identity defined and authorized for a role (as above),
- the role defined and authorized for a domain/type,
- the domain/type defined, including transitions into it.

The statements above only do the first part.

Ah ha. The last piece was the piece I was missing. The base-only policy has the roles defined and authorized for the specific domain/type. I also have the domain/type defined, but I do not have any transitions into it. I will test this out later tonight by adding the appropriate transition.

Quoted 9 lines
Quoted 6 lines

At this point, I am not sure why or how the user and role information is getting added to the policy.conf file when only the base modules
are defined. I found then when I went to add the users manually. I
did not dig into the how part, I was more interested in why it was not working. I will need to understand the how part later as I continue to strip down the base policies.

User identities are defined by policy/users, not in the individual policy modules.

Make sense. I think I remember reading that now either in the SELinux book or one of the many SELinux howtos. I will have to go back and review this. Thanks for the pointer.

Quoted 6 lines
Quoted 3 lines

But in this case, there was no reachable contexts for the full policy or the base-only policy. In both cases I was always hitting the failsafe context.

That suggests that the login app wasn't running in the right context, in which case the context would be valid, but not reachable per policy.

Excellent. I will look into this as well. Is the login app required to run in a specific context? Or just a context that has the appropriate permissions to transfer to the domain the user is in?

Quoted 8 lines
Quoted 4 lines

The only difference between the full-policy and
the base-only policy is the base-only policy failed to write to /selinux/context. Does this mean I have something configured improperly on my system?

It didn't fail to write, but the write reported invalid argument, i.e. the context written was not valid per policy. That's the point of writing it to /selinux/context - to check its validity against policy.

Make sense. This is something I will probably dig into later ... sounds interesting and I am curious to understand exactly how it works :)

Quoted 8 lines
Quoted 6 lines

I did try to add the userdomain module as a stand-alone module, but it requires the use of several other modules such as init, etc. I can go back and re-construct the list of required modules I needed to include the userdomain module if this is of interest. [NOTE: When I did have the userdomain + required modules in place, I was able to login successfully].

Naturally userdomain has dependencies; that isn't a surprise.

Understood :) My intention was to try and bisect the differences, but it became pretty large quickly. I understand why, just thought it might be easier to trace the root of the problem through the libselinux1 library and see if I could figure out what was required that way.

Quoted 7 lines
Quoted 5 lines

I understand I will need these modules eventually, but I am really trying to get my head around how these modules work. I will need this detailed information since I plan to write a busybox SELinux policy module which also implements the system functions like: init, loginutils, logging, etc.

I assume you are leveraging the sebusybox work then...

Yes, I have been testing their patch sets and I am currently running the latest published patches. I have also been in contact with Nakamura-san off list to coordinate patches and features with the busybox people.

Thanks again for your insight!

- Ryan

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

#5 lore raw

Hello Stephen,

As you suggested, I found adding the following two lines to the policy.conf file allowed me to successfully login.

type sysadm_t;
role sysadm_r types sysadm_t;

Just wanted to let you know I got it working!

Thanks,

- Ryan

--
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 9 lines · Ryan Bradetich

Hello Stephen,

As you suggested, I found adding the following two lines to the policy.conf file allowed me to successfully login.

type sysadm_t;
role sysadm_r types sysadm_t;

Just wanted to let you know I got it working!

You would need more than that to make it work correctly in enforcing mode, as you have to allow the login domain to transition to it and you have to allow the sysadm_t domain sufficient permissions to operate. Which you would get just by including userdomain and its dependencies of course. If your goal is a stripped down policy, then I think you'll find it simpler to go through userdomain and its dependencies and gradually remove parts you think you don't need (re-testing at each change to verify that it didn't break the system) than trying to create your own user domains from the ground up.

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

Hello Stephen,

Quoted 11 lines · Stephen Smalley
Quoted 9 lines · Ryan Bradetich

Hello Stephen,

As you suggested, I found adding the following two lines to the policy.conf file allowed me to successfully login.

type sysadm_t;
role sysadm_r types sysadm_t;

Just wanted to let you know I got it working!

Quoted 9 lines

You would need more than that to make it work correctly in enforcing mode, as you have to allow the login domain to transition to it and you have to allow the sysadm_t domain sufficient permissions to operate. Which you would get just by including userdomain and its dependencies of course. If your goal is a stripped down policy, then I think you'll find it simpler to go through userdomain and its dependencies and gradually remove parts you think you don't need (re-testing at each change to verify that it didn't break the system) than trying to create your own user domains from the ground up.

Yep, I understand it will not work in enforcing mode yet. My system still needs a lot of work before I can put it into enforcing mode because I am using busybox instead of the standard Unix tools (that already have policies).

My goal is more than just a stripped down policy. I am currently researching SELinux for a specific usage. On paper, I have already broken the system down into high level domains and have defined high-level interactions between these domains. I do not believe the refpolicy will meet all my needs, but I am hoping to leverage as much as I can from the refpolicy.

Here is the rough plan I am pursuing to get busybox up and working on my system.

1. Strip the policy down to just the base modules. I needed the
above fix to allow me to login in. I am at this point right now.

2. Busybox provides the init functionality, So I am going to start evaluating and reviewing the init module and figure out what is needed to successfully allow the kernel_t domain to transition to the init_t domain and do the work init busybox init needs to do.

[NOTE: I will be asking the communities advice on shortly is how to handle busybox. The problem is that busybox is a single binary that provides the functionality of many binaries (init, login, coreutils, etc). I am not quite far enough to fully understand the problem, but I am pretty sure it will be a problem. I will start a different thread on this problem soon.]

3. Identify the next module that is throwing AVC errors and repeat step 2 until I am happy I have a working system.

4. Set the box in enforcing mode to make sure everything still works as I expected.

5. Test and evaluate the policy.

Hopefully the additional background on what I am trying to do makes sense. I am not trying to re-invent the wheel, just wanted to get the system down to a the base, so I could start adding the additional module functionality I need in the busybox module.

Thanks again for your time and input!

- Ryan

P.S Unfortunately, time for work. I will have to respond to your next email at lunch or after work tonight.

--
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 23 lines · Ryan Bradetich

Yep, I understand it will not work in enforcing mode yet. My system still needs a lot of work before I can put it into enforcing mode because I am using busybox instead of the standard Unix tools (that already have policies).

My goal is more than just a stripped down policy. I am currently researching SELinux for a specific usage. On paper, I have already broken the system down into high level domains and have defined high-level interactions between these domains. I do not believe the refpolicy will meet all my needs, but I am hoping to leverage as much as I can from the refpolicy.

Here is the rough plan I am pursuing to get busybox up and working on my system.

1. Strip the policy down to just the base modules. I needed the
above fix to allow me to login in. I am at this point right now.

2. Busybox provides the init functionality, So I am going to start evaluating and reviewing the init module and figure out what is needed to successfully allow the kernel_t domain to transition to the init_t domain and do the work init busybox init needs to do.

Quoted 6 lines

[NOTE: I will be asking the communities advice on shortly is how to handle busybox. The problem is that busybox is a single binary that provides the functionality of many binaries (init, login, coreutils, etc). I am not quite far enough to fully understand the problem, but I am pretty sure it will be a problem. I will start a different thread on this problem soon.]

Yes, it is an issue. You aren't the first to encounter it, e.g.
http://www.coker.com.au/selinux/talks/ols2003/

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.
#9 lore raw
In reply to Ryan Bradetich
Quoted 4 lines · Ryan Bradetich

2. Busybox provides the init functionality, So I am going to start evaluating and reviewing the init module and figure out what is needed to successfully allow the kernel_t domain to transition to the init_t domain and do the work init busybox init needs to do.

domain_auto_trans(kernel_t, bin_t, init_t)

Not something we want for general-purpose desktop and server machines but should be fine for embedded systems.

Quoted 6 lines

[NOTE: I will be asking the communities advice on shortly is how to handle busybox. The problem is that busybox is a single binary that provides the functionality of many binaries (init, login, coreutils, etc). I am not quite far enough to fully understand the problem, but I am pretty sure it will be a problem. I will start a different thread on this problem soon.]

My conclusion after trying some of the other options is that the best thing to do is to divide busybox into several programs for different tasks. So have one executable for programs that don't have domain transitions (ls, cp, etc) - you could include init in this as the kernel shouldn't be executing bin_t for anything else.

Then have one executable for login and getty (which will require a minor change to policy), one for klogd and syslogd (the policy option for syslog-ng should make that work), one for ifconfig and related sys-admin tools, one for ping and related privileged programs that users may run, etc.

Having 3-4 busybox executables that each have subsets of the busybox functionality should not cause a significant overhead if you are dynamically linking busybox (as is done on Familiar).

Signature · 9 lines
[email protected]
http://etbe.blogspot.com/          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.
#10 lore raw

Hello Russell,

I read through your OLS-2003 paper Stephen pointed me at. It was a very interesting read and confirmed many of the suspicions I was having about busybox while digging deeper into SELinux. I am also interested in reading the proposal Nakamura-san and the Japan SELinux User Group has for integrating SELinux into busybox at the applet level.

I believe I have a short-term solution for my busybox problem by putting the majority of the system into a common system_t domain
(users will not have access to a shell on my embedded device). My
long term goal is to see a better solution for embedded systems using SELinux and Busybox.

Thanks!

- Ryan

Quoted 34 lines · Russell Coker
Quoted 4 lines · Ryan Bradetich

2. Busybox provides the init functionality, So I am going to start evaluating and reviewing the init module and figure out what is needed to successfully allow the kernel_t domain to transition to the init_t domain and do the work init busybox init needs to do.

domain_auto_trans(kernel_t, bin_t, init_t)

Not something we want for general-purpose desktop and server machines but should be fine for embedded systems.

Quoted 6 lines

[NOTE: I will be asking the communities advice on shortly is how to handle busybox. The problem is that busybox is a single binary that provides the functionality of many binaries (init, login, coreutils, etc). I am not quite far enough to fully understand the problem, but I am pretty sure it will be a problem. I will start a different thread on this problem soon.]

My conclusion after trying some of the other options is that the best thing to do is to divide busybox into several programs for different tasks. So have one executable for programs that don't have domain transitions (ls, cp, etc) - you could include init in this as the kernel shouldn't be executing bin_t for anything else.

Then have one executable for login and getty (which will require a minor change to policy), one for klogd and syslogd (the policy option for syslog-ng should make that work), one for ifconfig and related sys-admin tools, one for ping and related privileged programs that users may run, etc.

Having 3-4 busybox executables that each have subsets of the busybox functionality should not cause a significant overhead if you are dynamically linking busybox (as is done on Familiar).

Quoted 6 lines

--
[email protected]
http://etbe.blogspot.com/ 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.

#11 lore raw

Assgin domain to busybox applet(Re: Failed write to /selinux/context in selinux_trans_to_raw_contex()

In reply to Ryan Bradetich
Quoted 6 lines · On Fri, 2 Mar 2007 08:21:03 -0800 "Ryan Bradetich" wrote:

[NOTE: I will be asking the communities advice on shortly is how to handle busybox. The problem is that busybox is a single binary that provides the functionality of many binaries (init, login, coreutils, etc). I am not quite far enough to fully understand the problem, but I am pretty sure it will be a problem. I will start a different thread on this problem soon.]

We(people in JSELUG(Japan SELinux Users Group) are extending busybox to assign domain to busybox applets. It might be useful for you.
You can obtain it from
http://code.google.com/p/sebusybox/source

By preparing wrapper program or separting executable, you can assign domain to applet,
but it is not useful.
We decided to extend busybox to support dynamic domain transition.

In this, "CONFIG_SELINUX_DYNTRANSITION" is prepared.
It is under "Support NSA Security Enhanced Linux" in menu.
By enabling this, you can assign domain to applet by dynamic domain transition.

It can assign entrypoint label to applet, by following syntax. In file_contexts file:
<path to busybox>/<name of applet> system_u:object_r:<entry point label> For example, assume following situation
* busybox executable is: /usr/bin/busybox
* applet name is httpd
* entrypoint label you want to assign is httpd_exec_t
Then you have to write following in file_contexts /usr/bin/busybox/httpd system_u:object_r:httpd_exec_t

You also need to write domain_auto_trans rule
and allow some permissions(setcontext, dyntransition) for dynamic domain transition. Sample policy is under construction, sorry..

Extended Busybox obtain
applet's entrypoint label by matchpathcon,
decides domain transition by compute_av, and set new domain by setcon.

We are using file_contexts file to label entrypoint. However, it has to use /proc/self/exe,
so before mounting /proc ,it does not work.

We are preparing another patch that does not use file_contexts and uses "busybox_contexts file" to assign entrypoint label. I hope we can announce it in near future..

Documentation is under construction,
so please ask us if you have questions.

Regards,

Signature · 9 lines
Yuichi Nakamura
Hitachi Software Engineering Co., Ltd.
SELinux Policy Editor: http://seedit.sourceforge.net/


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

Re: Assgin domain to busybox applet(Re: Failed write to /selinux/context in selinux_trans_to_raw_contex()

Hello Nakamura-san,

Quoted 6 lines · Yuichi Nakamura

On Fri, 2 Mar 2007 08:21:03 -0800
We(people in JSELUG(Japan SELinux Users Group) are extending busybox to assign domain to busybox applets. It might be useful for you.
You can obtain it from
http://code.google.com/p/sebusybox/source

Excellent! I will grab a copy of this code later this week so I can
look at it in more detail. Thanks for the link!

Quoted 27 lines

By preparing wrapper program or separting executable, you can assign domain to applet,
but it is not useful.
We decided to extend busybox to support dynamic domain transition.

In this, "CONFIG_SELINUX_DYNTRANSITION" is prepared.
It is under "Support NSA Security Enhanced Linux" in menu.
By enabling this, you can assign domain to applet by dynamic domain transition.

It can assign entrypoint label to applet, by following syntax. In file_contexts file:
<path to busybox>/<name of applet> system_u:object_r:<entry point label> For example, assume following situation
* busybox executable is: /usr/bin/busybox
* applet name is httpd
* entrypoint label you want to assign is httpd_exec_t
Then you have to write following in file_contexts /usr/bin/busybox/httpd system_u:object_r:httpd_exec_t

You also need to write domain_auto_trans rule
and allow some permissions(setcontext, dyntransition) for dynamic domain transition. Sample policy is under construction, sorry..

Extended Busybox obtain
applet's entrypoint label by matchpathcon,
decides domain transition by compute_av, and set new domain by setcon.

Quoted 7 lines

We are using file_contexts file to label entrypoint. However, it has to use /proc/self/exe,
so before mounting /proc ,it does not work.

We are preparing another patch that does not use file_contexts and uses "busybox_contexts file" to assign entrypoint label. I hope we can announce it in near future..

Sounds interesting, Looking forward to your announcement!

Quoted 2 lines

Documentation is under construction,
so please ask us if you have questions.

Will do. Thanks for the pointers to your work!

- Ryan

Quoted 7 lines

Regards,
--
Yuichi Nakamura
Hitachi Software Engineering Co., Ltd. SELinux Policy Editor: http://seedit.sourceforge.net/

Quoted 5 lines

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

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

#13 lore raw

Re: Assgin domain to busybox applet(Re: Failed write to /selinux/context in selinux_trans_to_raw_contex()

Hello.

Quoted 2 lines · Ryan Bradetich

Excellent! I will grab a copy of this code later this week so I can
look at it in more detail. Thanks for the link!

Thank you, but you have to be careful about risk.
Our code uses dynamic domain transition,
but you have to be careful, because attacker can change domain by setcon call. It may be better to combine wrapper with our code.

Regards,
Yuichi Nakamura

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

#14 lore raw
In reply to Ryan Bradetich
Quoted 5 lines · Ryan Bradetich

Ah ha. The last piece was the piece I was missing. The base-only policy has the roles defined and authorized for the specific domain/type. I also have the domain/type defined, but I do not have any transitions into it. I will test this out later tonight by adding the appropriate transition.

Why re-invent the wheel? Just use userdomain, and gradually pare it down, testing along the way.

Quoted 3 lines

Excellent. I will look into this as well. Is the login app required to run in a specific context? Or just a context that has the appropriate permissions to transfer to the domain the user is in?

There isn't any requirement for a fixed context, just that the proper type transitions and allow rules are defined. But it should be easier to re-use the existing login domain (locallogin) and user domain (userdomain) definitions as a starting point and pare them down than re-inventing them.

Quoted 7 lines
Quoted 3 lines

It didn't fail to write, but the write reported invalid argument, i.e. the context written was not valid per policy. That's the point of writing it to /selinux/context - to check its validity against policy.

Make sense. This is something I will probably dig into later ... sounds interesting and I am curious to understand exactly how it works :)

/selinux has a pseudo filesystem (selinuxfs) mounted on it, which is actually an interface for interacting with the kernel's security server / policy engine as well as setting certain parameters. Similar to other pseudo filesystems used for control functions.

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.