Skip to contentSkip to conversation

essential patches

PATCH Russell Coker 3 participants 7 messages Mar 24, 2003 – Mar 25, 2003 SELinux security module

lore
Share & tools
lore
#0 lore raw

The attached patch file is essential for getting a working system based on the current CVS policy.

initrc_t needs r_dir_perms access to /dev for some startup scripts (and there is no good reason to stop it).

Any program that has access to create pty devices needs search access to /dev/pts (without such access it can't create a pty which makes no sense).

user_t needs search access to /boot and read access to the system.map files for the wchan.

Many programs in user_t request read access to sysctl_kernel_t dir and file, and for var_lib_t. We could probably survive without sysctl_kernel_t, but var_lib_t access is essential to many programs (particularly some perl scripts used for Debian package building). If we deny this then we need to add some new types for the things that should be allowed.

For random_device_t writing by a hostile user apparently does no harm according to all the best sources of information available to me. There are probably some people on this list who know more about cryptology than the people who wrote the /dev/random code for Linux. If an expert decrees that we should not allow write access then I'll accept that. As for read access, too many programs break when user_t can't access it, EG all SSL clients...

As for ifconfig, without udp_socket access it won't work when called from dhclient (dhcpc_t) and therefore denying such access breaks every DHCP system. I'm not sure why ifconfig looks for access to sysctl_net_t:dir as it doesn't seem to do anything to files under that dir. But based on my experience with that program I'm not inclined to turn things off without a really good reason. ifconfig can break any part of your network setup if it runs amok, denying it access to sysctl_net_t doesn't make any sense to me.

I've tried the current CVS policy on a few machines with different configurations and they all failed to work correctly on several counts.

This patch can be applied independantly of the other patches I've posted recently.

Signature · 4 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
domains/program/initrc.te renamed from tmp/policy/domains/program/initrc.te +4 -0
diff -ru /tmp/policy/domains/program/initrc.te ./domains/program/initrc.te
@@ -32,6 +32,9 @@
 allow initrc_t self:unix_stream_socket create_socket_perms;
 allow initrc_t self:fifo_file rw_file_perms;
 
+# allow listing the contents of /dev
+allow initrc_t device_t:dir r_dir_perms;
+
 # Read the root directory of a usbdevfs filesystem, and
 # the devices and drivers files.  Permit stating of the
 # device nodes, but nothing else.
@@ -254,3 +259,4 @@
 # Rules for the run_init_t domain.
 #
 run_program(sysadm_t, sysadm_r, init, initrc_exec_t, initrc_t)
+allow initrc_t privfd:fd use;
macros/global_macros.te renamed from tmp/policy/macros/global_macros.te +8 -0
diff -ru /tmp/policy/macros/global_macros.te ./macros/global_macros.te
@@ -531,6 +546,9 @@
 # Read and write my pty files.
 allow $1_t $1_devpts_t:chr_file { setattr rw_file_perms };
 
+# allow searching /dev/pts
+allow $1_t devpts_t:dir search;
+
 ifdef(`devfsd.te', `
 allow $1_t device_t:filesystem getattr;
 ')
@@ -605,6 +623,11 @@
 allow $1 self:msgq rw_msgq_perms;
 allow $1 self:shm  rw_shm_perms;
 
+# Use descriptors created by login, sshd, or newrole.
+allow $1 privfd:fd use;
+
+# Use descriptors created by mount (e.g. NFS).
+allow $1 mount_t:fd use;
 ')
 
 #
macros/user_macros.te renamed from tmp/policy/macros/user_macros.te +11 -1
diff -ru /tmp/policy/macros/user_macros.te ./macros/user_macros.te
@@ -78,6 +78,10 @@
 allow $1_t sshd_t:unix_stream_socket rw_stream_socket_perms;
 ')dnl end of ssh section
 
+allow $1_t boot_t:dir { getattr search };
+dontaudit $1_t boot_t:dir read;
+allow $1_t system_map_t:file { getattr read };
+
 # Type for tmpfs/shm files.
 type $1_tmpfs_t, file_type, sysadmfile, tmpfsfile;
 # Use the type when creating files in tmpfs.
@@ -286,6 +301,12 @@
 allow $1_t var_run_t:dir r_dir_perms;
 allow $1_t var_run_t:{ file lnk_file } r_file_perms;
 
+allow $1_t var_lib_t:dir r_dir_perms;
+allow $1_t var_lib_t:file r_file_perms;
+
+allow $1_t sysctl_kernel_t:dir search;
+allow $1_t sysctl_kernel_t:file { getattr read };
+
 # Read /etc.
 allow $1_t etc_t:dir r_dir_perms;
 allow $1_t etc_t:notdevfile_class_set r_file_perms;
@@ -301,7 +322,7 @@
 
 # Read and write /dev/tty and /dev/null.
 allow $1_t devtty_t:chr_file rw_file_perms;
-allow $1_t { null_device_t zero_device_t }:chr_file rw_file_perms;
+allow $1_t { null_device_t zero_device_t random_device_t }:chr_file rw_file_perms;
 
 # Do not audit write denials to /etc/ld.so.cache.
 dontaudit $1_t ld_so_cache_t:file write;
domains/program/ifconfig.te renamed from tmp/policy/domains/program/ifconfig.te +4 -2
diff -ru /tmp/policy/domains/program/ifconfig.te ./domains/program/ifconfig.te
@@ -48,8 +48,10 @@
 
 allow ifconfig_t tun_tap_device_t:chr_file { read write };
 
+allow ifconfig_t fs_t:filesystem getattr;
+
 # ifconfig attempts to create a UDP socket and search some sysctl entries.
 # Don't audit those attempts; comment out these rules if it is desired to
 # see the denials.
-dontaudit ifconfig_t sysctl_t:dir search;
-dontaudit ifconfig_t self:udp_socket create;
+allow ifconfig_t { sysctl_t sysctl_net_t }:dir search;
+allow ifconfig_t self:udp_socket create_socket_perms;
#1 lore raw

It seems that the errors you are seeing is a conflict with the concept of "Core" policy and attempting to create a policy that provides least privilege. It's very difficult to have a policy that provides only "core" services yet is usable as a general-purpose machine.

For example, the dhcpd domain was removed from the core policy, so natually, it will fail to run correctly under a least privilege policy.

By removing domains from the core policy, programs may fail to transition as you would like them to. In the case of ifconfig/dhclient, the transition no longer occurs -- but this does not imply that all permissions required by dhcpc_t should now be rolled into the policy for ifconfig.

Other comments are inlined below:

Quoted 2 lines · Russell Coker

The attached patch file is essential for getting a working system based on the current CVS policy.

This patch is NOT essential to getting a working RedHat 7.2 and 8.0 systems booting and operating in enforcing mode, but I do realize this does not encompass all possible Linux distributions. It's a difference in the startup behaviour of different systems with different "core" requirements.

Quoted 2 lines

initrc_t needs r_dir_perms access to /dev for some startup scripts (and there is no good reason to stop it).

What startup scripts on Debian require access to /dev entries? Least privilege is typically justified with the inverse of your statement, what good reason is there to add new permissions?

Quoted 2 lines

Any program that has access to create pty devices needs search access to /dev/pts (without such access it can't create a pty which makes no sense).

This makes sense, we'll add this.

Quoted 3 lines

user_t needs search access to /boot and read access to the system.map files for the wchan.

It's a matter of opinion, I would think that the system.map files contains privileged information that should be protected. Again, what programs (in core) require access? If there is a special program that requires access, why is it not in a special domain that has access rather than allowing all of user_t?

Quoted 5 lines

Many programs in user_t request read access to sysctl_kernel_t dir and file, and for var_lib_t. We could probably survive without sysctl_kernel_t, but var_lib_t access is essential to many programs (particularly some perl scripts used for Debian package building). If we deny this then we need to add some new types for the things that should be allowed.

Sorry, I'm not familiar with the Debian package manager, but if it needs special access, then yes, it should run in another new domain. The core policy cannot be all things to all people and all systems.

Quoted 6 lines

For random_device_t writing by a hostile user apparently does no harm according to all the best sources of information available to me. There are probably some people on this list who know more about cryptology than the people who wrote the /dev/random code for Linux. If an expert decrees that we should not allow write access then I'll accept that. As for read access, too many programs break when user_t can't access it, EG all SSL clients...

What programs require write access to the random device? I'm certainly no expert, but I tend not to add unjustified permissions simply because it _seems_ to do no harm. Perhaps ssl clients should be running in a more restrictive domain - don't they also require access to privileged information, such as private keys? Why run them directly in the user domain?

Quoted 7 lines

As for ifconfig, without udp_socket access it won't work when called from dhclient (dhcpc_t) and therefore denying such access breaks every DHCP system. I'm not sure why ifconfig looks for access to sysctl_net_t:dir as it doesn't seem to do anything to files under that dir. But based on my experience with that program I'm not inclined to turn things off without a really good reason. ifconfig can break any part of your network setup if it runs amok, denying it access to sysctl_net_t doesn't make any sense to me.

See my initial comments.

Quoted 2 lines

I've tried the current CVS policy on a few machines with different configurations and they all failed to work correctly on several counts.

I've tried the current CVS policy on a few machines and all boot in enforcing mode and allow limited operation (limited, since this is a core-only policy).

chris.

--
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 4 lines · Chris Vance

It seems that the errors you are seeing is a conflict with the concept of "Core" policy and attempting to create a policy that provides least privilege. It's very difficult to have a policy that provides only "core" services yet is usable as a general-purpose machine.

No, the errors I am seeing are a result of the policy being so complex that it's beyond the ability of any small group of people to fully test it, so any removal of allow rules is likely to result in some breakage before it has gone through some public testing.

Quoted 7 lines

For example, the dhcpd domain was removed from the core policy, so natually, it will fail to run correctly under a least privilege policy. By removing domains from the core policy, programs may fail to transition as you would like them to. In the case of ifconfig/dhclient, the transition no longer occurs -- but this does not imply that all permissions required by dhcpc_t should now be rolled into the policy for ifconfig.

I am aware of this. I intentionally installed the dhcpc.te file in my policy as mentioned twice in my email.

The issue is not something inherantly specific to dhcpc_t, the issue is that ifconfig lost some functionality and that dhclient was one (of potentially many) programs that rely on such functionality.

Of course you could add ifconfig_t allow rules to dhcpc.te, pump.te, etc. But it would probably be best to just add it to ifconfig.te.

Quoted 8 lines
Quoted 2 lines

user_t needs search access to /boot and read access to the system.map files for the wchan.

It's a matter of opinion, I would think that the system.map files contains privileged information that should be protected. Again, what programs (in core) require access? If there is a special program that requires access, why is it not in a special domain that has access rather than allowing all of user_t?

Why are the system.map files in a different type then? If we aren't going to allow ps to access them then the only use for them is for ksymoops, in which case we may as well leave them in boot_t.

Also in that case we don't need the Red Hat symlink to be created on boot (ksymoops knows how to find the right system.map file) and therefore we can stop giving initrc_t write access to /boot (I don't particularly like granting startup scripts access to change my boot configuration).

Quoted 10 lines
Quoted 6 lines

Many programs in user_t request read access to sysctl_kernel_t dir and file, and for var_lib_t. We could probably survive without sysctl_kernel_t, but var_lib_t access is essential to many programs (particularly some perl scripts used for Debian package building). If we deny this then we need to add some new types for the things that should be allowed.

Sorry, I'm not familiar with the Debian package manager, but if it needs special access, then yes, it should run in another new domain. The core policy cannot be all things to all people and all systems.

I have just done further testing (my initial testing was a rushed effort to try and get things going again). It seems that access to the directory is needed to gain access to a Debian specific sub-directory and I can't duplicate the situation that required file access. So I agree with you on this.

Quoted 11 lines
Quoted 7 lines

For random_device_t writing by a hostile user apparently does no harm according to all the best sources of information available to me. There are probably some people on this list who know more about cryptology than the people who wrote the /dev/random code for Linux. If an expert decrees that we should not allow write access then I'll accept that. As for read access, too many programs break when user_t can't access it, EG all SSL clients...

What programs require write access to the random device? I'm certainly no expert, but I tend not to add unjustified permissions simply because it _seems_ to do no harm.

Fair comment regarding write access. OK, I'll change it to read-only in my tree.

Quoted 4 lines

Perhaps ssl clients should be running in a more restrictive domain - don't they also require access to privileged information, such as private keys? Why run them directly in the user domain?

SSL clients don't require any special access to files or other local resources. Consider an SSL web browser, it does not require any special access to files on disk (netscape runs in a separate domain to intentionally give it LESS access to files because of it's history). But for a web browser to actually provide a benefit from SSL then it needs a source of good random numbers. I recall an attack against an early version of Netscape which didn't generate pseudo-random numbers well enough.

SSL is used for POP, IMAP, FTP, HTTP, and probably other protocols. Currently apart from Netscape/Mozilla we don't have special domains for any of the clients for those protocols.

Quoted 6 lines
Quoted 2 lines

I've tried the current CVS policy on a few machines with different configurations and they all failed to work correctly on several counts.

I've tried the current CVS policy on a few machines and all boot in enforcing mode and allow limited operation (limited, since this is a core-only policy).

My understanding is that the idea of a core policy is that it will contain the base that you add other policy modules on to. If it can't do that (IE if you have to change the core policy every time you add a new policy module) then the core is broken.

There are more useful limitations that could be put in the core which would probably be less painful:
Prevent sysadm_t from reading symlinks from untrusted users (along with a special policy for ls to allow sysadm_t to see what the links are).

Support for multiple run_init type programs to allow delegating daemon start/stop permissions for some daemons (IE the database administrator can re-start the database). I've already done more than half the work for this...

We have to keep a balance between security and usability though if we want SE Linux to become popular. My tree will continue to be usable by most people without too much pain, regardless of what is done with the NSA tree.

Signature · 10 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.
#3 lore raw
Quoted 19 lines · Russell Coker
Quoted 4 lines · Chris Vance

It seems that the errors you are seeing is a conflict with the concept of "Core" policy and attempting to create a policy that provides least privilege. It's very difficult to have a policy that provides only "core" services yet is usable as a general-purpose machine.

No, the errors I am seeing are a result of the policy being so complex that it's beyond the ability of any small group of people to fully test it, so any removal of allow rules is likely to result in some breakage before it has gone through some public testing.

Quoted 7 lines

For example, the dhcpd domain was removed from the core policy, so natually, it will fail to run correctly under a least privilege policy. By removing domains from the core policy, programs may fail to transition as you would like them to. In the case of ifconfig/dhclient, the transition no longer occurs -- but this does not imply that all permissions required by dhcpc_t should now be rolled into the policy for ifconfig.

Quoted 6 lines

I am aware of this. I intentionally installed the dhcpc.te file in my policy as mentioned twice in my email.

The issue is not something inherantly specific to dhcpc_t, the issue is that ifconfig lost some functionality and that dhclient was one (of potentially many) programs that rely on such functionality.

Sorry, this is a mistake on my part. The interaction between some of these domains is not clear, especially when it's not a configuration I typically use. Wayne has added the necessary rule back to the ifconfig domain and cleanup up netutils.te. I just committed these two changes to Sourceforge.

Quoted 13 lines
Quoted 4 lines

Perhaps ssl clients should be running in a more restrictive domain - don't they also require access to privileged information, such as private keys? Why run them directly in the user domain?

SSL clients don't require any special access to files or other local resources. Consider an SSL web browser, it does not require any special access to files on disk (netscape runs in a separate domain to intentionally give it LESS access to files because of it's history). But for a web browser to actually provide a benefit from SSL then it needs a source of good random numbers. I recall an attack against an early version of Netscape which didn't generate pseudo-random numbers well enough.

Quoted 3 lines

SSL is used for POP, IMAP, FTP, HTTP, and probably other protocols. Currently apart from Netscape/Mozilla we don't have special domains for any of the clients for those protocols.

Even without using client-side certificates, the SSL protocol normally requires a PKI. Nearly all SSL clients will maintain a list of trusted roots. Replacing or inserting a new root can severely impact the security of the SSL protocol. I would consider this to be privileged information. Sorry, private keys was just a simple example.

Quoted 5 lines

There are more useful limitations that could be put in the core which would probably be less painful:
Prevent sysadm_t from reading symlinks from untrusted users (along with a special policy for ls to allow sysadm_t to see what the links are).

Quoted 8 lines

Support for multiple run_init type programs to allow delegating daemon start/stop permissions for some daemons (IE the database administrator can re-start the database). I've already done more than half the work for this...

We have to keep a balance between security and usability though if we want SE Linux to become popular. My tree will continue to be usable by most people without too much pain, regardless of what is done with the NSA tree.

I would definitely agree that there is much work that must be done to get make the policy useful for a larger audience. I think the core policy is a step in the right direction, an unfortunate side effect is that some programs will no longer run under the core policy. Otherwise, it's impossible to secure a machine running an arbitrary set of applications with unknown interaction. The difficult problem has always been understanding what programs do and why.

Look for commits to Sourceforge later today that cleanup some additional core domains. At a minimum, these will include syslogd, klogd, crontd, logrotate. If you have the opportunity to test them on non-redhat systems, that would be great.

chris.

--
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 · Chris Vance
Quoted 3 lines

The issue is not something inherantly specific to dhcpc_t, the issue is that ifconfig lost some functionality and that dhclient was one (of potentially many) programs that rely on such functionality.

Sorry, this is a mistake on my part. The interaction between some of these domains is not clear, especially when it's not a configuration I typically use. Wayne has added the necessary rule back to the ifconfig domain and cleanup up netutils.te. I just committed these two changes to Sourceforge.

Great! Thanks for the quick response.

Quoted 18 lines
Quoted 14 lines
Quoted 4 lines

Perhaps ssl clients should be running in a more restrictive domain - don't they also require access to privileged information, such as private keys? Why run them directly in the user domain?

SSL clients don't require any special access to files or other local resources. Consider an SSL web browser, it does not require any special access to files on disk (netscape runs in a separate domain to intentionally give it LESS access to files because of it's history). But for a web browser to actually provide a benefit from SSL then it needs a source of good random numbers. I recall an attack against an early version of Netscape which didn't generate pseudo-random numbers well enough.

Quoted 3 lines

SSL is used for POP, IMAP, FTP, HTTP, and probably other protocols. Currently apart from Netscape/Mozilla we don't have special domains for any of the clients for those protocols.

Quoted 5 lines

Even without using client-side certificates, the SSL protocol normally requires a PKI. Nearly all SSL clients will maintain a list of trusted roots. Replacing or inserting a new root can severely impact the security of the SSL protocol. I would consider this to be privileged information. Sorry, private keys was just a simple example.

Root certificates are read-only data. It's OK for them to be readable as long as they are not writable. In a typical installation they will be stored somewhere under /etc or /usr where user_t will only get read access to them.

The only information that can potentially need to be restricted is when the SSL client receives a certificate from the server that is not signed (or not signed ny a known CA) and the user is prompted for whether they should continue to trust it.

However the most common SSL client is Netscape. Netscape has a separate domain to protect the rest of the system from it (not to protect it from the rest of the system) because of it's history.

Probably the best thing to do is to change the SSL client programs so that there is no facility for them to accept unsigned certificates (should be a simple compilation option).

Quoted 10 lines
Quoted 9 lines

There are more useful limitations that could be put in the core which would probably be less painful:
Prevent sysadm_t from reading symlinks from untrusted users (along with a special policy for ls to allow sysadm_t to see what the links are).

Support for multiple run_init type programs to allow delegating daemon start/stop permissions for some daemons (IE the database administrator can re-start the database). I've already done more than half the work for this...

Quoted 7 lines

I would definitely agree that there is much work that must be done to get make the policy useful for a larger audience. I think the core policy is a step in the right direction, an unfortunate side effect is that some programs will no longer run under the core policy. Otherwise, it's impossible to secure a machine running an arbitrary set of applications with unknown interaction. The difficult problem has always been understanding what programs do and why.

Yes. Part of the problem is that some programs have grown over time into monstrosities that can't be understood by humans. ifconfig is a good example. :-#

Quoted 4 lines

Look for commits to Sourceforge later today that cleanup some additional core domains. At a minimum, these will include syslogd, klogd, crontd, logrotate. If you have the opportunity to test them on non-redhat systems, that would be great.

OK. I'll have a look at it.

Signature · 10 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

usermod

Was there a reason usermod was not wrapped similar to useradd/userdel?

On a similar note, what about the gpasswd/group[add|mod|del] family? As they are all sbin_t, they do not have permission, when run by sysadm_t, to open /etc/gshadow (which is shadow_t).

Thanks,
david

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

Re: usermod

Quoted 1 line · david caplan

Was there a reason usermod was not wrapped similar to useradd/userdel?

I never use that program and it seems that the other people involved in writing the wrappers don't use it either.

Quoted 3 lines

On a similar note, what about the gpasswd/group[add|mod|del] family? As they are all sbin_t, they do not have permission, when run by sysadm_t, to open /etc/gshadow (which is shadow_t).

Once again, it's not something that apparently gets used much. Also you forgot to mention vigr which is another program in need of a wrapper.

It's been on my todo list to fix this for a while but I haven't got around to it. I'm sure that if you send Steve a patch to address this then it'll get in the next release.

Signature · 10 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.