Android 在 SElinux下 如何获得对一个内核节点的访问权限
2016-03-28 11:41
471 查看
版权声明:本文为博主原创文章,未经博主允许不得转载。
Android 5.0下,因为采取了SEAndroid/SElinux的安全机制,即使拥有root权限,或者对某内核节点设置为777的权限,仍然无法在JNI层访问。
本文将以用户自定义的内核节点/dev/wf_bt为例,手把手教会读者如何在JNI层获得对该节点的访问权限。
第一步:找到需要访问该内核节点的进程(process),笔者自己这个节点由system_server进程来访问
第二步:打开文件AndroidL/android/external/sepolicy/file_contexts.be
仿照这个文件里的写法,为你的节点定义一个你想要的名字:
[python] view
plaincopy
/dev/tegra.* u:object_r:video_device:s0
/dev/tf_driver u:object_r:tee_device:s0
/dev/tty u:object_r:owntty_device:s0
/dev/tty[0-9]* u:object_r:tty_device:s0
# We add here
/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
plaincopy
# Device types
type device, dev_type, fs_type;
type alarm_device, dev_type, mlstrustedobject;
type adb_device, dev_type;
type ashmem_device, dev_type, mlstrustedobject;
type audio_device, dev_type;
type binder_device, dev_type, mlstrustedobject;
type block_device, dev_type;
# We add here
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
plaincopy
# Read/Write to /proc/net/xt_qtaguid/ctrl and and /dev/xt_qtaguid.
allow system_server qtaguid_proc:file rw_file_perms;
allow system_server qtaguid_device:chr_file rw_file_perms;
# chr_file表示字符设备文件,如果是普通文件用file,目录请用dir
# rw_file_perms代表读写权限
allow system_server wf_bt_device:chr_file rw_file_perms; // 允许system_server进程拥有对wf_bt_device的这个字符设备的读写权限;
这句话的意思是:允许system_server进程拥有对wf_bt_device的这个字符设备的读写权限。
改了这些之后,你就可以make installclean;make -j16编译image来验证权限是否获取成功。
fd =open("/dev/wf_bt",O_RDONLY | O_NOCTTY); 绝对成功!!!!!
=====================================
allow system_server wf_bt_device:chr_file rw_file_perms; //允许system_server进程拥有对wf_bt_device的这个字符设备的读写权限。
原文:http://blog.csdn.net/wh_19910525/article/details/45170755
Android 5.0下,因为采取了SEAndroid/SElinux的安全机制,即使拥有root权限,或者对某内核节点设置为777的权限,仍然无法在JNI层访问。
本文将以用户自定义的内核节点/dev/wf_bt为例,手把手教会读者如何在JNI层获得对该节点的访问权限。
第一步:找到需要访问该内核节点的进程(process),笔者自己这个节点由system_server进程来访问
第二步:打开文件AndroidL/android/external/sepolicy/file_contexts.be
仿照这个文件里的写法,为你的节点定义一个你想要的名字:
[python] view
plaincopy
/dev/tegra.* u:object_r:video_device:s0
/dev/tf_driver u:object_r:tee_device:s0
/dev/tty u:object_r:owntty_device:s0
/dev/tty[0-9]* u:object_r:tty_device:s0
# We add here
/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
plaincopy
# Device types
type device, dev_type, fs_type;
type alarm_device, dev_type, mlstrustedobject;
type adb_device, dev_type;
type ashmem_device, dev_type, mlstrustedobject;
type audio_device, dev_type;
type binder_device, dev_type, mlstrustedobject;
type block_device, dev_type;
# We add here
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
plaincopy
# Read/Write to /proc/net/xt_qtaguid/ctrl and and /dev/xt_qtaguid.
allow system_server qtaguid_proc:file rw_file_perms;
allow system_server qtaguid_device:chr_file rw_file_perms;
# chr_file表示字符设备文件,如果是普通文件用file,目录请用dir
# rw_file_perms代表读写权限
allow system_server wf_bt_device:chr_file rw_file_perms; // 允许system_server进程拥有对wf_bt_device的这个字符设备的读写权限;
这句话的意思是:允许system_server进程拥有对wf_bt_device的这个字符设备的读写权限。
改了这些之后,你就可以make installclean;make -j16编译image来验证权限是否获取成功。
fd =open("/dev/wf_bt",O_RDONLY | O_NOCTTY); 绝对成功!!!!!
=====================================
allow system_server wf_bt_device:chr_file rw_file_perms; //允许system_server进程拥有对wf_bt_device的这个字符设备的读写权限。
原文:http://blog.csdn.net/wh_19910525/article/details/45170755
相关文章推荐
- Linux内核-链表
- Centos中安装VMware 12
- 通用 CentOS 6 服务器安全配置指南
- linux awk命令
- centos7下更改java环境
- 一天一个linux命令,这篇文章不错,大家可以看看
- Linux文本处理工具集锦
- centos中mysql无法显示中文问题
- linux 进程通信 IPC
- linux watchdog demo hacking
- CentOS 7 /RHEL 7: How To Change The System Locale
- 配置Linux日志文件
- linux下的 fork vfork和clone函数
- linux随生成机数
- Linux ulimit 系统资源控制
- linux 下 pac 使用
- linux 下 pac 使用
- Linux date命令
- Linux配置SSH免密码登陆
- linux 多线程的实现的基本原理