Android下使用chcon修改文件的安全上下文(file_contexts)

            在init.rc中运行某一可执行程序时,需要修改selinux规则,否则会提示要为该服务添加selinux角色。其中的一步是在file_contexts

添加节点或文件的安全安全上下文,如device/qcom/sepolicy/common/file_contexts

/dev/coresight-tmc-etr-stream                   u:object_r:qdss_device:s0
/dev/system_health_monitor                      u:object_r:system_health_monitor_device:s0
/dev/qce                                        u:object_r:qce_device:s0
/dev/msm-rng                                    u:object_r:rng_device:s0
/dev/qbt1000                                    u:object_r:qbt1000_device:s0
/dev/at_.*                                      u:object_r:at_device:s0
/dev/sg.*                                       u:object_r:sg_device:s0/system/bin/audiod                             
/system/bin/charger_monitor                     u:object_r:charger_monitor_exec:s0
/system/bin/hvdcp_opti                          u:object_r:hvdcp_exec:s0
/system/bin/cnd                                 u:object_r:cnd_exec:s0
/system/bin/diag_callback_client                u:object_r:diag_exec:s0

修改后,编译并烧写boot.img,用ls -Z查看文件的安全信息,发现是u:object_r:system_file:s0,但我的的目的是改成u:ubject_r:xxx_exec:s0,

说明我的修改没有生效。但通过adb push该文件到系统是,我的目的就达到了。想起了Android生成system.img时有用到flle_contexts这个

参数,file_contexts可能还涉及system.img,继续烧写system.img,目标实现了。也就是说,不仅要修改file_contexts文件,还要将该文件

放到out目录下的system文件夹下进行编译,同时烧写boot.img和system才能修改该文件的安全上下文。但在recovery下通过其他方式(非

OTA)替换该文件时,该文件又变成了system_file,这时可使用chcon手工修改该文件的file_contexts,如chcon u:object_r:xxx_exec:s0 xxx,

具体用法可参考(http://www.jianshu.com/p/a3572eee341c)

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值