rek*_*ado 7 fedora selinux firefox mozilla
我的目标是在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
Run Code Online (Sandbox Code Playgroud)
在第一个条件得到满足,作为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 } ;
Run Code Online (Sandbox Code Playgroud)
所述第二条件被满足时,作为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 } ;
Run Code Online (Sandbox Code Playgroud)
每在Fedora的20缺省配置中,第三个条件没有满足,因为unconfined_t不能过渡mozilla_t。
$ sesearch -s unconfined_t -t mozilla_t -c process -p transition -Ad
(no output)
Run Code Online (Sandbox Code Playgroud)
为了解决这个问题,我编写了一个简短的策略模块,授予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 ;
Run Code Online (Sandbox Code Playgroud)
现在我应该能够mozilla_t通过直接运行可执行文件在域中运行 Firefox 进程/usr/lib64/firefox/firefox,但该进程仍保留在域中unconfined_t。
这里发生了什么?为什么不是进程上下文mozilla_t?
小智 3
你差一点就拥有了。问题是允许规则
允许 unconfined_t mozilla_t :进程转换;
允许转换发生,但不会导致转换发生。为此,您需要一个 type_transition 规则:
type_transition unconfined_t mozilla_exec_t :进程 mozilla_t;
这会导致当 unconfined_t 进程执行 mozilla_exec_t 文件时发生转换。
完成后,Firefox 将无法运行。我使用audit2allow 来追踪允许firefox 管理临时文件和套接字所需的附加规则。
以下是适用于我的基于 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;
Run Code Online (Sandbox Code Playgroud)
编译并安装它:
# checkmodule -M -m -o mozilla.mod mozilla.te
checkmodule:从 rekado.te 加载策略配置
checkmodule:加载策略配置
checkmodule:将二进制表示形式(版本 10)写入 mozilla.mod
# semodule_package -o mozilla.pp -m mozilla.mod
# sudo semodule -i mozilla.pp
| 归档时间: |
|
| 查看次数: |
1495 次 |
| 最近记录: |