Linux 2.6.32 Centos 6.4 setuid() 失败/安全更改?

Pat*_*ick 5 security linux setuid centos6.4

最近更新到 CentOS 6.4 后,两台机器都有 setuid() 限制,它们的作用类似于功能或 selinux,但是两者都被禁用。例如以下失败:

[root@host statd]# perl -e 'use POSIX; POSIX::setuid(99);system("id")'
[root@host statd]# echo $?
0
Run Code Online (Sandbox Code Playgroud)

什么时候应该返回类似的东西:

host:~# perl -e 'use POSIX; POSIX::setuid(99);system("id")'
uid=99(nobody) gid=0(root) groups=99(nobody),0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
Run Code Online (Sandbox Code Playgroud)

跟踪 perl 的调用,setuid() 调用成功,但是 system() 子项立即退出,就像它被 selinux 或类似的终止一样。但是,即使在 semodule -DB 之后,/var/log/audit/audit.log 中也没有日志条目。

setuid32(99)                            = 0
getuid32()                              = 99
geteuid32()                             = 99
pipe([3, 4])                            = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7705728) = 10073
close(4)                                = 0
rt_sigaction(SIGINT, {SIG_IGN, [], 0}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGQUIT, {SIG_IGN, [], 0}, {SIG_DFL, [], 0}, 8) = 0
waitpid(10073, [{WIFEXITED(s) && WEXITSTATUS(s) == 255}], 0) = 10073
--- SIGCHLD (Child exited) @ 0 (0) ---
rt_sigaction(SIGINT, {SIG_DFL, [], 0}, NULL, 8) = 0
rt_sigaction(SIGQUIT, {SIG_DFL, [], 0}, NULL, 8) = 0
read(3, "\r\0\0\0", 4)                  = 4
close(3)                                = 0
exit_group(0)    
Run Code Online (Sandbox Code Playgroud)

这个问题在第一次重新启动后变得明显,因为 nfs.statd 失败并显示“无法访问本地 netconfig 数据库:找不到 Netconfig 数据库”。并且 rpc.rquotasd 失败,因为“RPC:服务器本地主机需要更强的身份验证”。

nfs.statd 问题可以通过以 root 身份运行来解决(chown root:root /var/lib/nfs/statd)。以 root 身份在机器上运行所有内容似乎不是一个很好的解决方法。;)

尝试 su 到另一个帐户也不起作用:

[root@host ~]# su - jboss
su: warning: cannot change directory to /opt/jboss: Permission denied
su: /bin/bash: Permission denied
[root@host ~]# su jboss
su: /bin/bash: Permission denied
Run Code Online (Sandbox Code Playgroud)

基本系统信息如下:

[root@host statd]# getenforce
Permissive
[root@host statd]# uname -a
Linux host.example.com 2.6.32-358.14.1.el6.i686 #1 SMP Tue Jul 16 21:12:30 UTC 2013 i686 i686 i386 GNU/Linux
[root@host statd]# cat /etc/redhat-release
CentOS release 6.4 (Final)
[root@host statd]# getcap /usr/bin/perl
/usr/bin/perl =
Run Code Online (Sandbox Code Playgroud)

当它显然不是 selinux 或 linux 功能时,可能会导致什么?

Pat*_*ick 1

不知何故,升级过程将 / 的权限更改为:

[root@host ~]# ls -alZ /
drw-r--r--. 42374 5031 system_u:object_r:root_t:s0      .
drw-r--r--. 42374 5031 system_u:object_r:root_t:s0      ..
Run Code Online (Sandbox Code Playgroud)

这是用一个修复的

chown root:root / && chmod 755 /
Run Code Online (Sandbox Code Playgroud)

对缩小错误空间有很大帮助的是运行

strace perl -e 'use POSIX; POSIX::setuid(99);exec("id")'
Run Code Online (Sandbox Code Playgroud)

这表明 perl 的 execve() 调用每次使用 EACCES 都会失败,因为它尝试了所有 $PATH 目录。