+ -
当前位置:首页 → 问答吧 → 有没有是成功试过selinuxde ?

有没有是成功试过selinuxde ?

时间:2010-04-02

来源:互联网

我依照官方资料介绍http://wiki.archlinux.org/index.php/...

作者: zswlb9999   发布时间: 2010-04-02

没玩arch
gentoo的经验

1. 内核要配好
成功标志:
ls -l /selinux
里面有内容
内核配置可参考gentoo官帖
2.两次rlpkg,中间要重启
arch 和 fedora 都是一次rlpkg
成功标志:
ls -lZ
显示正常 不带?
正常开关enforcing
sestatus -v
有enable标记
restorecon 建议在permissive下

作者: U571   发布时间: 2010-04-02

我发胡第一个贴有sestaut的内容,奇怪不见了。
问题是设置了enforce为1后,重启不能登录,提示/bin/bash没有权限。
1)配置了 /etc/selinux/refpolicy/src/policy/build.conf:
MONOLITHIC = n
2)ln -s /etc/selinux/refpolicy/policy/policy.21 /etc/policy.bin
改为:
ln -s /etc/selinux/refpolicy/policy/policy.24 /etc/policy.bin
其他依照文档操作。
[wu@hashost ~]$ ls -lZ /
总用量 76
drwxr-xr-x. 2 root root system_u:object_r:bin_t 4096 3月 29 13:38 bin
drwxr-xr-x. 3 root root system_u:object_r:boot_t 4096 3月 28 23:23 boot
drwxr-xr-x. 13 root root system_u:object_r:tmpfs_t 5300 4月 2 00:04 dev
drwxr-xr-x. 47 root root system_u:object_r:etc_t 4096 4月 2 00:03 etc
drwxr-xr-x. 3 root root system_u:object_r:home_root_t 4096 3月 26 12:47 home
drwxr-xr-x. 8 root root system_u:object_r:lib_t 4096 3月 28 15:07 lib
drwxr-xr-x. 2 root root system_u:object_r:lib_t 4096 12月 12 07:09 lib64
drwx------. 2 root root system_u:object_r:lost_found_t 16384 3月 26 11:05 lost+found
drwxr-xr-x. 5 root root system_u:object_r:mnt_t 4096 4月 2 00:04 media
drwxr-xr-x. 3 root root system_u:object_r:mnt_t 4096 3月 29 14:49 mnt
drwxr-xr-x. 2 root root system_u:object_r:usr_t 4096 2月 26 04:56 opt
dr-xr-xr-x. 96 root root system_u:object_rroc_t 0 4月 2 00:03 proc
drwxr-x---. 2 root root root:object_r:user_home_dir_t 4096 3月 26 13:06 root
drwxr-xr-x. 2 root root system_u:object_r:bin_t 4096 3月 29 13:38 sbin
drwxr-xr-x. 7 root root system_u:object_r:security_t 0 4月 2 00:03 selinux
drwxr-xr-x. 4 root root system_u:object_r:var_t 4096 2月 26 04:56 srv
drwxr-xr-x. 12 root root system_u:object_r:sysfs_t 0 4月 2 00:03 sys
drwxrwxrwt. 6 root root system_u:object_r:tmp_t 4096 4月 2 00:07 tmp
drwxr-xr-x. 10 root root system_u:object_r:usr_t 4096 1月 30 2009 usr
drwxr-xr-x. 13 root root system_u:object_r:var_t 4096 3月 26 11:18 var


[wu@hashost ~]$ sestatus -v
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: permissive
Mode from config file: enforcing
Policy version: 24
Policy from config file: refpolicy

Process contexts:
Current context: user_u:user_r:insmod_t
Init context: system_u:system_r:kernel_t

File contexts:
Controlling term: user_u:object_r:devpts_t
/etc/passwd system_u:object_r:etc_t
/etc/shadow system_u:object_r:shadow_t
/bin/bash system_u:object_r:shell_exec_t
/bin/login system_u:object_r:login_exec_t
/bin/sh system_u:object_r:bin_t -> system_u:object_r:shell_exec_t
/sbin/agetty system_u:object_r:getty_exec_t
/sbin/init system_u:object_r:init_exec_t
/lib/libc.so.6 system_u:object_r:lib_t -> system_u:object_r:lib_t

作者: zswlb9999   发布时间: 2010-04-02

楼主不是安装selinux有问题
而是使用selinux有问题

现在这个状态已经正常开启了
只是不能enforcing
ausearch -m avc -ts recent 看下说些什么

另: 安装步骤中的Post-instalation steps有做没??

作者: U571   发布时间: 2010-04-02

貌似没说清楚
你现在这个无法启动的原因如下:
make relabel 无法对运行中进程进行 label 操作; 直接导致运行中进程在下次启动的时候运行在错误的安全域中。如你的sestatus显示的:
Init context: system_u:system_r:kernel_t
就是init 进程运行在 kernel_t 这个域上,而安全规则refpolicy中init 进程是要运行在init_t 这个域上的。
正常的Init context为system_u:system_r:init_t
/bin/sh system_u:object_r:bin_t -> system_u:object_r:shell_exec_t
也运行在错误域上,应该运行在shell_exe_t上
那么要保证 init 运行的域 和 refpolicy 上的一致,就必须对init进行重新标记。
系统是通过restorecond脚本,在重启后将refpolicy中的标记还原到系统中去的。
假如你有制作了这个脚本,你必须确认在/etc/rc.conf有添加restorecond。
这样下次启动才会运行。

作者: U571   发布时间: 2010-04-02

我安装过5次selinux都失败:就设置enforce后无法登录。

第一,二次安装有做Post-instalation steps,后几次没有做。
http://wiki.archlinux.org/index.php/SELinux
在上面的介绍中,有提到过restorecond:

To maintain correct context, you can use restorecond:
touch /etc/rc.d/restorecond
chmod ugo+x /etc/rc.d/restorecond

Which should contain:

#!/bin/sh

restorecond
------------
我不了解restorecond脚本名为何要与restorecond一样,我在硬盘搜了一下,有如下程序:
/usr/sbin/restorecond
/sbin/restorecon
因怀疑wiyi有误,后来就没有做Post-instalation steps。
我再试试做这一步。

另:
[root@hashost wu]# ausearch -m avc -ts recent
bash: ausearch: command not found

谢谢楼上。

作者: zswlb9999   发布时间: 2010-04-02

从make开始重做
cd /etc/selinux/refpolicy/src/policy
make bare
make conf
make load

[root@hashost policy]# make relabel
Relabeling filesystem types: btrfs ext2 ext3 ext4 xfs jfs
/sbin/setfiles /etc/selinux/refpolicy/contexts/files/file_contexts /
filespec_add: conflicting specifications for /usr/bin/getconf and /usr/lib/getconf/XBS5_LP64_OFF64, using system_u:object_r:lib_t.
---
上面提示有冲突。先记下来。继续做后面的。
文件系统是ext3,我没有做下面的
fixfiles restore
restorecon -r /
---------------
restorecond脚本做了,也加到/etc/rc.conf
准备重启。

作者: zswlb9999   发布时间: 2010-04-02

重启后设置enforce 为1后登录失败。

---------------
[wu@hashost ~]$ ls -lZ /etc/rc.d/re*
-rwxr-xr-x. 1 root root user_u:object_r:etc_t 23 4月 2 09:33 /etc/rc.d/restorecond


user_u???
----------------
[root@hashost wu]# cat /etc/rc.d/restorecond
#!/bin/sh
restorecond

[root@hashost wu]#

-----------------------
[root@hashost wu]# sestatus -v
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: permissive
Mode from config file: enforcing
Policy version: 24
Policy from config file: refpolicy

Process contexts:
Current context: user_u:user_r:insmod_t
Init context: system_u:system_r:kernel_t
/sbin/agetty system_u:system_r:kernel_t

File contexts:
Controlling term: user_u:object_r:devpts_t
/etc/passwd system_u:object_r:etc_t
/etc/shadow system_u:object_r:shadow_t
/bin/bash system_u:object_r:shell_exec_t
/bin/login system_u:object_r:login_exec_t
/bin/sh system_u:object_r:bin_t -> system_u:object_r:shell_exec_t
/sbin/agetty system_u:object_r:getty_exec_t
/sbin/init system_u:object_r:init_exec_t
/lib/libc.so.6 system_u:object_r:lib_t -> system_u:object_r:lib_t
[root@hashost wu]#

作者: zswlb9999   发布时间: 2010-04-02

对个人用户用处不大吧,服务器上用处大一些。

作者: alpha.gu   发布时间: 2010-04-03

引用:
-rwxr-xr-x. 1 root root user_u:object_r:etc_t 23 4月 2 09:33 /etc/rc.d/restorecond
user_u是不正常的
引用:
[root@hashost wu]# ausearch -m avc -ts recent
bash: ausearch: command not found
sorry, 对Arch不是很熟,-。-

你找下有没这个文件。

/var/log/audit/audit.log
出错信息在这里面。
过滤下信息 找关键字"denied" "restorecond"
应该是编写的脚本被selinux阻挡了,没有执行。

解决办法:(步骤如下)
1. permissive模式下,手动指定restorecond的运行域

chcon -v -u system_u -r object_r -t initrc_exec_t /etc/rc.d/restorecond

手工指定域标签 可以参照下 /etc/rc.d 下的可执行文件,上面的只是个参考。
确认restorecond 标签和其他可执行文件的相同
ls -lZ 看看
[等等]
顺便把这条规则加到refpolicy里去,据说restorecond会把chcon的修改覆盖掉,不晓得会不会自修改自己。
/usr/sbin/semanage fcontext -a -t initrc_exec_t /etc/rc.d/restorecond
2. 开启selinux
setenforce 1 或 书上步骤:echo 1 >/selinux/enforce
3. 重启
成功的话一切正常,直接可到登录界面。不成功的话,init阶段出错信息会很多。
Good luck!

另:Fedora 12 的 Security-Enhanced Linux user guide 可以在官网下载,有兴趣可以下来看看。声明先:没zh_CN版本的 -。- !

作者: U571   发布时间: 2010-04-03

另外:Fedora下有个修复案例

selinux enforcing 下
手动改到 permissive
关闭了 restorecond 的开机启动
之后又将 selinux 设回 enforcing 状态,重启
系统出错
/bin/bash可进入,但无法将restorecond设为开机启动,无法修改一些相关文件。
即使更改到 permissive状态,依然无法修改。

解决方法是
cd /
touch .fixfiles
selinux 依然为 enforcing
重启
一切恢复正常
修改 restorecond 到 开机启动状态
rm .fixfiles

不晓得arch行不行得通,上面方法如果不行,试下这种。

作者: U571   发布时间: 2010-04-03

重启启动读文件时提示超级块错误,提示ctrl+D....(设置了enforcing=1 selinx=1 启动)
怀疑编译内核配置不对,AUR的kernel-selinux的内核配置好像是32位的,我的系统原是采用64位安装。详细阅读后再继续。
谢谢楼上提供的分析及信息。

作者: zswlb9999   发布时间: 2010-04-03