Android Selinux 修改使system_app可以打开/dev/videoX(一)

一 查看文件的Selinux属性

    ls -Zd /dev/

drwxr-xr-x root     root              u:object_r:device:s0

    则/dev文件夹在android selinux中的domain是device

    ls -Z /dev/video0                                             
crw-rw---- system   camera            u:object_r:video_device:s0 video0

    则/dev/video0在android selinux中的domain是video_device

 

二 查看自己的app进程的Selinux属性

    ps -Z | grep XXX

u:r:system_app:s0              system    13218 308   xxx.xxx.xxx

    可以看到自己的app进程id为「system」, 在android selinux中的domain是system_app

 

三 查看自己的app在访问/dev/video0时被selinux阻止的规则

    点开自己的app(里面有打开/dev/video0的操作)

    adb shell su root dmesg | grep 'avc: ' 或者直接在logcat中,就可以看到相应的selinux阻止操作的打印

    <14>[  274.162831] type=1400 audit(10202.409:93): avc: denied { getattr } for pid=2233 comm=".xxx.xxx" path="/dev/video2" dev="tmpfs" ino=8650 scontext=u:r:system_app:s0 tcontext=u:object_r:video_device:s0 tclass=chr_file permissive=0


    <14>[  274.162959] type=1400 audit(10202.409:94): avc: denied { read } for pid=2252 comm=".xxx.xxx" name="/" dev="tmpfs" ino=9783 scontext=u:r:system_app:s0 tcontext=u:object_r:device:s0 tclass=dir permissive=0


    我这里有两个操作被阻止了

    1. 对/dev/video2的getattr操作

        denied { getattr }: 表明是getattr操作

        path="/dev/video2": 表明是对/dev/video2的操作

        scontext=u:r:system_app: 表明subject 的domain 是system_app

        tcontext=u:object_r:video_device: 表明 target 的doumain 是 video_device

        tclass=chr_file : 表明 target 的class 是chr_file

    2. 对/dev文件夹的open操作

        分析见上

 

四 那么如何修改sepolicy 使得权限对system_app放开呢

    因为我有boot.img所以直接修改ramdisk里的sepolicy

    1 解压boot.img

    2 使用xda 上提供的工具:selinux-inject修改sepolicy

       a) selinux-inject: http://forum.xda-developers.com/android/software/setools-android-sepolicy-inject-t2977563

       b) 修改规则:

       -s 是subject

       -t 是target

       -c 是class

       -p 是要添加的allow 的规则

       ./sepolicy-inject -s system_app -t video_device -c file -p getattr -P sepolicy2 -o sepolicy2    // 使得system_app对video_device有getattr权限

      ./sepolicy-inject -s system_app -t device -c dir -p open -P sepolicy2 -o sepolicy2     // 使得system_app对/dev有open权限

       sesearch -A -s system_app -t device -c dir sepolicy2

       sesearch -A -s system_app -t video_device -c chr_file sepolicy2    // 用来查看权限是否改成功了

    3 压缩回boot.img

    4 fastboot flash boot new_boot.img

       fastboot reboot

 

 

 


      

转载于:https://www.cnblogs.com/blowing-in-the-wind/p/5684942.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值