SELinux policy问题解决思路总结

本文介绍了SELinux的基本概念,提供了确认安全问题是否由权限引起的方法,并详细讲解了三种添加所需权限的方法,包括使用工具生成策略文件、精确指定设备权限及调整进程属性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文转载自:http://www.th7.cn/system/lin/201512/147098.shtml


一、了解SELinux基本概念,这个网上资料很多,参考下(http://jingpin.jikexueyuan.com/article/55398.html)

http://blog.youkuaiyun.com/innost/article/details/19299937/

http://blog.youkuaiyun.com/luoshengyang/article/details/37613135

http://www.2cto.com/kf/201504/390742.html

二、确认是否安全问题

可以通过手动关闭selinux,确认问题是否是权限引起的,具体方法:

查看SELinux状态:

1、/usr/sbin/sestatus -v      ##如果SELinux status参数为enabled即为开启状态

SELinux status:                 enabled

2、getenforce                 ##也可以用这个命令检查

关闭SELinux:

1、临时关闭(不用重启机器):

setenforce 0                  ##设置SELinux 成为permissive模式

                              ##setenforce 1 设置SELinux 成为enforcing模式



三、抓dmesg log,转换出系统缺少的policy

dmesg log:

dmesg | grep rpcServer

[ 8.132704] init: Starting service 'rpcServer'...

[ 12.936186] type=1400 audit(1449623772.120:13): avc: denied { read } for pid=174 comm="rpcServer" name="mmcblk0p1" dev="tmpfs" ino=8105 scontext=u:r:rpcServer:s0 tcontext=u:object_r:block_device:s0 tclass=blk_file permissive=0

比如上面这个log,你需要能清楚这句话的意思:原进程(scontext)需要目标(tcontext)进程tclass属性的read权限 。

我们可以通过ls -Z、ps -Z、ls -l等查看具体设备文件相关属性

三、如何添需要的权限(这个可以分3类来处理)

1.第一类比较简单,通过audit2allow等工具转换出对应模块缺少的policy(.te文件)

添加到sepolicy/rpcServer.te:

allowrpcServer block_device:blk_file read ;  分别对应上面的allow scontext tcontext:tclass   read


2.第二类,有一些policy加进来,编译的时候系统会报错,原因是我们上面转换的policy一般都是某个进程对所以的的设备文件具有相关权限,这个权限过大,会和google的安全策略(external/sepolicy下neverallow)想冲突。这种情况下,我们需要找出原进程究竟需要哪个具体的设备文件的相关权限,就可以解决

添加:

先在sepolicy/file_contexts定义mmcblk0p1 设备节点:/dev/block/mmcblk0p1 u:object_r:rpc_block_device:s0

在sepolicy/rpcServer.te添加该设备节点的权限:allow rpcServer rpc_block_device:blk_file read;

3.第三类,原进程的属性(root、radio、system等)与目标设备文件的属性不匹配,这种情况下我们映射会不起作用。这样的话,需要在init.rc 和ueventd.rc里面修改相应的属性:

我这边例子是查下来问题原因:

vmodem driver is not able openthe NVM partitions so default NVM values are expected. Issue is with permissionmis-match:
vmodem driver context is “radio”and block device nodes are “root”
由于mmcblk0p1是modem使用的Nvm Calculate Static,rpcServer无权限挂载,先将rpcServer和设备mmcblk0p1都设置设置成一样的radio属性:

ueventd.rc文件中:

/dev/block/mmcblk0p1 0660 radio radio

/dev/vmodem 0660 radio radio

init.rc和init.ptest.rc文件中,system/bin/rpcServer 的user、group的root属性改成radio:

chown radio radio /sys/class/misc/vmodem/modem_state 

service rpcServer /system/bin/rpcServer

socket msmSock stream 660 system radio

class core

user radio

group radio

然后添加kernel和rpcServer对mmcblk0p1 设备的权限:

在sepolicy/file_contexts定义mmcblk0p1 设备节点:/dev/block/mmcblk0p1
u:object_r:rpc_block_device:s0

在sepolicy/kernel.te:allowkernel rpc_block_device:blk_file
read;

在sepolicy/rpcServer.te:allow
rpcServer rpc_block_device:blk_file read;

其中上面两种情况解决套路是一样的,而第三种,需要根据不同的平台,对应的设备和进程属性来具体分析。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值