zoukankan      html  css  js  c++  java
  • Android 5.x SEAndroid/SElinux内核节点的读写权限【学习笔记】

    本文转载自:http://blog.csdn.net/tung214/article/details/44461985

    Android 5.0下,因为采取了SEAndroid/SElinux的安全机制,即使拥有root权限,或者对某内核节点设置为777的权限,仍然无法在JNI层访问。

    本文将以用户自定义的内核节点/dev/wf_bt为例,手把手教会读者如何在JNI层获得对该节点的访问权限。
     
    第一步:找到需要访问该内核节点的进程(process),笔者自己这个节点由system_server进程来访问
     
    第二步:打开文件AndroidL/android/external/sepolicy/file_contexts.be
    仿照这个文件里的写法,为你的节点定义一个你想要的名字:
    [python] view plain copy
     
    1. /dev/tegra.* u:object_r:video_device:s0  
    2. /dev/tf_driver u:object_r:tee_device:s0  
    3. /dev/tty u:object_r:owntty_device:s0  
    4. /dev/tty[0-9]* u:object_r:tty_device:s0  
    5. # We add here  
    6. /dev/wf_bt              u:object_r:wf_bt_device:s0  
    wf_bt_device是自定义,其他左右两边的内容都和上面的范例一致。
     
    第三步:打开文件AndroidL/android/external/sepolicy/device.te
    仿照这个文件里的写法,将刚刚第二步写的wf_bt_device声明为dev_type:
    [python] view plain copy
     
    1. # Device types  
    2. type device, dev_type, fs_type;  
    3. type alarm_device, dev_type, mlstrustedobject;  
    4. type adb_device, dev_type;  
    5. type ashmem_device, dev_type, mlstrustedobject;  
    6. type audio_device, dev_type;  
    7. type binder_device, dev_type, mlstrustedobject;  
    8. type block_device, dev_type;  
    9. # We add here  
    10. type wf_bt_device, dev_type;  
    第四步:
    AndroidL/android/external/sepolicy/目录下很多.te文件都是以进程名来结尾的,比如有针对surfaceflinger进程的surfaceflinger,有针对vold进程的vold.te,
    刚刚从第一步得到,这个节点是由system_server进程来访问,所以,我们找到system_server.te打开,加入允许这个进程对/dev/wf_bt的读写权限,
     
    [python] view plain copy
     
    1. # Read/Write to /proc/net/xt_qtaguid/ctrl and and /dev/xt_qtaguid.  
    2. allow system_server qtaguid_proc:file rw_file_perms;  
    3. allow system_server qtaguid_device:chr_file rw_file_perms;  
    4.   
    5. # chr_file表示字符设备文件,如果是普通文件用file,目录请用dir  
    6. # rw_file_perms代表读写权限  
    7. allow system_server wf_bt_device:chr_file rw_file_perms;  
    这句话的意思是:允许system_server进程拥有对wf_bt_device的这个字符设备的读写权限。
    改了这些之后,你就可以make installclean;make -j16编译image来验证权限是否获取成功。
     
    fd =open("/dev/wf_bt",O_RDONLY | O_NOCTTY); 绝对成功!!!!!
     
    鸣谢:感谢Joly_xie
  • 相关阅读:
    [转] 余国藩:人文学科何以不是科学
    [openssl][nginx] 使用openssl模拟ssl/tls客户端测试nginx stream
    [openssl] 使用openssl生成证书
    [bluez] linux下蓝牙鼠标的延迟问题
    很好的一篇文章讲epoll
    [ipsec][strongswan] VirtualPN隧道网络加速FEC(forward error correction)
    [ipsec][crypto] ike/ipsec与tls的认证机制比较
    [ipsec][crypto] 有点不同的数字证书到底是什么
    [ike][ipsec] child sa rekey机制的细节分析
    [dev][nginx] 在阅读nginx代码之前都需要准备什么
  • 原文地址:https://www.cnblogs.com/zzb-Dream-90Time/p/6964268.html
Copyright © 2011-2022 走看看