Skip to contentSkip to conversation

Fedora Rawhide mplayer policy

PATCH Ivan Gyurdiev 2 participants 3 messages Jan 22, 2005 – Jan 25, 2005 SELinux security module

lore
Share & tools
lore
#0 lore raw

I filed a bug on mplayer not being able to read /dev/rtc, and dwalsh advised that I should try to write a mplayer policy.

So, this is what I came up with...
It's tailored to Fedora Rawhide 1.21.2-7 strict + the livna mplayer packages. It also assumes Daniel Walsh has added nscd_client_domain to x_client_macros.te.

Comments? I've never written a policy before, so I borrowed as much as I could from others.

Signature · 2 lines
Ivan Gyurdiev <[email protected]>
Cornell University
base_user_macros.new renamed from base_user_macros.te +2 -0
@@ -188,6 +188,8 @@
 ifdef(`using_spamassassin', `spamassassin_domain($1)')
 ifdef(`uml.te', `uml_domain($1)')
 ifdef(`cdrecord.te', `cdrecord_domain($1)')
+ifdef(`mplayer.te', `mplayer_domain($1)')
+ifdef(`mplayer.te', `mencoder_domain($1)')
 
 # Instantiate a derived domain for user cron jobs.
 ifdef(`crond.te', `crond_domain($1)')
# mplayer
/usr/bin/mplayer	--	system_u:object_r:mplayer_exec_t
/usr/bin/mencoder	--	system_u:object_r:mencoder_exec_t
/etc/mplayer(/.*)?		system_u:object_r:mplayer_etc_t
HOME_DIR/\.mplayer(/.*)?        system_u:object_r:ROLE_mplayer_rw_t

#
# Macros for mplayer
#
# Author: Ivan Gyurdiev <[email protected]>
#
#
# mplayer_domain(domain_prefix)
# mencoder_domain(domain_prefix)

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

# These are common acess permissions for mplayer and mencoder # mplayer_common($1,$2)

define(mplayer_common',

# Home directory stuff
if (use_nfs_home_dirs) {
create_dir_file($1_$2_t, nfs_t)
}
if (use_samba_home_dirs) {
create_dir_file($1_$2_t, cifs_t)
}
ifdef(automount.te',
allow $1_$2_t autofs_t:dir { search getattr };
') dnl end if automount

# Read local config
r_dir_file($1_$2_t, $1_mplayer_rw_t)

# Read global config
r_dir_file($1_$2_t, mplayer_etc_t)

# Read data in /usr/share (fonts, icons..)
r_dir_file($1_$2_t, usr_t)

# Read /proc files and directories
# Necessary for /proc/meminfo, /proc/cpuinfo, etc.. allow $1_$2_t proc_t:dir search;
allow $1_$2_t proc_t:file { getattr read };

# Sysctl on kernel version
allow $1_$2_t sysctl_kernel_t:dir search; allow $1_$2_t sysctl_kernel_t:file { getattr read };

# allow ps
can_ps($1_t, $1_$2_t)
# uses shared libraries
uses_shlib($1_$2_t)
# localization
read_locale($1_$2_t)

# Access the terminal.
allow $1_$2_t devpts_t:dir { search };
allow $1_$2_t $1_tty_device_t:chr_file rw_file_perms; allow $1_$2_t $1_devpts_t:chr_file rw_file_perms;

# Required for win32 binary loader
# FIXME: more is needed here - it wants execute on /dev/zero and /usr/lib/win32/*

allow $1_mencoder_t zero_device_t:chr_file { read write }; allow $1_mencoder_t self:process { execmem };

')

define(mplayer_domain',

# Derive from X client domain
x_client_domain($1, mplayer', ')

# Mplayer common stuff
mplayer_common($1, mplayer)

# Additional rules for search /tmp/.X11-unix
ifdef(xdm.te',
allow $1_mplayer_t xdm_tmp_t:dir search;
')dnl end if xdm.te

# Prevent getattr denials on restricted types when browsing with gmplayer dontaudit $1_mplayer_t *:dir_file_class_set { getattr };

# Audio
allow $1_mplayer_t sound_device_t:chr_file rw_file_perms;

# RTC clock
allow $1_mplayer_t clock_device_t:chr_file { ioctl read };

# Read home directory content
r_dir_file($1_mplayer_t, $1_home_t);

# Allow execmod to make libSDL work
allow $1_mplayer_t shlib_t:file { execmod };

# Play DVD/VCD
allow $1_mplayer_t device_t:lnk_file { getattr read }; allow $1_mplayer_t removable_device_t:blk_file { getattr read };

') dnl end mplayer_domain

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

define(mencoder_domain',

# Privhome type transitions to $1_home_t in home dir. type $1_mencoder_t, domain, privhome;

# Transition
domain_auto_trans($1_t, mencoder_exec_t, $1_mencoder_t) can_exec($1_mencoder_t, mencoder_exec_t)
role $1_r types $1_mencoder_t;

# Mplayer common stuff
mplayer_common($1, mencoder)

') dnl end mencoder_domain

#DESC mplayer - media player
#
# Author: Ivan Gyurdiev <[email protected]>
#

# Type for the mplayer executable.
type mplayer_exec_t, file_type, exec_type, sysadmfile; type mencoder_exec_t, file_type, exec_type, sysadmfile; type mplayer_etc_t, file_type, sysadmfile;

# Everything else is in the mplayer_domain macro in

# macros/program/mplayer_macros.te.
#1 lore raw
Quoted 10 lines · Ivan Gyurdiev

I filed a bug on mplayer not being able to read /dev/rtc, and dwalsh advised that I should try to write a mplayer policy.

So, this is what I came up with...
It's tailored to Fedora Rawhide 1.21.2-7 strict + the livna mplayer packages. It also assumes Daniel Walsh has added nscd_client_domain to x_client_macros.te.

Comments? I've never written a policy before, so I borrowed as much as I could from others.

ifdef(mplayer.te', mplayer_domain($1)')
ifdef(mplayer.te', mencoder_domain($1)')

The above is better written as:
ifdef(mplayer.te', mplayer_domain($1)
mencoder_domain($1)')

It might be better still to have the mplayer_domain() macro just call the mencoder_domain() macro.

Why have a special type for the mplayer configuration files? Is it expected that secret data will be in such files or that programs which are not permitted to write to other files under /etc will be permitted to write to them?

dontaudit $1_mplayer_t *:dir_file_class_set { getattr };

The "*" should be replaced by "file_type" to reduce the size of the policy binary.

It seems that the main benefit given by the mplayer domain is to prevent user_t from reading /dev/rtc. But that is minimal, maybe it would be better to just have a tunable for whether userdomain should be permitted to read clock_device_t:chr_file. mencoder may be a different case however as it's got to write data and read from V4L devices etc.

Signature · 9 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.
#2 lore raw

Here's a new version that fixes some minor things Russel Cooker noted, fixes a typo, moves ability to read removable_device_t into common portion, labels /usr/lib/win32 with win32_lib_t, and adds execute permissions to win32_lib_t, and /dev/zero.

Signature · 2 lines
Ivan Gyurdiev <[email protected]>
Cornell University
base_user_macros.new renamed from base_user_macros.te +4 -0
@@ -188,6 +188,10 @@
 ifdef(`using_spamassassin', `spamassassin_domain($1)')
 ifdef(`uml.te', `uml_domain($1)')
 ifdef(`cdrecord.te', `cdrecord_domain($1)')
+ifdef(`mplayer.te', `
+mplayer_domain($1)
+mencoder_domain($1)
+')
 
 # Instantiate a derived domain for user cron jobs.
 ifdef(`crond.te', `crond_domain($1)')
# mplayer
/usr/bin/mplayer	--	   	system_u:object_r:mplayer_exec_t
/usr/bin/mencoder	--	   	system_u:object_r:mencoder_exec_t

/usr/lib/win32(/.*)? system_u:object_r:win32_lib_t
/usr/lib/win32/.*\.so(\.[^/]*)* -- system_u:object_r:shlib_t

/etc/mplayer(/.*)? system_u:object_r:mplayer_etc_t
HOME_DIR/\.mplayer(/.*)? system_u:object_r:ROLE_mplayer_rw_t

#
# Macros for mplayer
#
# Author: Ivan Gyurdiev <[email protected]>
#
#
# mplayer_domain(domain_prefix)
# mencoder_domain(domain_prefix)

################################################
# mplayer_common(prefix, mplayer domain) #
################################################

define(mplayer_common',

# Home directory stuff
if (use_nfs_home_dirs) {
create_dir_file($1_$2_t, nfs_t)
}
if (use_samba_home_dirs) {
create_dir_file($1_$2_t, cifs_t)
}
ifdef(automount.te',
allow $1_$2_t autofs_t:dir { search getattr };
') dnl end if automount

# Read local config
r_dir_file($1_$2_t, $1_mplayer_rw_t)

# Read global config
r_dir_file($1_$2_t, mplayer_etc_t)

# Read data in /usr/share (fonts, icons..)
r_dir_file($1_$2_t, usr_t)

# Read /proc files and directories
# Necessary for /proc/meminfo, /proc/cpuinfo, etc.. allow $1_$2_t proc_t:dir search;
allow $1_$2_t proc_t:file { getattr read };

# Sysctl on kernel version
allow $1_$2_t sysctl_kernel_t:dir search; allow $1_$2_t sysctl_kernel_t:file { getattr read };

# allow ps
can_ps($1_t, $1_$2_t)
# uses shared libraries
uses_shlib($1_$2_t)
# localization
read_locale($1_$2_t)

# Access the terminal.
allow $1_$2_t devpts_t:dir { search };
allow $1_$2_t $1_tty_device_t:chr_file rw_file_perms; allow $1_$2_t $1_devpts_t:chr_file rw_file_perms;

# Required for win32 binary loader
allow $1_$2_t zero_device_t:chr_file { read write execute }; allow $1_$2_t self:process { execmem };
allow $1_$2_t win32_lib_t:file rx_file_perms;

# Access to DVD/CD
allow $1_$2_t device_t:lnk_file { getattr read }; allow $1_$2_t removable_device_t:blk_file { getattr read }; ')

##############################
# mplayer_domain(prefix) #
##############################

define(mplayer_domain',

# Derive from X client domain
x_client_domain($1, mplayer', ')

# Mplayer common stuff
mplayer_common($1, mplayer)

# Additional rules for search /tmp/.X11-unix
ifdef(xdm.te',
allow $1_mplayer_t xdm_tmp_t:dir search;
')dnl end if xdm.te

# Prevent getattr denials on restricted types when browsing with gmplayer dontaudit $1_mplayer_t file_type:dir_file_class_set { getattr };

# Audio
allow $1_mplayer_t sound_device_t:chr_file rw_file_perms;

# RTC clock
allow $1_mplayer_t clock_device_t:chr_file { ioctl read };

# Read home directory content
r_dir_file($1_mplayer_t, $1_home_t);

# Allow execmod to make libSDL work
allow $1_mplayer_t shlib_t:file { execmod };

') dnl end mplayer_domain

##############################
# mencoder_domain(prefix) #
##############################

define(mencoder_domain',

# Privhome type transitions to $1_home_t in home dir. type $1_mencoder_t, domain, privhome;

# Transition
domain_auto_trans($1_t, mencoder_exec_t, $1_mencoder_t) can_exec($1_mencoder_t, mencoder_exec_t)
role $1_r types $1_mencoder_t;

# Mplayer common stuff
mplayer_common($1, mencoder)

') dnl end mencoder_domain

#DESC mplayer - media player
#
# Author: Ivan Gyurdiev <[email protected]>
#

# Type for the mplayer executable.
type mplayer_exec_t, file_type, exec_type, sysadmfile; type mencoder_exec_t, file_type, exec_type, sysadmfile; type mplayer_etc_t, file_type, sysadmfile; type win32_lib_t, file_type, sysadmfile;

# Everything else is in the mplayer_domain macro in

# macros/program/mplayer_macros.te.