Skip to contentSkip to conversation

type_change rules

DISCUSSION Russell Coker 3 participants 6 messages Aug 18, 2002 – Aug 19, 2002 SELinux security module

lore
Share & tools
lore
#0 lore raw

In macros/user.te we have the following line:
type_change $1_t tty_device_t:chr_file $1_tty_device_t;

However the tty label seems to be that which matches the last usesr logged in (a security issue in itself).

However it also has the issue that when you create a new user role you must also create matching type_change rules to allow changes from all other user domains (IE the number of rules is proportional to the number of user domains squared). Is there any reason for not doing the following? type_change $1_t ttyfile:chr_file $1_tty_device_t;

Signature · 3 lines
I do not get viruses because I do not use MS software.
If you use Outlook then please do not put my email address in your
address-book so that WHEN you get a virus it won't use my address in the
Quoted 1 line

From field.

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

In macros/user.te we have the following line:
type_change $1_t tty_device_t:chr_file $1_tty_device_t;

However the tty label seems to be that which matches the last usesr logged in (a security issue in itself).

login should reset the tty label back to the original type when the user logs out. However, if login doesn't exit properly, then it will be left in the type. In this case, the tty will be correctly updated on the next login due to the type_change rules in newrole.te for dealing with the similar issue when newrole is terminated abruptly. The real fix is to have the rc scripts or getty reset the types properly.

Quoted 5 lines

However it also has the issue that when you create a new user role you must also create matching type_change rules to allow changes from all other user domains (IE the number of rules is proportional to the number of user domains squared). Is there any reason for not doing the following? type_change $1_t ttyfile:chr_file $1_tty_device_t;

Aside from the state explosion in the TE rules, no. But the better solution would be to have the rc scripts or getty reset the type properly to avoid the need for these rules.

--
Stephen D. Smalley, NAI Labs
[email protected]

--
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 10 lines · Stephen Smalley
Quoted 5 lines · Russell Coker

In macros/user.te we have the following line:
type_change $1_t tty_device_t:chr_file $1_tty_device_t;

However the tty label seems to be that which matches the last usesr logged in (a security issue in itself).

login should reset the tty label back to the original type when the user logs out. However, if login doesn't exit properly, then it will be left in the type.

In my case it appears that login exec's the user's shell and is gone from memory.

So it seems that to get this working correctly I need some changes to the login program to make it hang around (as login programs apparently do in other distributions), and I need to make sure that the SAK is blocked from killing the login process.

Quoted 4 lines

In this case, the tty will be correctly updated on the next login due to the type_change rules in newrole.te for dealing with the similar issue when newrole is terminated abruptly. The real fix is to have the rc scripts or getty reset the types properly.

rc scripts aren't involved. Doing it in init is ugly. Changing getty means changing 4 getty programs that I use on machines I run (and more getty programs for a comprehensive solution). I don't think that this is the real fix.

I could write a getty wrapper which just does fork()/exec()/wait() and then changes the specified device back to it's original SID after the wait() returns. As the wrapper would NEVER open the terminal in question it wold escape the SAK. This might be the best solution, although if there are other benefits to having /bin/login keep running then that might be the option.

Quoted 10 lines
Quoted 6 lines

However it also has the issue that when you create a new user role you must also create matching type_change rules to allow changes from all other user domains (IE the number of rules is proportional to the number of user domains squared). Is there any reason for not doing the following?
type_change $1_t ttyfile:chr_file $1_tty_device_t;

Aside from the state explosion in the TE rules, no. But the better solution would be to have the rc scripts or getty reset the type properly to avoid the need for these rules.

I think getting login to do it would be best. Or if not login then have a getty wrapper program do it.

Signature · 3 lines
I do not get viruses because I do not use MS software.
If you use Outlook then please do not put my email address in your
address-book so that WHEN you get a virus it won't use my address in the
Quoted 1 line

From field.

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

In my case it appears that login exec's the user's shell and is gone from memory.

So it seems that to get this working correctly I need some changes to the login program to make it hang around (as login programs apparently do in other distributions), and I need to make sure that the SAK is blocked from killing the login process.

If compiled with PAM support, the util-linux login forks a child process that waits for the user shell to exit and then cleans up the session (including relabeling the tty back to its original SID, with the SELinux patch).

Quoted 4 lines

rc scripts aren't involved. Doing it in init is ugly. Changing getty means changing 4 getty programs that I use on machines I run (and more getty programs for a comprehensive solution). I don't think that this is the real fix.

I think it is. Keep in mind that the same issue arises for the Linux ownership and modes on ttys, and that this must be addressed somewhere in getty or init. But I concede that it may be a lot of work to support all getty programs.

--
Stephen D. Smalley, NAI Labs
[email protected]

--
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
Quoted 9 lines · Stephen Smalley
Quoted 7 lines · Russell Coker

In my case it appears that login exec's the user's shell and is gone from memory.

So it seems that to get this working correctly I need some changes to the login program to make it hang around (as login programs apparently do in other distributions), and I need to make sure that the SAK is blocked from killing the login process.

Quoted 4 lines

If compiled with PAM support, the util-linux login forks a child process that waits for the user shell to exit and then cleans up the session (including relabeling the tty back to its original SID, with the SELinux patch).

I'll have to look into that. Debian is using the shadow utils login which is different.

Quoted 9 lines
Quoted 4 lines

rc scripts aren't involved. Doing it in init is ugly. Changing getty means changing 4 getty programs that I use on machines I run (and more getty programs for a comprehensive solution). I don't think that this is the real fix.

I think it is. Keep in mind that the same issue arises for the Linux ownership and modes on ttys, and that this must be addressed somewhere in getty or init. But I concede that it may be a lot of work to support all getty programs.

I think it's simply impractical to change all getty programs. I think that the solution is a wrapper that either:
1) Relabels the tty device based on a config file or command line parameter and then exec's the real getty.
2) Monitors the real getty and changes the SID back after that session finishes.

Option 2 was what I first thought of, but it means more processes, and there's the issue that init writes the PID to the utmp file (and code to manage utmp is a PITA to write).

I'll probably implement option 1 some time this week. I think it'll make a useful addition to selinux-small, I can imagine other uses for such a program as well.

Signature · 3 lines
I do not get viruses because I do not use MS software.
If you use Outlook then please do not put my email address in your
address-book so that WHEN you get a virus it won't use my address in the
Quoted 1 line

From field.

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

If compiled with PAM support, the util-linux login forks a child process that waits for the user shell to exit and then cleans up the session (including relabeling the tty back to its original SID, with the SELinux patch).

I'll have to look into that. Debian is using the shadow utils login which is different.

I may have missed something here, but Debian login only forks a child process to wait for the user to logout if CLOSE_SESSIONS is set to YES in /etc/login.defs.

This is required for instance if you want a kerberos PAM module to destroy the ticket when you logout.

Signature · 6 lines
Brian May <[email protected]>

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