Skip to contentSkip to conversation

macros patch

PATCH Russell Coker 1 participant 1 message Jul 12, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

The attached patch adds a new create_lnk_perms macro and makes some changes to other macros to use it.

It makes sysadm_t not have access to create policy_src_t:{ sock_file fifo_file }.

It doesn't alow userdomain to have misc_device_t:notdevfile rw_file_perms access.

For chroot macros the domains for a chroot are not supposed to have NIS access (they are separate from the main processes), and they are not user domains.

I think that allowing user_games_t any form of write access to user_tmp_t (including setattr on a directory) is a bad idea.

print_spool_t should only apply to file, not sock_file, fifo_file, or lnk_file.

Referencing staff_home_dir_t in the screen policy is a mistake. Generally any occurance of staff_home_dir_t or similar is a mistake.

I removed a couple of occurrences of can_exec_any().

user_t should not have privfd. privfd is only for domains such as local_login_t and sshd_t.

Steve, I believe that this is worthy of CVS inclusion.

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
macros/admin_macros.te renamed from usr/src/se/policy/macros/admin_macros.te +3 -2
diff -ru /usr/src/se/policy/macros/admin_macros.te ./macros/admin_macros.te
@@ -125,7 +124,8 @@
 # policy management infrastructure is in place so that an administrator
 # cannot directly manipulate policy files with arbitrary programs.
 #
-allow $1_t policy_src_t:notdevfile_class_set create_file_perms;
+allow $1_t policy_src_t:file create_file_perms;
+allow $1_t policy_src_t:lnk_file create_lnk_perms;
 allow $1_t policy_src_t:dir create_dir_perms;
 
 # Relabel all files.
@@ -133,7 +133,7 @@
 # sysadmfile to file_type (and change the assertion in assert.te that
 # only auth_write can relabel shadow_t)
 allow $1_t sysadmfile:dir { getattr read search relabelfrom relabelto };
-allow $1_t sysadmfile:file_class_set { getattr relabelfrom relabelto };
+allow $1_t sysadmfile:notdevfile_class_set { getattr relabelfrom relabelto };
 
 ifdef(`startx.te', `
 ifdef(`xserver.te', `
macros/base_user_macros.te renamed from usr/src/se/policy/macros/base_user_macros.te +1 -1
diff -ru /usr/src/se/policy/macros/base_user_macros.te ./macros/base_user_macros.te
@@ -172,7 +174,7 @@
 allow $1_t mouse_device_t:chr_file r_file_perms;
 ')
 # Access other miscellaneous devices.
-allow $1_t misc_device_t:file_class_set rw_file_perms;
+allow $1_t misc_device_t:{ chr_file blk_file } rw_file_perms;
 allow $1_t device_t:lnk_file { getattr read };
 
 #
macros/core_macros.te renamed from usr/src/se/policy/macros/core_macros.te +25 -8
diff -ru /usr/src/se/policy/macros/core_macros.te ./macros/core_macros.te
@@ -94,6 +94,11 @@
 define(`link_file_perms', `{ getattr link unlink rename }')
 
 #
+# Permissions for creating lnk_files.
+#
+define(`create_lnk_perms', `{ create read getattr setattr link unlink rename }')
+
+#
 # Permissions for creating and using files.
 # 
 define(`create_file_perms', `{ create ioctl read getattr lock write setattr append link unlink rename }')
@@ -195,37 +200,44 @@
 # 
 define(`r_dir_file', `
 allow $1 $2:dir r_dir_perms;
-allow $1 $2:{ file lnk_file } r_file_perms;
+allow $1 $2:file r_file_perms;
+allow $1 $2:lnk_file { getattr read };
 ')
 
 define(`rw_dir_file', `
 allow $1 $2:dir rw_dir_perms;
-allow $1 $2:{ file lnk_file } rw_file_perms;
+allow $1 $2:file rw_file_perms;
+allow $1 $2:lnk_file { getattr read };
 ')
 
 define(`ra_dir_file', `
 allow $1 $2:dir ra_dir_perms;
-allow $1 $2:{ file lnk_file } ra_file_perms;
+allow $1 $2:file ra_file_perms;
+allow $1 $2:lnk_file { getattr read };
 ')
 
 define(`ra_dir_create_file', `
 allow $1 $2:dir ra_dir_perms;
-allow $1 $2:{ file lnk_file } { create ra_file_perms };
+allow $1 $2:file { create ra_file_perms };
+allow $1 $2:lnk_file { create read getattr };
 ')
 
 define(`rw_dir_create_file', `
 allow $1 $2:dir rw_dir_perms;
-allow $1 $2:{ file lnk_file } create_file_perms;
+allow $1 $2:file create_file_perms;
+allow $1 $2:lnk_file create_lnk_perms;
 ')
 
 define(`create_dir_file', `
 allow $1 $2:dir create_dir_perms;
-allow $1 $2:{ file lnk_file } create_file_perms;
+allow $1 $2:file create_file_perms;
+allow $1 $2:lnk_file create_lnk_perms;
 ')
 
 define(`create_dir_notdevfile', `
 allow $1 $2:dir create_dir_perms;
-allow $1 $2:notdevfile_class_set create_file_perms;
+allow $1 $2:{ file sock_file fifo_file } create_file_perms;
+allow $1 $2:lnk_file create_lnk_perms;
 ')
 
 define(`create_append_log_file', `
@@ -441,13 +453,18 @@
 # Allow the process to create the file.
 #
 ifelse(`$4', `', `
-allow $1 $3:notdevfile_class_set create_file_perms;
+allow $1 $3:{ file sock_file fifo_file } create_file_perms;
+allow $1 $3:lnk_file create_lnk_perms;
 allow $1 $3:dir create_dir_perms;
 ', `
 ifelse(`$4', `dir', `
 allow $1 $3:$4 create_dir_perms;
 ', `
+ifelse(`$4', `lnk_file', `
+allow $1 $3:$4 create_lnk_perms;
+', `
 allow $1 $3:$4 create_file_perms;
+')dnl end ifelse lnk_file
 ')dnl end if dir
 ')dnl end if param 4 specified
 
macros/program/chroot_macros.te renamed from usr/src/se/policy/macros/program/chroot_macros.te +2 -3
diff -ru /usr/src/se/policy/macros/program/chroot_macros.te ./macros/program/chroot_macros.te
@@ -39,10 +39,10 @@
 # entry point for $2_super_t
 type $2_super_entry_t, file_type, sysadmfile, home_type, user_home_type;
 # $2_t is the base domain, has full access to $2_rw_t files
-type $2_t, domain, userdomain, unpriv_userdomain;
+type $2_t, domain;
 # $2_super_t is the super-chroot domain, can also write to $2_ro_t
 # but still can not access outside the chroot
-type $2_super_t, domain, userdomain, unpriv_userdomain;
+type $2_super_t, domain;
 allow $2_super_t chroot_tty_device:chr_file rw_file_perms;
 
 ifdef(`$1_chroot_def', `', `
@@ -119,7 +119,6 @@
 can_create_pty($2)
 can_create_pty($2_super)
 can_network({ $2_t $2_super_t })
-can_ypbind({ $2_t $2_super_t })
 allow { $2_t $2_super_t } null_device_t:chr_file rw_file_perms;
 allow $2_super_t { $2_rw_t $2_ro_t }:{ dir file } mounton;
 allow { $2_t $2_super_t } self:capability { dac_override kill };
macros/program/games_domain.te renamed from usr/src/se/policy/macros/program/games_domain.te +0 -1
diff -ru /usr/src/se/policy/macros/program/games_domain.te ./macros/program/games_domain.te
@@ -24,7 +24,6 @@
 create_dir_file($1_games_t, $1_home_t)
 
 create_dir_file($1_games_t, $1_tmp_t)
-allow $1_games_t $1_tmp_t:dir { setattr };
 allow $1_games_t $1_tmp_t:sock_file create_file_perms;
 
 dontaudit $1_games_t sysctl_t:dir search;
macros/program/lpr_macros.te renamed from usr/src/se/policy/macros/program/lpr_macros.te +1 -1
diff -ru /usr/src/se/policy/macros/program/lpr_macros.te ./macros/program/lpr_macros.te
@@ -81,7 +81,7 @@
 allow $1_lpr_t $1_home_t:{ file lnk_file } r_file_perms;  
 
 # Read and write shared files in the spool directory.
-allow $1_lpr_t print_spool_t:notdevfile_class_set rw_file_perms;
+allow $1_lpr_t print_spool_t:file rw_file_perms;
 
 # lpr can run in lightweight mode, without a local print spooler. If the
 # lpd policy is present, grant some permissions for this domain and the lpd
macros/program/mozilla_macros.te renamed from usr/src/se/policy/macros/program/mozilla_macros.te +1 -1
diff -ru /usr/src/se/policy/macros/program/mozilla_macros.te ./macros/program/mozilla_macros.te
@@ -56,7 +56,7 @@
 dontaudit $1_mozilla_t proc_t:dir read;
 
 allow $1_mozilla_t { var_t var_lib_t }:dir search;
-dontaudit $1_mozilla_t var_run_t:dir search;
+dontaudit $1_mozilla_t var_run_t:dir { getattr search };
 
 # Execute downloaded programs.
 can_exec($1_mozilla_t, $1_mozilla_rw_t)
macros/program/screen_macros.te renamed from usr/src/se/policy/macros/program/screen_macros.te +0 -1
diff -ru /usr/src/se/policy/macros/program/screen_macros.te ./macros/program/screen_macros.te
@@ -77,7 +77,6 @@
 allow $1_screen_t self:capability { setuid setgid fsetid };
 
 dontaudit $1_screen_t shadow_t:file { read };
-allow $1_screen_t staff_home_dir_t:dir { search };
 
 allow $1_screen_t tmp_t:dir { search };
 can_network($1_screen_t)
macros/program/ssh_macros.te renamed from usr/src/se/policy/macros/program/ssh_macros.te +0 -3
diff -ru /usr/src/se/policy/macros/program/ssh_macros.te ./macros/program/ssh_macros.te
@@ -100,9 +100,6 @@
 # Use capabilities.
 allow $1_ssh_t self:capability { setuid setgid dac_override dac_read_search };
 
-# Run helpers.
-can_exec_any($1_ssh_t)
-
 # Read the ssh key file.
 allow $1_ssh_t sshd_key_t:file r_file_perms;
 
macros/program/su_macros.te renamed from usr/src/se/policy/macros/program/su_macros.te +0 -1
diff -ru /usr/src/se/policy/macros/program/su_macros.te ./macros/program/su_macros.te
@@ -126,7 +121,6 @@
 allow $1_su_t { sysadm_tty_device_t sysadm_devpts_t }:chr_file { getattr ioctl };
 
 allow $1_su_t { home_root_t $1_home_dir_t }:dir search;
-create_dir_file($1_su_t, $1_home_dir_t)
 allow $1_su_t $1_home_t:file create_file_perms;
 ifdef(`user_canbe_sysadm', `
 allow $1_su_t home_dir_type:dir { search write };
macros/program/uml_macros.te renamed from usr/src/se/policy/macros/program/uml_macros.te +3 -1
diff -ru /usr/src/se/policy/macros/program/uml_macros.te ./macros/program/uml_macros.te
@@ -47,7 +47,9 @@
 ')dnl end ifelse sysadm
 ')dnl end ifdef startx
 
-allow $1_t { $1_uml_ro_t $1_uml_rw_t $1_uml_exec_t }:file_class_set { relabelfrom relabelto create_file_perms };
+allow $1_t { $1_uml_ro_t $1_uml_rw_t }:{ file sock_file fifo_file } { relabelfrom relabelto create_file_perms };
+allow $1_t $1_uml_exec_t:file { relabelfrom relabelto create_file_perms };
+allow $1_t { $1_uml_ro_t $1_uml_rw_t }:lnk_file { relabelfrom relabelto create_lnk_perms };
 allow $1_t { $1_uml_ro_t $1_uml_rw_t $1_uml_exec_t }:dir { relabelfrom relabelto create_dir_perms };
 r_dir_file($1_t, uml_ro_t)
 
macros/program/x_client_macros.te renamed from usr/src/se/policy/macros/program/x_client_macros.te +7 -2
diff -ru /usr/src/se/policy/macros/program/x_client_macros.te ./macros/program/x_client_macros.te
@@ -37,6 +37,7 @@
 
 # Transition from the user domain to the derived domain.
 domain_auto_trans($1_t, $2_exec_t, $1_$2_t)
+can_exec($1_$2_t, $2_exec_t)
 
 # The user role is authorized for this domain.
 role $1_r types $1_$2_t;
@@ -97,8 +99,12 @@
 allow $1_$2_t zero_device_t:chr_file rw_file_perms;
 allow $1_$2_t zero_device_t:chr_file x_file_perms;
 
-# Execute system programs.
-can_exec_any($1_$2_t)
+# allow using shared libraries and running programs
+uses_shlib($1_$2_t)
+allow $1_$2_t { bin_t sbin_t }:dir search;
+allow $1_$2_t bin_t:lnk_file read;
+can_exec($1_$2_t, { shell_exec_t bin_t })
+allow $1_$2_t etc_t:file { getattr read };
 
 # Inherit and use descriptors from gnome-pty-helper.
 ifdef(`gnome-pty-helper.te', `allow $1_$2_t $1_gph_t:fd use;')
macros/program/xserver_macros.te renamed from usr/src/se/policy/macros/program/xserver_macros.te +4 -1
diff -ru /usr/src/se/policy/macros/program/xserver_macros.te ./macros/program/xserver_macros.te
@@ -200,7 +200,10 @@
 allow $1_xserver_t tty_device_t:chr_file { setattr rw_file_perms };
 
 # Run helper programs in $1_xserver_t.
-can_exec_any($1_xserver_t)
+allow $1_xserver_t { bin_t sbin_t }:dir search;
+allow $1_xserver_t etc_t:file { getattr read };
+allow $1_xserver_t bin_t:lnk_file read;
+can_exec($1_xserver_t, { bin_t shell_exec_t })
 
 # Connect to xfs.
 ifdef(`xfs.te', `
macros/user_macros.te renamed from usr/src/se/policy/macros/user_macros.te +1 -1
diff -ru /usr/src/se/policy/macros/user_macros.te ./macros/user_macros.te
@@ -145,7 +145,7 @@
 define(`full_user_role', `
 
 # user_t/$1_t is an unprivileged users domain.
-type $1_t, domain, userdomain, unpriv_userdomain, web_client_domain, privfd
+type $1_t, domain, userdomain, unpriv_userdomain, web_client_domain
 ifdef(`unlimitedUsers', `,privhome, etc_writer, privmodule, privlog, privowner, admin, fs_domain, privmem, privowner, sysctl_kernel_writer, auth, auth_write')
 ;