Skip to contentSkip to conversation

refpoliy additions: amavis, clamd

DISCUSSION Erich Schubert 2 participants 2 messages Feb 25, 2006 – Mar 7, 2006 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hi,
attached are first versions of policies for amavis and clamd, along with a slightly updated tor policy (which needs tor ports defined in corenetwork!)

Looks like I might actually be arriving at a point where I can switch into enforcing mode... ;-)

There are some issues remaining, though. :-(
First of all:
drwx------ root root root:object_r:user_home_dir_t:s0 /root
How do I fix genhomedircon? :-(
Secondly:
I can't get ssh_sysadm_login=1 working properly?
(might be related)

best regards,
Erich Schubert

Signature · 3 lines
    erich@(vitavonni.de|debian.org)    --    GPG Key ID: 4B3A135C    (o_
      Which is worse: ignorance or apathy? Who knows? Who cares?     //\
  Wie kann ich wissen, was ich denke, bevor ich höre, was ich sage.  V_/_
# amavis executable will have:
# label: system_u:object_r:amavis_exec_t
# MLS sensitivity: s0
# MCS categories: <none>

/usr/sbin/amavisd.* -- gen_context(system_u:object_r:amavis_exec_t,s0)
/etc/amavisd(/.*)? -- gen_context(system_u:object_r:amavis_etc_t,s0)
/var/run/amavis(/.*)? gen_context(system_u:object_r:amavis_var_run_t,s0)
/var/lib/amavis(/.*)? gen_context(system_u:object_r:amavis_var_lib_t,s0)

# less common:
/etc/amavis\.conf		--	gen_context(system_u:object_r:amavis_etc_t,s0)
/var/log/amavisd\.log		--	gen_context(system_u:object_r:amavis_var_log_t,s0)
/var/amavis(/.*)?			gen_context(system_u:object_r:amavis_var_lib_t,s0)
/var/virusmails(/.*)?			gen_context(system_u:object_r:amavis_quarantine_t,s0)

## <summary>policy for amavis</summary>

########################################
## <summary>
## Execute a domain transition to run amavis.
## </summary>
## <param name="domain">
## Domain allowed to transition.
## </param>
#
interface(amavis_domtrans',

	gen_require(`
		type amavis_t, amavis_exec_t;
	')

	domain_auto_trans($1,amavis_exec_t,amavis_t)

	allow $1 amavis_t:fd use;
	allow amavis_t $1:fd use;
	allow amavis_t:$1:fifo_file rw_file_perms;
	allow amavis_t $1:process sigchld;

')

policy_module(amavis,0.1.0)

gen_tunable(remote_amavis,false)

########################################
#
# Declarations
#

type amavis_t;
type amavis_exec_t;
domain_type(amavis_t)
init_daemon_domain(amavis_t, amavis_exec_t)

# configuration files
type amavis_etc_t;
files_type(amavis_etc_t)
# pid files
type amavis_var_run_t;
files_pid_file(amavis_var_run_t)
# var/lib files
type amavis_var_lib_t;
files_type(amavis_var_lib_t)
# log files
type amavis_var_log_t;
logging_log_file(amavis_var_log_t)
# tmp files
type amavis_tmp_t;
files_tmp_file(amavis_tmp_t)
# virus quarantine
type amavis_quarantine_t;
files_type(amavis_quarantine_t)

########################################
#

# amavis local policy
#
# Check in /etc/selinux/refpolicy/include for macros to use instead of allow rules.

# Some common macros (you might be able to remove some) files_read_etc_files(amavis_t) files_read_etc_runtime_files(amavis_t) files_read_usr_files(amavis_t)
libs_use_ld_so(amavis_t)
libs_use_shared_libs(amavis_t) miscfiles_read_localization(amavis_t)
## internal communication is often done using fifo and unix sockets. allow amavis_t self:fifo_file rw_file_perms;
allow amavis_t self:unix_stream_socket create_stream_socket_perms; allow amavis_t self:unix_dgram_socket create_socket_perms; allow amavis_t self:process { signal sigchld signull }; allow amavis_t self:capability { chown dac_override setgid setuid }; dontaudit amavis_t self:capability sys_tty_config;

# amavis tries to access /proc/self/stat, /etc/shadow and /root - perl...
kernel_dontaudit_list_proc(amavis_t)
auth_dontaudit_read_shadow(amavis_t)
userdom_dontaudit_search_sysadm_home_dirs(amavis_t)
# find perl
corecmd_exec_bin(amavis_t)
corecmd_search_sbin(amavis_t)
# configuration files
allow amavis_t amavis_etc_t:dir r_dir_perms;
allow amavis_t amavis_etc_t:file r_file_perms;
allow amavis_t amavis_etc_t:lnk_file { getattr read };
mta_read_config(amavis_t)
# pid file
allow amavis_t amavis_var_run_t:file manage_file_perms;
allow amavis_t amavis_var_run_t:sock_file manage_file_perms;
allow amavis_t amavis_var_run_t:dir rw_dir_perms;
files_pid_filetrans(amavis_t,amavis_var_run_t, { file sock_file })
# var/lib files for amavis
allow amavis_t amavis_var_lib_t:file create_file_perms;
allow amavis_t amavis_var_lib_t:sock_file create_file_perms;
allow amavis_t amavis_var_lib_t:dir create_dir_perms;
files_var_filetrans(amavis_t,amavis_var_lib_t,{ file dir sock_file })
files_var_lib_filetrans(amavis_t,amavis_var_lib_t)
# log files
allow amavis_t amavis_var_log_t:file create_file_perms;
allow amavis_t amavis_var_log_t:sock_file create_file_perms;
allow amavis_t amavis_var_log_t:dir { rw_dir_perms setattr };
logging_log_filetrans(amavis_t,amavis_var_log_t,{ sock_file file dir })
# or use syslog
logging_send_syslog_msg(amavis_t)
# tmp files
allow amavis_t amavis_tmp_t:file create_file_perms;
allow amavis_t amavis_tmp_t:dir { rw_dir_perms setattr };
files_tmp_filetrans(amavis_t,amavis_tmp_t)
# mail quarantine
allow amavis_t amavis_quarantine_t:file create_file_perms;
allow amavis_t amavis_quarantine_t:sock_file create_file_perms;
allow amavis_t amavis_quarantine_t:dir create_dir_perms;

## Networking basics (adjust to your needs!)
sysnet_dns_name_resolve(amavis_t)
corenet_non_ipsec_sendrecv(amavis_t)

# this doesn't work yet:
# corenet_tcp_sendrecv_lo_if(amavis_t)
corenet_tcp_sendrecv_all_if(amavis_t)

corenet_tcp_sendrecv_link_local_node(amavis_t)
corenet_tcp_sendrecv_site_local_node(amavis_t)

# amavis accessible from outside
tunable_policy(`remote_amavis',`
	corenet_tcp_sendrecv_all_if(amavis_t)
	corenet_tcp_sendrecv_all_nodes(amavis_t)
')
# amavis uses well-defined ports
corenet_tcp_sendrecv_amavisd_recv_port(amavis_t)
corenet_tcp_sendrecv_amavisd_send_port(amavis_t)
# just the other side not. ;-)
corenet_tcp_sendrecv_all_ports(amavis_t)
# connect to backchannel port
corenet_tcp_connect_amavisd_send_port(amavis_t)
# bind to incoming port
corenet_tcp_bind_amavisd_recv_port(amavis_t)
allow amavis_t self:tcp_socket { listen accept };

# Init script handling
init_use_fd(amavis_t)
init_use_script_ptys(amavis_t)
domain_use_interactive_fds(amavis_t)
allow initrc_t amavis_var_lib_t:dir search;
allow initrc_t amavis_var_run_t:file setattr;

# Cron handling
cron_use_fd(amavis_t)
cron_use_system_job_fds(amavis_t)
cron_rw_pipes(amavis_t)
allow crond_t amavis_var_lib_t:dir search;

# run spamassassin
optional_policy(`spamassassin',`
	spamassassin_exec(amavis_t)
	spamassassin_exec_client(amavis_t)
	# learn
	allow spamd_t var_lib_t:dir search;
	allow spamd_t amavis_var_lib_t:dir r_dir_perms;
	# access bayes database and such
	allow spamd_t amavis_var_lib_t:file create_file_perms;
')
# connect to clamscan
optional_policy(`clamd',`
	clamd_connect(amavis_t)
	allow clamd_t amavis_var_lib_t:dir r_dir_perms;
	allow clamd_t amavis_var_lib_t:file r_file_perms;
	# check if its available
	allow amavis_t clamscan_exec_t:file getattr;
')
# use random
dev_read_rand(amavis_t)
dev_read_urand(amavis_t)
# use ldap
ldap_use(amavis_t)
# clamd executable will have:
# label: system_u:object_r:clamd_exec_t
# MLS sensitivity: s0
# MCS categories: <none>

/usr/bin/clamscan -- gen_context(system_u:object_r:clamscan_exec_t,s0)
/usr/bin/clamdscan -- gen_context(system_u:object_r:clamscan_exec_t,s0)
/usr/sbin/clamd -- gen_context(system_u:object_r:clamd_exec_t,s0)
/usr/bin/freshclam -- gen_context(system_u:object_r:freshclam_exec_t,s0)
/etc/clamav(/.*)? gen_context(system_u:object_r:clamd_etc_t,s0)
/var/run/clamav(/.*)? gen_context(system_u:object_r:clamd_var_run_t,s0)
/var/run/clamav/clamd.ctl -s gen_context(system_u:object_r:clamd_sock_t,s0)
/var/lib/clamav(/.*)? gen_context(system_u:object_r:clamd_var_lib_t,s0)
/var/log/clamav -d gen_context(system_u:object_r:clamd_var_log_t,s0)
/var/log/clamav/clamav.* -- gen_context(system_u:object_r:clamd_var_log_t,s0)
/var/log/clamav/freshclam.* -- gen_context(system_u:object_r:freshclam_var_log_t,s0)

## <summary>policy for clamd</summary>

########################################
## <summary>
## Execute a domain transition to run clamd.
## </summary>
## <param name="domain">
## Domain allowed to transition.
## </param>
#
interface(clamd_domtrans',

	gen_require(`
		type clamd_t, clamd_exec_t;
	')

	domain_auto_trans($1,clamd_exec_t,clamd_t)

	allow $1 clamd_t:fd use;
	allow clamd_t $1:fd use;
	allow clamd_t:$1:fifo_file rw_file_perms;
	allow clamd_t $1:process sigchld;

')

########################################
## <summary>
## Connect to run clamd.
## </summary>
## <param name="domain">
## Domain allowed to connect.
## </param>
#
interface(clamd_connect',

	gen_require(`
		type clamd_t, clamd_sock_t, clamd_var_run_t;
	')

	allow $1 clamd_var_run_t:dir search;
	allow $1 clamd_sock_t:sock_file write;
	allow $1 clamd_t:unix_stream_socket connectto;
	# the socket was supposed to transition to clamd_sock_t, but
	# somehow sometimes still ends up as clamd_var_run_t - work around
	allow $1 var_run_t:sock_file write;

')

policy_module(clamd,1.0.0)

########################################
#
# Declarations
#

# Main clamd domain
type clamd_t;
type clamd_exec_t;
domain_type(clamd_t)
init_daemon_domain(clamd_t, clamd_exec_t)

# Main clamd domain
type freshclam_t;
type freshclam_exec_t;
domain_type(freshclam_t)
init_daemon_domain(freshclam_t, freshclam_exec_t)

# Clam client executable
type clamscan_exec_t;

# configuration files
type clamd_etc_t;
files_type(clamd_etc_t)
# pid files
type clamd_var_run_t;
files_pid_file(clamd_var_run_t)
# socket domain
type clamd_sock_t;
files_type(clamd_sock_t)
# log files
type clamd_var_log_t;
logging_log_file(clamd_var_log_t)
type freshclam_var_log_t;
logging_log_file(freshclam_var_log_t)
# var/lib files
type clamd_var_lib_t;
files_type(clamd_var_lib_t)
# tmp files
type clamd_tmp_t;
files_tmp_file(clamd_tmp_t)

########################################
#

# clamd local policy
#
# Check in /etc/selinux/refpolicy/include for macros to use instead of allow rules.

# Some common macros
files_read_etc_files(clamd_t) files_read_etc_runtime_files(clamd_t) libs_use_ld_so(clamd_t)
libs_use_shared_libs(clamd_t) miscfiles_read_localization(clamd_t)
allow clamd_t self:fifo_file rw_file_perms;
allow clamd_t self:unix_stream_socket create_stream_socket_perms; allow clamd_t self:unix_dgram_socket create_socket_perms; allow clamd_t self:capability { kill setgid setuid dac_override }; kernel_dontaudit_list_proc(clamd_t)

# configuration files
allow clamd_t clamd_etc_t:dir r_dir_perms;
allow clamd_t clamd_etc_t:file r_file_perms;
allow clamd_t clamd_etc_t:lnk_file { getattr read };
# pid file
allow clamd_t clamd_var_run_t:file manage_file_perms;
allow clamd_t clamd_var_run_t:sock_file manage_file_perms;
allow clamd_t clamd_var_run_t:dir rw_dir_perms;
files_pid_filetrans(clamd_t,clamd_var_run_t, file)
# socket file
allow clamd_t clamd_sock_t:file manage_file_perms;
allow clamd_t clamd_sock_t:sock_file manage_file_perms;
allow clamd_t clamd_sock_t:dir rw_dir_perms;
files_pid_filetrans(clamd_t, clamd_sock_t, sock_file)
# note - this file still transitions to clamd_var_run_t :-(
# log files
allow clamd_t clamd_var_log_t:file create_file_perms;
allow clamd_t clamd_var_log_t:sock_file create_file_perms;
allow clamd_t clamd_var_log_t:dir { rw_dir_perms setattr };
logging_log_filetrans(clamd_t,clamd_var_log_t)
# var/lib files for clamd
allow clamd_t clamd_var_lib_t:file create_file_perms;
allow clamd_t clamd_var_lib_t:sock_file create_file_perms;
allow clamd_t clamd_var_lib_t:dir create_dir_perms;
files_var_filetrans(clamd_t,clamd_var_lib_t,{ file dir sock_file })
files_var_lib_filetrans(clamd_t,clamd_var_lib_t)
# tmp files
allow clamd_t clamd_tmp_t:file create_file_perms;
allow clamd_t clamd_tmp_t:dir create_dir_perms;
files_tmp_filetrans(clamd_t,clamd_tmp_t, { file dir } )

## Networking basics (adjust to your needs!)
sysnet_dns_name_resolve(clamd_t)
corenet_tcp_sendrecv_all_if(clamd_t)
corenet_tcp_sendrecv_all_nodes(clamd_t)
corenet_tcp_sendrecv_all_ports(clamd_t)
corenet_tcp_sendrecv_clamd_port(clamd_t)
corenet_non_ipsec_sendrecv(clamd_t)
corenet_tcp_bind_clamd_port(clamd_t)
corenet_tcp_bind_all_nodes(clamd_t)
allow clamd_t self:tcp_socket { listen accept };

# Init script handling
init_use_fd(clamd_t)
init_use_script_ptys(clamd_t)
domain_use_interactive_fds(clamd_t)
allow initrc_t clamd_sock_t:sock_file unlink;
allow initrc_t clamd_etc_t:file r_file_perms;

# cron handling
cron_use_fd(clamd_t)
cron_use_system_job_fds(clamd_t)
cron_rw_pipes(clamd_t)
# use random
dev_read_rand(clamd_t)
dev_read_urand(clamd_t)

## freshclam

# database updates for clam virus scanner
files_read_etc_files(freshclam_t)
files_read_etc_runtime_files(freshclam_t)
libs_use_ld_so(freshclam_t)
libs_use_shared_libs(freshclam_t)
miscfiles_read_localization(freshclam_t)
allow freshclam_t self:fifo_file rw_file_perms;
allow freshclam_t self:unix_stream_socket create_stream_socket_perms;
allow freshclam_t self:unix_dgram_socket create_socket_perms;
allow freshclam_t self:capability { setgid setuid dac_override };
# configuration files
allow freshclam_t clamd_etc_t:dir r_dir_perms;
allow freshclam_t clamd_etc_t:file r_file_perms;
allow freshclam_t clamd_etc_t:lnk_file { getattr read };
# log files (own logfiles only)
allow freshclam_t clamd_var_log_t:dir search;
allow freshclam_t freshclam_var_log_t:file create_file_perms;
allow freshclam_t freshclam_var_log_t:sock_file create_file_perms;
allow freshclam_t freshclam_var_log_t:dir { rw_dir_perms setattr };
logging_log_filetrans(freshclam_t,freshclam_var_log_t)
# var/lib files together with clamd
allow freshclam_t clamd_var_lib_t:file create_file_perms;
allow freshclam_t clamd_var_lib_t:sock_file create_file_perms;
allow freshclam_t clamd_var_lib_t:dir create_dir_perms;
files_var_filetrans(freshclam_t,clamd_var_lib_t,{ file dir sock_file })
files_var_lib_filetrans(freshclam_t,clamd_var_lib_t)
# pidfiles- var/run together with clamd
allow freshclam_t clamd_var_run_t:file manage_file_perms;
allow freshclam_t clamd_var_run_t:sock_file manage_file_perms;
allow freshclam_t clamd_var_run_t:dir rw_dir_perms;
files_pid_filetrans(freshclam_t,clamd_var_run_t, file)

## Networking basics (adjust to your needs!) sysnet_dns_name_resolve(freshclam_t) corenet_tcp_sendrecv_all_if(freshclam_t) corenet_tcp_sendrecv_all_nodes(freshclam_t) corenet_tcp_sendrecv_all_ports(freshclam_t) corenet_tcp_sendrecv_clamd_port(freshclam_t) corenet_non_ipsec_sendrecv(freshclam_t) corenet_tcp_connect_http_port(freshclam_t) corenet_tcp_bind_all_ports(freshclam_t) corenet_tcp_bind_all_nodes(freshclam_t) allow freshclam_t self:tcp_socket { listen accept };

# Init script handling
init_use_fd(freshclam_t)
init_use_script_ptys(freshclam_t)
domain_use_interactive_fds(freshclam_t)

# cron handling
cron_use_fd(freshclam_t)
cron_use_system_job_fds(freshclam_t)
cron_rw_pipes(freshclam_t)
# use random
dev_read_rand(freshclam_t)
dev_read_urand(freshclam_t)
# use clamd
clamd_connect(freshclam_t)

## Clamscan, the userspace clam scanner
#### NOT YET SUPPORTED. these need to be done per-user #### so this will heavily be macro-based

/usr/sbin/tor -- gen_context(system_u:object_r:tor_exec_t,s0)
/etc/tor(/.*)? gen_context(system_u:object_r:tor_etc_t,s0)
/var/lib/tor(/.*)? gen_context(system_u:object_r:tor_var_lib_t,s0)
/var/log/tor(/.*)? gen_context(system_u:object_r:tor_var_log_t,s0)
/var/run/tor(/.*)? gen_context(system_u:object_r:tor_var_run_t,s0)

## <summary>Policy for TOR, the onion router</summary>

########################################
## <summary>
## Execute a domain transition to run tor.
## </summary>
## <param name="domain">
## Domain allowed to transition.
## </param>
#
interface(tor_domtrans',

	gen_requires(`
		type tor_t, tor_exec_t;
	')

	domain_auto_trans($1,tor_exec_t,tor_t)

	allow $1 tor_t:fd use;
	allow tor_t $1:fd use;
	allow tor_t:$1:fifo_file rw_file_perms;
	allow tor_t $1:process sigchld;

')

policy_module(tor,0.1.1)

########################################
#
# Declarations
#

type tor_t;
type tor_exec_t;
domain_type(tor_t)
init_daemon_domain(tor_t, tor_exec_t)

# etc/tor
type tor_etc_t;
files_config_file(tor_etc_t)
# var/lib/tor
type tor_var_lib_t;
files_type(tor_var_lib_t)
# log files
type tor_var_log_t;
logging_log_file(tor_var_log_t)
# pid files
type tor_var_run_t;
files_pid_file(tor_var_run_t)

########################################
#

# tor local policy
#
# configuration files
allow tor_t tor_etc_t:dir r_dir_perms;
allow tor_t tor_etc_t:file r_file_perms;
allow tor_t tor_etc_t:lnk_file { getattr read };
# var/lib/tor files
allow tor_t tor_var_lib_t:file create_file_perms;
allow tor_t tor_var_lib_t:sock_file create_file_perms;
allow tor_t tor_var_lib_t:dir create_dir_perms;
files_var_filetrans(tor_t,tor_var_lib_t,{ file dir sock_file })
files_var_lib_filetrans(tor_t,tor_var_lib_t)
# log files
allow tor_t tor_var_log_t:file create_file_perms;
allow tor_t tor_var_log_t:sock_file create_file_perms;
allow tor_t tor_var_log_t:dir { rw_dir_perms setattr };
logging_log_filetrans(tor_t,tor_var_log_t,{ sock_file file dir })
# pid file
allow tor_t tor_var_run_t:file manage_file_perms;
allow tor_t tor_var_run_t:sock_file manage_file_perms;
allow tor_t tor_var_run_t:dir rw_dir_perms;
files_pid_filetrans(tor_t,tor_var_run_t, { file sock_file })
# base
files_read_etc_files(tor_t)
miscfiles_read_localization(tor_t)
libs_use_ld_so(tor_t)
libs_use_shared_libs(tor_t)
allow tor_t self:fifo_file { read write };
# tor uses crypto and needs random
dev_read_urand(tor_t)
# comm with init
init_use_fd(tor_t)
init_use_script_ptys(tor_t)
domain_use_interactive_fds(tor_t)
# networking basics
sysnet_dns_name_resolve(tor_t)
corenet_tcp_sendrecv_all_if(tor_t)
#corenet_raw_sendrecv_all_if(tor_t)
corenet_tcp_sendrecv_all_nodes(tor_t)
#corenet_raw_sendrecv_all_nodes(tor_t)
corenet_tcp_sendrecv_all_ports(tor_t)
corenet_tcp_sendrecv_all_reserved_ports(tor_t)
corenet_non_ipsec_sendrecv(tor_t)
# TOR will need to connect to various ports
corenet_tcp_connect_all_ports(tor_t)
# ... especially including port 80 and other privileged ports
corenet_tcp_connect_all_reserved_ports(tor_t)
corenet_tcp_bind_tor_port(tor_t)
corenet_tcp_bind_all_nodes(tor_t)
# Couldn't find appropriate macros for this...
allow tor_t self:unix_stream_socket create_stream_socket_perms;
allow tor_t self:netlink_route_socket r_netlink_socket_perms;
allow tor_t self:tcp_socket { listen accept };

optional_policy(selinuxutil',
seutil_sigchld_newrole(tor_t)
')

#1 lore raw
Quoted 7 lines · Erich Schubert

Hi,
attached are first versions of policies for amavis and clamd, along with a slightly updated tor policy (which needs tor ports defined in corenetwork!)

Looks like I might actually be arriving at a point where I can switch into enforcing mode... ;-)

Merged, with some notes:

Renamed the clamd module to clamav.

I dropped the clamscan_exec_t type. Looking at the example policy, it doesn't look like this was completed, as the per-user domains can't even read the user's files. It seems to me that this was over-engineered before, it would probably be better for the user domains just to be allowed to connect to clamd, and they'll already have access to their files to send over the unix domain socket.

Clamd_sock_t should probably be folded in to clamd_var_run_t, as there doesn't seem to be a need for them to be separate, like in daemons such as mysql.

Please put informative summaries for the modules. "Policy for clamd" does not tell you anything if you don't know what clamd is, and it should be obvious that it is policy. :)

I did some reordering of the rules to be consistent with the rest of refpolicy.

There were a few instances of types being explicitly referenced though they are not owned by the module (e.g., initrc_t in clamav); this is not allowed.

Comments like these:

	# use random
	dev_read_rand(amavis_t)
	dev_read_urand(amavis_t)
	# use ldap
	ldap_use(amavis_t)

aren't really needed, since they don't tell you anything more than the interface names already do.

I need a corenetwork patch for the tor port.

Signature · 9 lines
Chris PeBenito
Tresys Technology, LLC
(410) 290-1411 x150


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