我的目标是在mozilla_t域中执行Firefox,而不是unconfined_t 。 该机器在SELinux的强制模式下运行Fedora 20。
不幸的是,我似乎无法得到这个权利。 无论我做什么,该进程总是在unconfined_t域中执行。
我知道要满足三个条件:
mozilla_exec_t )必须对源域可执行( unconfined_t或bin_t ) mozilla_exec_t )必须标记为目标域( mozilla_t )的入口点 unconfined_t或bin_t )转换到目标域( mozilla_t ) 目标文件是/usr/bin/firefox的firefox脚本,它调用/usr/lib64/firefox/run-mozilla.run ,它再次运行二进制文件/usr/lib64/firefox/firefox 。 这是这些文件上ls -Z的输出:
-rwxr-xr-x. root root system_u:object_r:bin_t:s0 /usr/bin/firefox -rwxr-xr-x. root root system_u:object_r:bin_t:s0 /usr/lib64/firefox/run-mozilla.sh -rwxr-xr-x. root root system_u:object_r:mozilla_exec_t:s0 /usr/lib64/firefox/firefox
满足第一个条件,因为unconfined_t被允许执行目标文件上下文mozilla_exec_t 。
$ sesearch -s unconfined_t -t mozilla_exec_t -c file -p execute -Ad Found 1 semantic av rules: allow unconfined_t mozilla_exec_t : file { ioctl read getattr lock execute execute_no_trans entrypoint open } ;
满足第二个条件,因为mozilla_exec_t被定义为mozilla_t域的入口点。
$ sesearch -s mozilla_t -t mozilla_exec_t -c file -p entrypoint -Ad Found 1 semantic av rules: allow mozilla_t mozilla_exec_t : file { ioctl read getattr lock execute execute_no_trans entrypoint open } ;
根据Fedora 20中的默认configuration, 第三个条件不符合,因为unconfined_t不能转换到mozilla_t 。
$ sesearch -s unconfined_t -t mozilla_t -c process -p transition -Ad (no output)
为了解决这个问题,我写了一个简短的策略模块,授予unconfined_t进程权限以转换到mozilla_t 。
module rekado 1.0; require { type unconfined_t; type mozilla_t; class process transition; } allow unconfined_t mozilla_t : process transition ;
现在,我应该可以通过直接运行可执行文件/usr/lib64/firefox/firefox在域mozilla_t运行Firefox进程,但进程保留在域unconfined_t 。
这里发生了什么? 为什么不是进程上下文mozilla_t ?
你几乎已经有了。 问题是允许规则
允许unconfined_t mozilla_t:进程转换;
允许过渡发生,但不会导致发生。 为此你需要一个type_transition规则:
type_transition unconfined_t mozilla_exec_t:进程mozilla_t;
这会导致在unconfined_t进程执行mozilla_exec_t文件时发生转换。
完成后,Firefox将无法运行。 我使用audit2allow来追踪允许firefoxpipe理临时文件和套接字所需的附加规则。
这是一个适用于基于CentOS 6的虚拟机的策略。 它需要启用selinux布尔mozilla_read_content(通过: setsebool -P mozilla_read_content 1 )。
module mozilla 1.0; require { role unconfined_r; type unconfined_t; type mozilla_t; type mozilla_exec_t; type tmp_t; type user_tmp_t; type fs_t; class process transition; class file { ioctl getattr setattr create read write unlink open relabelto }; class dir { ioctl getattr setattr create read write unlink add_name remove_name }; class filesystem getattr; class sock_file { getattr setattr create read write unlink }; class unix_stream_socket connectto; } role unconfined_r types mozilla_t; allow unconfined_t self:file relabelto; allow unconfined_t mozilla_t : process transition ; type_transition unconfined_t mozilla_exec_t : process mozilla_t; allow mozilla_t fs_t:filesystem getattr; allow mozilla_t tmp_t:file { ioctl getattr setattr create write unlink open }; allow mozilla_t tmp_t:dir { ioctl getattr setattr create read write add_name remove_name }; allow mozilla_t user_tmp_t:dir { ioctl create write add_name setattr remove_name }; allow mozilla_t user_tmp_t:sock_file { getattr setattr create read write unlink }; allow mozilla_t unconfined_t:unix_stream_socket connectto;
编译并安装它:
#checkmodule -M -m -o mozilla.mod mozilla.te
checkmodule:从rekado.te加载策略configuration
checkmodule:加载策略configuration
checkmodule:将二进制表示(版本10)写入mozilla.mod
#semodule_package -o mozilla.pp -m mozilla.mod
#sudo semodule -i mozilla.pp