matchpathcon
针对文件(例如 /usr/lib64/gconv/gconv-modules.cache)使用我得到:
/usr/lib64/gconv/gconv-modules.cache system_u:object_r:lib_t:s0
然而:
# ls -alZ /usr/lib64/gconv/gconv-modules.cache
-rw-r--r--. root root unconfined_u:object_r:lib_t:s0
因此,该文件似乎没有正确的上下文(用户部分不匹配)。但是,运行时restorecon -v
该文件不会更改。
我可以做这个:
# chcon -t httpd_sys_content_t /usr/lib64/gconv/gconv-modules.cache
# ls -alZ /usr/lib64/gconv/gconv-modules.cache
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0
# restorecon -v /usr/lib64/gconv/gconv-modules.cache
unconfined_u:object_r:httpd_sys_content_t:s0 -> unconfined_t:object_r:lib_t:s0
所以似乎只更新文件的restorecon
SELinux ,而不更新上下文。这是一个错误还是对此行为有解释?我认为这可能是一个错误,因为文档(type
user
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Security-Enhanced_Linux/sect-Security-Enhanced_Linux-Working_with_SELinux-SELinux_Contexts_Labeling_Files.html)显示了上下文不匹配的文件上的恢复操作,并且它已按预期user
更改。unconfined_u->system_u
操作系统:RedHat 7.3
SELinux:3.13.1-102.el7_3.16
答案1
打开支持案例后,我发现我被 Red Hat 文档误导了,应该更仔细地阅读手册页:
# man restorecon
...
If a file object does not have a context, restorecon will write the
default context to the file object's extended attributes. **If a file
object has a context, restorecon will only modify the type portion of
the security context. The -F option will force a replacement of the
entire context.**
...