Skip to contentSkip to conversation

patch: stricter /tmp handling

PATCH Thomas Bleher 2 participants 2 messages Dec 9, 2004 – Dec 10, 2004 SELinux security module

lore
Share & tools
lore
#0 lore raw

This patches uses my latest changes to file_type_auto_trans() to make /tmp more strict.
Right now, any process with tmp_domain() can create any file type under /tmp except chr_file and blk_file. But most domains only need file and dir.
This patch changes tmp_domain() so that normally, only file and dir access is allowed. It also adds a third parameter to the macro, so domains which need more access can get it.
I have run this patch for a few weeks on all my machines so most things should work, but I don't have any server machines running SELinux ATM, so some daemons probably need additional permissions.
This patch also removes the tmpfile attribute from tetex_data_t, since these are not really tmpfiles.

Thomas

Signature · 2 lines
http://www.cip.ifi.lmu.de/~bleher/selinux/ - my SELinux pages
GPG-Fingerprint: BC4F BB16 30D6 F253 E3EA  D09E C562 2BAE B2F4 ABE7
domains/program/ssh.te +1 -1
diff -urN orig/domains/program/ssh.te mod/domains/program/ssh.te
@@ -203,7 +203,7 @@
 # so a tunnel can point to another ssh tunnel...
 can_tcp_connect(sshd_t, sshd_t)
 
-tmp_domain(sshd)
+tmp_domain(sshd, `', { dir file sock_file })
 ifdef(`pam.te', `
 can_exec(sshd_t, pam_exec_t)
 ')
domains/program/unused/kudzu.te +1 -2
diff -urN orig/domains/program/unused/kudzu.te mod/domains/program/unused/kudzu.te
@@ -84,8 +84,7 @@
 allow kudzu_t sysfs_t:lnk_file read;
 file_type_auto_trans(kudzu_t, etc_t, etc_runtime_t, file)
 allow kudzu_t tape_device_t:chr_file r_file_perms;
-tmp_domain(kudzu)
-file_type_auto_trans(kudzu_t, tmp_t, kudzu_tmp_t, chr_file)
+tmp_domain(kudzu, `', `{ file dir chr_file }')
 
 # for file systems that are not yet mounted
 dontaudit kudzu_t file_t:dir search;
domains/program/unused/postgresql.te +1 -1
diff -urN orig/domains/program/unused/postgresql.te mod/domains/program/unused/postgresql.te
@@ -48,7 +48,7 @@
 system_crond_entry(postgresql_exec_t, postgresql_t)
 ')
 
-tmp_domain(postgresql);
+tmp_domain(postgresql, `', `{ dir file sock_file }')
 file_type_auto_trans(postgresql_t, tmpfs_t, postgresql_tmp_t)
 
 # Use the network.
domains/program/unused/xdm.te +1 -1
diff -urN orig/domains/program/unused/xdm.te mod/domains/program/unused/xdm.te
@@ -31,7 +31,7 @@
 file_type_auto_trans(xdm_t, var_run_t, xdm_var_run_t, fifo_file)
 file_type_auto_trans(xdm_t, var_run_t, xdm_var_run_t, dir)
 
-tmp_domain(xdm)
+tmp_domain(xdm, `', `{ file dir sock_file }')
 var_lib_domain(xdm)
 # NB we do NOT allow xdm_xserver_t xdm_var_lib_t:dir, only access to an open
 # handle of a file inside the dir!!!
domains/program/unused/xfs.te +1 -1
diff -urN orig/domains/program/unused/xfs.te mod/domains/program/unused/xfs.te
@@ -20,7 +20,7 @@
 allow xfs_t tmp_t:dir search;
 file_type_auto_trans(xfs_t, initrc_tmp_t, xfs_tmp_t, sock_file)
 ', `
-tmp_domain(xfs)
+tmp_domain(xfs, `', sock_file)
 ')
 
 allow xfs_t { etc_t etc_runtime_t }:file { getattr read };
domains/program/unused/zebra.te +1 -2
diff -urN orig/domains/program/unused/zebra.te mod/domains/program/unused/zebra.te
@@ -20,8 +20,7 @@
 logdir_domain(zebra)
 
 # /tmp/.bgpd is such a bad idea!
-type zebra_tmp_t, file_type, sysadmfile, tmpfile;
-file_type_auto_trans(zebra_t, tmp_t, zebra_tmp_t, sock_file)
+tmp_domain(zebra, `', sock_file)
 
 allow zebra_t self:unix_dgram_socket create_socket_perms;
 allow zebra_t self:unix_stream_socket { connectto create_stream_socket_perms };
macros/admin_macros.te +1 -1
diff -urN orig/macros/admin_macros.te mod/macros/admin_macros.te
@@ -22,7 +22,7 @@
 # Type and access for pty devices.
 can_create_pty($1)
 
-tmp_domain($1)
+tmp_domain($1, `, $1_file_type', `{ file dir lnk_file sock_file fifo_file }')
 
 # Type for tty devices.
 type $1_tty_device_t, sysadmfile, ttyfile, dev_fs;
macros/global_macros.te +6 -2
diff -urN orig/macros/global_macros.te mod/macros/global_macros.te
@@ -396,10 +396,14 @@
 allow $2_t device_t:dir getattr;
 ')
 
-
+# grant access to /tmp
+# by default, only plain files and dirs may be stored there.
+# This can be overridden with a third parameter
 define(`tmp_domain', `
 type $1_tmp_t, file_type, sysadmfile, tmpfile $2;
-file_type_auto_trans($1_t, tmp_t, $1_tmp_t)
+ifelse($3, `',
+`file_type_auto_trans($1_t, tmp_t, $1_tmp_t, `{ file dir }')',
+`file_type_auto_trans($1_t, tmp_t, $1_tmp_t, `$3')')
 ')
 
 define(`tmpfs_domain', `
macros/program/gpg_agent_macros.te +1 -1
diff -urN orig/macros/program/gpg_agent_macros.te mod/macros/program/gpg_agent_macros.te
@@ -56,7 +56,7 @@
 allow $1_gpg_agent_t self:fifo_file { getattr read write };
 
 # create /tmp files
-tmp_domain($1_gpg_agent)
+tmp_domain($1_gpg_agent, `', `{ file dir sock_file }')
 
 # gpg connect
 allow $1_gpg_t $1_gpg_agent_tmp_t:dir search;
macros/program/screen_macros.te +1 -1
diff -urN orig/macros/program/screen_macros.te mod/macros/program/screen_macros.te
@@ -27,7 +27,7 @@
 # Transition from the user domain to this domain.
 domain_auto_trans($1_t, screen_exec_t, $1_screen_t)
 
-tmp_domain($1_screen)
+tmp_domain($1_screen, `', `{ dir file fifo_file }')
 base_file_read_access($1_screen_t)
 # The user role is authorized for this domain.
 role $1_r types $1_screen_t;
macros/program/xserver_macros.te +1 -1
diff -urN orig/macros/program/xserver_macros.te mod/macros/program/xserver_macros.te
@@ -138,7 +138,7 @@
 allow $1_xserver_t zero_device_t:chr_file { read write execute };
 
 # Type for temporary files.
-tmp_domain($1_xserver)
+tmp_domain($1_xserver, `', `{ dir file sock_file }')
 file_type_auto_trans($1_xserver_t, xdm_xserver_tmp_t, $1_xserver_tmp_t, sock_file)
 
 ifelse($1, xdm, `
macros/user_macros.te +1 -1
diff -urN orig/macros/user_macros.te mod/macros/user_macros.te
@@ -21,7 +21,7 @@
 type $1_home_dir_t, file_type, sysadmfile, home_dir_type, home_type, user_home_dir_type;
 type $1_home_t, file_type, sysadmfile, home_type, user_home_type, $1_file_type;
 
-tmp_domain($1, `, user_tmpfile, $1_file_type')
+tmp_domain($1, `, user_tmpfile, $1_file_type', `{ file lnk_file dir sock_file fifo_file }')
 
 # Type and access for pty devices.
 can_create_pty($1, `, userpty_type, user_tty_type')
types/file.te +1 -1
diff -urN orig/types/file.te mod/types/file.te
@@ -178,7 +178,7 @@
 type var_lock_t, file_type, sysadmfile, lockfile;
 type var_lib_t, file_type, sysadmfile;
 # for /var/{spool,lib}/texmf index files
-type tetex_data_t, file_type, sysadmfile, tmpfile;
+type tetex_data_t, file_type, sysadmfile;
 type var_spool_t, file_type, sysadmfile;
 type var_yp_t, file_type, sysadmfile;
 
#1 lore raw

Merged.

I had to make a change to the xfs part. It needed to be tmp_domain(xfs, ', {dir sock_file}') for /tmp/.font-unix

Quoted 15 lines · Thomas Bleher

This patches uses my latest changes to file_type_auto_trans() to make /tmp more strict.
Right now, any process with tmp_domain() can create any file type under /tmp except chr_file and blk_file. But most domains only need file and dir.
This patch changes tmp_domain() so that normally, only file and dir access is allowed. It also adds a third parameter to the macro, so domains which need more access can get it.
I have run this patch for a few weeks on all my machines so most things should work, but I don't have any server machines running SELinux ATM, so some daemons probably need additional permissions.
This patch also removes the tmpfile attribute from tetex_data_t, since these are not really tmpfiles.

Thomas

Signature · 7 lines
James Carter <[email protected]>
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.