Linux 2.6.32 Centos 6.4 setuid() 失敗/安全變更?

Linux 2.6.32 Centos 6.4 setuid() 失敗/安全變更?

最近更新到 CentOS 6.4 後,兩台機器都有 setuid() 限制,其作用類似於功能或 selinux,但兩者都被停用。例如以下失敗:

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

當它應該返回類似以下內容時:

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

追蹤 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)    

第一次重新啟動後,此問題變得明顯,因為 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

系統基本資訊如下:

[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 =

當它顯然不是 selinux 或 linux 功能時,可能是什麼原因導致的?

答案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      ..

這是用一個修復的

chown root:root / && chmod 755 /

對縮小錯誤空間有很大幫助的是運行

strace perl -e 'use POSIX; POSIX::setuid(99);exec("id")'

這表示 perl 的 execve() 呼叫每次使用 EACCES 都會失敗,因為它嘗試了所有 $PATH 目錄。

相關內容