LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 731|回复: 11

有没有是成功试过selinuxde ?

[复制链接]
发表于 2010-4-2 00:19:30 | 显示全部楼层 |阅读模式
我依照官方资料介绍http://wiki.archlinux.org/index. ... 本情况如下:
文件系统:ext3
修改过
1)
/etc/selinux/refpolicy/src/policy/build.conf中的
MONOLITHIC = y

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



运行情况:
启动参数 设置 selinux=1
[wu@hashost ~]$ sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   permissive
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        refpolicy
[wu@hashost ~]$
当设置seenforce 为1时,强逼重新登录,但登录失败。(提示没有/bin/bash的权限)

只能关机重启。

谁成功安装过?
发表于 2010-4-2 00:43:02 | 显示全部楼层
没玩arch
gentoo的经验

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

使用道具 举报

 楼主| 发表于 2010-4-2 08:12:25 | 显示全部楼层
我发胡第一个贴有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_ubject_r:bin_t         4096  3月 29 13:38 bin
drwxr-xr-x.  3 root root system_ubject_r:boot_t        4096  3月 28 23:23 boot
drwxr-xr-x. 13 root root system_ubject_r:tmpfs_t       5300  4月  2 00:04 dev
drwxr-xr-x. 47 root root system_ubject_r:etc_t         4096  4月  2 00:03 etc
drwxr-xr-x.  3 root root system_ubject_r:home_root_t   4096  3月 26 12:47 home
drwxr-xr-x.  8 root root system_ubject_r:lib_t         4096  3月 28 15:07 lib
drwxr-xr-x.  2 root root system_ubject_r:lib_t         4096 12月 12 07:09 lib64
drwx------.  2 root root system_ubject_r:lost_found_t 16384  3月 26 11:05 lost+found
drwxr-xr-x.  5 root root system_ubject_r:mnt_t         4096  4月  2 00:04 media
drwxr-xr-x.  3 root root system_ubject_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_r:proc_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
回复 支持 反对

使用道具 举报

发表于 2010-4-2 08:42:32 | 显示全部楼层
楼主不是安装selinux有问题
而是使用selinux有问题

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

另: 安装步骤中的Post-instalation steps有做没??
回复 支持 反对

使用道具 举报

发表于 2010-4-2 12:47:27 | 显示全部楼层
貌似没说清楚
你现在这个无法启动的原因如下:
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_ubject_r:bin_t -> system_ubject_r:shell_exec_t
也运行在错误域上,应该运行在shell_exe_t上
那么要保证 init 运行的域 和 refpolicy 上的一致,就必须对init进行重新标记。
系统是通过restorecond脚本,在重启后将refpolicy中的标记还原到系统中去的。
假如你有制作了这个脚本,你必须确认在/etc/rc.conf有添加restorecond。
这样下次启动才会运行。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-4-2 17:33:15 | 显示全部楼层
我安装过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

谢谢楼上。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-4-2 17:48:57 | 显示全部楼层
从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_ubject_r:lib_t.
---
        上面提示有冲突。先记下来。继续做后面的。
文件系统是ext3,我没有做下面的
fixfiles restore
restorecon -r /
---------------
restorecond脚本做了,也加到/etc/rc.conf
准备重启。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-4-2 18:21:11 | 显示全部楼层
重启后设置enforce 为1后登录失败。

---------------
[wu@hashost ~]$ ls -lZ  /etc/rc.d/re*
-rwxr-xr-x. 1 root root user_ubject_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_ubject_r:devpts_t
/etc/passwd                     system_ubject_r:etc_t
/etc/shadow                     system_ubject_r:shadow_t
/bin/bash                       system_ubject_r:shell_exec_t
/bin/login                      system_ubject_r:login_exec_t
/bin/sh                         system_ubject_r:bin_t -> system_ubject_r:shell_exec_t
/sbin/agetty                    system_ubject_r:getty_exec_t
/sbin/init                      system_ubject_r:init_exec_t
/lib/libc.so.6                  system_u:object_r:lib_t -> system_u:object_r:lib_t
[root@hashost wu]#
回复 支持 反对

使用道具 举报

发表于 2010-4-2 20:44:28 | 显示全部楼层
对个人用户用处不大吧,服务器上用处大一些。
回复 支持 反对

使用道具 举报

发表于 2010-4-2 23:31:09 | 显示全部楼层
-rwxr-xr-x. 1 root root user_ubject_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版本的 -。- !
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表