chattr
Quoted 7 lines · Russell Coker
It seems that chattr depends on the "write" permission and that lsattr depends on the "read" permission. I think that they should depend on "setattr" and "getattr" permissions respectively.
[email protected] pointed out that it is possible to chattr /tmp on my SE play machine, "chattr +i /tmp
/var/tmp/var/tmp/*" would be rather annoying...
Sorry I made a mistake, you can't set the i attribute, but you can set the attributes suSd.
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.
--
You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 2 lines · Russell Coker
Sorry I made a mistake, you can't set the i attribute, but you can set the attributes suSd.
True, as long as you have setattr permission to the type (at least, with ext2 and ext3). So I think that the real issue is that 'setattr' permission is unnecessarily included in the rw_file_perms and rw_dir_perms macros. For better control, we should probably remove it from these macros and selectively grant it as needed. It would still remain in the create_file_perms and create_dir_perms macros.
--
Stephen D. Smalley, NAI Labs
[email protected]
--
You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 6 lines · Stephen Smalley
True, as long as you have setattr permission to the type (at least, with ext2 and ext3). So I think that the real issue is that 'setattr' permission is unnecessarily included in the
rw_file_permsandrw_dir_permsmacros. For better control, we should probably remove it from these macros and selectively grant it as needed. It would still remain in thecreate_file_permsandcreate_dir_permsmacros.
The attached patch (also committed to the sourceforge CVS tree) removes setattr permission from the rw_file_perms and rw_dir_perms macros and adds it explicitly to a number of allow rules where it is needed. It is likely that you will encounter plenty of other cases where setattr permission must also be granted.
Also, as a side note, just to clarify, the SELinux setattr permission is checked for any inode setattr operation (e.g. truncate, utimes, chmod, chown) as well as for certain ioctls (e.g. flags set by chattr). We could define a separate permission for each of these operations, but SELinux itself does not require such a distinction. In contrast, when setting the SID of a file, SELinux uses a separate set of permissions (relabelfrom and relabelto) and provides finer-grained control, since the SID is relevant to the SELinux access controls.
--
Stephen D. Smalley, NAI Labs
[email protected]
Index: policy/domains/misc/kernel.te
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux/policy/domains/misc/kernel.te,v retrieving revision 1.1.1.1
domains/misc/kernel.te +1 -1
@@ -43,7 +43,7 @@ allow kernel_t file_t:dir mounton; allow kernel_t file_t:dir rw_dir_perms; allow kernel_t file_t:blk_file create_file_perms; -allow kernel_t { sysctl_t sysctl_kernel_t }:file rw_file_perms; +allow kernel_t { sysctl_t sysctl_kernel_t }:file { setattr rw_file_perms }; # Lookup the policy. allow kernel_t policy_config_t:dir r_dir_perms;
Index: policy/domains/program/crond.te
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux/policy/domains/program/crond.te,v retrieving revision 1.3
domains/program/crond.te +2 -2
@@ -163,7 +163,7 @@ allow system_crond_t cron_spool_t:file r_file_perms; # Write to /var/lib/slocate.db. -allow system_crond_t var_lib_t:dir rw_dir_perms; +allow system_crond_t var_lib_t:dir { setattr rw_dir_perms }; allow system_crond_t var_lib_t:file create_file_perms; # Update whatis files.
@@ -203,7 +203,7 @@ `allow sysadm_mail_t system_crond_tmp_t:file ra_file_perms;') # Used for /sbin/tmpwatch -allow system_crond_t tmpfile:dir rw_dir_perms; +allow system_crond_t tmpfile:dir { setattr rw_dir_perms }; allow system_crond_t tmpfile:dir rmdir; allow system_crond_t tmpfile:notdevfile_class_set link_file_perms; allow system_crond_t catman_t:dir rw_dir_perms;
Index: policy/domains/program/getty.te
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux/policy/domains/program/getty.te,v retrieving revision 1.1.1.4
domains/program/getty.te +3 -3
@@ -37,9 +37,9 @@ # Write to /var/log/wtmp. allow getty_t wtmp_t:file rw_file_perms; -# Read and write ttys. -allow getty_t tty_device_t:chr_file rw_file_perms; -allow getty_t ttyfile:chr_file rw_file_perms; +# Chown, chmod, read and write ttys. +allow getty_t tty_device_t:chr_file { setattr rw_file_perms }; +allow getty_t ttyfile:chr_file { setattr rw_file_perms }; rw_dir_create_file(getty_t, var_lock_t)
Index: policy/domains/program/initrc.te
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux/policy/domains/program/initrc.te,v retrieving revision 1.1.1.3
domains/program/initrc.te +4 -4
@@ -78,7 +78,7 @@ allow initrc_t ld_so_cache_t:file rw_file_perms; # Update /etc/mail. -allow initrc_t etc_mail_t:file rw_file_perms; +allow initrc_t etc_mail_t:file { setattr rw_file_perms }; ifdef(`xfs.te', `# Unlink the xfs socket.
@@ -87,9 +87,9 @@ allow initrc_t xfs_tmp_t:sock_file { read getattr access unlink };') # Update /var/log/wtmp and /var/log/dmesg. -allow initrc_t wtmp_t:file rw_file_perms; -allow initrc_t var_log_t:file rw_file_perms; -allow initrc_t lastlog_t:file rw_file_perms; +allow initrc_t wtmp_t:file { setattr rw_file_perms }; +allow initrc_t var_log_t:file { setattr rw_file_perms }; +allow initrc_t lastlog_t:file { setattr rw_file_perms }; # Access /var/lib/random-seed. allow initrc_t var_lib_t:file rw_file_perms;
Index: policy/domains/program/login.te
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux/policy/domains/program/login.te,v retrieving revision 1.3
domains/program/login.te +3 -3
@@ -75,8 +75,8 @@ allow local_login_t security_t:security change_sid; # Read and write ttys. -allow local_login_t tty_device_t:chr_file rw_file_perms; -allow local_login_t ttyfile:chr_file rw_file_perms; +allow local_login_t tty_device_t:chr_file { setattr rw_file_perms }; +allow local_login_t ttyfile:chr_file { setattr rw_file_perms }; # Relabel ttys. allow local_login_t tty_device_t:chr_file { getattr relabelfrom relabelto };
@@ -120,7 +120,7 @@ # Use the pty created by rlogind. ifdef(`rlogind.te', -`allow remote_login_t rlogind_devpts_t:chr_file rw_file_perms;') +`allow remote_login_t rlogind_devpts_t:chr_file { setattr rw_file_perms };') # Write to /var/run/utmp. allow remote_login_t initrc_var_run_t:file rw_file_perms;
Index: policy/domains/program/modutil.te
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux/policy/domains/program/modutil.te,v retrieving revision 1.1.1.3
domains/program/modutil.te +1 -2
@@ -49,8 +49,7 @@ allow depmod_t sysadm_home_t:file r_file_perms; # Rules for /proc/sys/kernel/tainted -allow insmod_t sysctl_kernel_t:file rw_file_perms; -allow insmod_t sysctl_t:file write; +allow insmod_t sysctl_kernel_t:file { setattr rw_file_perms }; # /var/log/ksymoops/* allow insmod_t var_log_ksyms_t:file create_file_perms;
Index: policy/domains/program/sendmail.te
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux/policy/domains/program/sendmail.te,v retrieving revision 1.3
domains/program/sendmail.te +1 -1
@@ -38,7 +38,7 @@ allow sendmail_t smtp_port_t:tcp_socket name_bind; # Write to /etc/aliases and /etc/mail. -allow sendmail_t etc_aliases_t:file rw_file_perms; +allow sendmail_t etc_aliases_t:file { setattr rw_file_perms }; allow sendmail_t etc_mail_t:dir rw_dir_perms; allow sendmail_t etc_mail_t:file create_file_perms;
Index: policy/domains/program/sshd.te
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux/policy/domains/program/sshd.te,v retrieving revision 1.3
domains/program/sshd.te +6 -7
@@ -76,10 +76,9 @@ # Obtain the SID to use for relabeling ptys allow sshd_t security_t:security change_sid; -# Relabel ptys created by sshd -allow sshd_t sshd_devpts_t:chr_file { getattr relabelfrom relabelto }; -allow sshd_t ptyfile:chr_file { getattr relabelfrom relabelto }; -allow sshd_t ptyfile:chr_file rw_file_perms; +# Relabel and access ptys created by sshd +allow sshd_t sshd_devpts_t:chr_file { setattr relabelfrom rw_file_perms }; +allow sshd_t user_devpts_t:chr_file { setattr relabelto rw_file_perms }; ################################# #
@@ -106,8 +105,8 @@ #allow sshd_login_t sysadm_home_t:file r_file_perms; # Use the pty created by sshd -allow sshd_login_t sshd_devpts_t:chr_file rw_file_perms; -allow sshd_login_t ptyfile:chr_file rw_file_perms; +allow sshd_login_t sshd_devpts_t:chr_file { setattr rw_file_perms }; +allow sshd_login_t user_devpts_t:chr_file { setattr rw_file_perms }; # Write to /var/run/utmp allow sshd_login_t initrc_var_run_t:file rw_file_perms;
@@ -123,7 +122,7 @@ # Relabel ptys created by sshd allow sshd_login_t sshd_devpts_t:chr_file { relabelfrom relabelto }; -allow sshd_login_t ptyfile:chr_file { getattr relabelfrom relabelto }; +allow sshd_login_t user_devpts_t:chr_file { getattr relabelfrom relabelto }; # Obtain the SID for the user allow sshd_t security_t:security get_user_sids;
Index: policy/macros/global_macros.te
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux/policy/macros/global_macros.te,v retrieving revision 1.5
macros/global_macros.te +13 -13
@@ -79,7 +79,7 @@ # # Permissions for reading and writing files and their attributes. # -define(`rw_file_perms', `{ ioctl read getattr access lock poll write setattr append }') +define(`rw_file_perms', `{ ioctl read getattr access lock poll write append }') # # Permissions for reading and appending to files.
@@ -104,12 +104,12 @@ # # Permissions for reading and writing directories and their attributes. # -define(`rw_dir_perms', `{ read getattr access lock poll setattr search add_name remove_name write }') +define(`rw_dir_perms', `{ read getattr access lock poll search add_name remove_name write }') # # Permissions for reading and adding names to directories. # -define(`ra_dir_perms', `{ read getattr access lock poll setattr search add_name write }') +define(`ra_dir_perms', `{ read getattr access lock poll search add_name write }') #
@@ -467,20 +467,20 @@ # define(`can_sysctl',` allow $1 sysctl_t:dir r_dir_perms; -allow $1 sysctl_t:file rw_file_perms; +allow $1 sysctl_t:file { setattr rw_file_perms }; allow $1 sysctl_fs_t:dir r_dir_perms; -allow $1 sysctl_fs_t:file rw_file_perms; +allow $1 sysctl_fs_t:file { setattr rw_file_perms }; allow $1 sysctl_kernel_t:dir r_dir_perms; -allow $1 sysctl_kernel_t:file rw_file_perms; +allow $1 sysctl_kernel_t:file { setattr rw_file_perms }; allow $1 sysctl_net_t:dir r_dir_perms; -allow $1 sysctl_net_t:file rw_file_perms; +allow $1 sysctl_net_t:file { setattr rw_file_perms }; allow $1 sysctl_net_unix_t:dir r_dir_perms; -allow $1 sysctl_net_unix_t:file rw_file_perms; +allow $1 sysctl_net_unix_t:file { setattr rw_file_perms }; allow $1 sysctl_vm_t:dir r_dir_perms; -allow $1 sysctl_vm_t:file rw_file_perms; +allow $1 sysctl_vm_t:file { setattr rw_file_perms }; allow $1 sysctl_dev_t:dir r_dir_perms; -allow $1 sysctl_dev_t:file rw_file_perms; -allow $1 sysctl_modprobe_t:file rw_file_perms; +allow $1 sysctl_dev_t:file { setattr rw_file_perms }; +allow $1 sysctl_modprobe_t:file { setattr rw_file_perms }; ')
@@ -504,7 +504,7 @@ type_transition $1_t devpts_t:chr_file $1_devpts_t; # Read and write my pty files. -allow $1_t $1_devpts_t:chr_file rw_file_perms; +allow $1_t $1_devpts_t:chr_file { setattr rw_file_perms }; ')
@@ -523,7 +523,7 @@ type_transition $1_t devpts_t:chr_file $2_devpts_t; # Read and write pty files. -allow $1_t $2_devpts_t:chr_file rw_file_perms; +allow $1_t $2_devpts_t:chr_file { setattr rw_file_perms }; ')
Index: policy/macros/program/xserver_macros.te
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux/policy/macros/program/xserver_macros.te,v retrieving revision 1.1.1.2
macros/program/xserver_macros.te +3 -3
@@ -79,13 +79,13 @@ allow $1_xserver_t proc_t:file rw_file_perms; # Create and access /dev/dri devices. -allow $1_xserver_t dri_device_t:dir rw_dir_perms; +allow $1_xserver_t dri_device_t:dir { setattr rw_dir_perms }; allow $1_xserver_t dri_device_t:chr_file create_file_perms; # Access ttys. ifelse($1, xdm, , ` -allow $1_xserver_t $1_tty_device_t:chr_file rw_file_perms;') -allow $1_xserver_t tty_device_t:chr_file rw_file_perms; +allow $1_xserver_t $1_tty_device_t:chr_file {setattr rw_file_perms};') +allow $1_xserver_t tty_device_t:chr_file {setattr rw_file_perms}; # Get network interface configuration. allow $1_xserver_t kernel_t:system { net_io_control };
Quoted 7 lines · Stephen Smalley
Quoted 6 lines
True, as long as you have setattr permission to the type (at least, with ext2 and ext3). So I think that the real issue is that 'setattr' permission is unnecessarily included in the
rw_file_permsandrw_dir_permsmacros. For better control, we should probably remove it from these macros and selectively grant it as needed. It would still remain in thecreate_file_permsandcreate_dir_permsmacros.
Quoted 5 lines
The attached patch (also committed to the sourceforge CVS tree) removes setattr permission from the
rw_file_permsandrw_dir_permsmacros and adds it explicitly to a number of allow rules where it is needed. It is likely that you will encounter plenty of other cases where setattr permission must also be granted.
# Write to /var/lib/slocate.db.
-allow system_crond_t var_lib_t:dir rw_dir_perms; +allow system_crond_t var_lib_t:dir { setattr rw_dir_perms };
Does writing to slocate.db really require setattr access?
# Used for /sbin/tmpwatch
-allow system_crond_t tmpfile:dir rw_dir_perms;
+allow system_crond_t tmpfile:dir { setattr rw_dir_perms };
allow system_crond_t tmpfile:dir rmdir;
allow system_crond_t tmpfile:notdevfile_class_set link_file_perms; allow system_crond_t catman_t:dir rw_dir_perms;
What is /sbin/tmpwatch? Is this a program that periodically removes old files from /tmp? If so then it probably doesn't need setattr access, and should be run in my tmpreaper_t domain.
# Update /etc/mail.
-allow initrc_t etc_mail_t:file rw_file_perms; +allow initrc_t etc_mail_t:file { setattr rw_file_perms };
I changed the above to the following in my tree:
ifdef(sendmail.te',
# Update /etc/mail.
allow initrc_t etc_mail_t:file { setattr rw_file_perms }; ')
Currently postfix.te depends on sendmail.te, but not for long. This /etc/mail is a sendmail specific thing apparently not used by other mail servers.
Also giving initrc access to that directory/file is a bad idea anyway, the sendmail start script in question should be run in the sendmail_t domain IMHO (as I have done for devfsd in Debian).
# Rules for /proc/sys/kernel/tainted
-allow insmod_t sysctl_kernel_t:file rw_file_perms; -allow insmod_t sysctl_t:file write;
+allow insmod_t sysctl_kernel_t:file { setattr rw_file_perms };
Is this really what you desire, removing the sysctl_t access? I'm sure it was added for a reason...
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.
--
You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 3 lines · Russell Coker
Also giving initrc access to that directory/file is a bad idea anyway, the sendmail start script in question should be run in the
sendmail_tdomain IMHO (as I have done for devfsd in Debian).
I'd disagree. As a general principle, you want to limit a domain to executing as small a set of types as possible, preferably just to its own executable and the necessary shared libraries.
Quoted 7 lines
# Rules for
/proc/sys/kernel/tainteddomains/program/modutil.te +1
-2-allow insmod_t sysctl_kernel_t:file rw_file_perms; -allow insmod_t sysctl_t:file write; +allow insmod_t sysctl_kernel_t:file { setattr rw_file_perms };Is this really what you desire, removing the
sysctl_taccess? I'm sure it was added for a reason...
Yes. I think it was originally added as a workaround for out-of-date sysctl SID tables in the SELinux module. It should no longer be needed for updating tainted.
--
Stephen D. Smalley, NAI Labs
[email protected]
--
You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.