This article was reproduced from: http://blog.csdn.net/u012719256/article/details/52585956
Android 5.0, because of the seandroid/selinux security mechanism, even if you have root privileges, or a kernel node set to 777 of the permissions, still cannot be accessed at the JNI layer.
This article will use a user-defined kernel node
/dev/wf_bt As an example, hands-on teaches the reader how to gain access to the node in the JNI layer. The first step: find the process that needs to access the kernel node, the author own this node by
System_serverProcess to access the second step: Open File androidl/android/external/sepolicy/
file_contexts.beFollow the notation in this file to define the name you want for your node:
[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 is custom, and the other left and right sides of the content are consistent with the example above. Step three: Open File androidl/android/external/sepolicy/
Device.teFollowing the writing in this document, the second step of the Wf_bt_device is declared as 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;
Fourth step: Under the androidl/android/external/sepolicy/directory
many. te files end with a process name, for example, there are surfaceflinger for the surfaceflinger process, there are vold.te for the vold process, just from the first step, this node is accessed by the System_server process, so we found
System_server. Te opens to allow this process to read and write access to the/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 indicates the character device file, if it is a normal file, directory please use Dir
- # rw_file_perms represents read and Write permissions
- Allow system_server wf_bt_device:chr_file rw_file_perms; Allows the system_server process to have read and write access to the Wf_bt_device character device;
This means that the system_server process is allowed to have read and write access to the Wf_bt_device character device. After you change this, you can make installclean;make-j16 compile the image to verify that the permissions are successful. FD =open ("/dev/wf_bt", O_rdonly | O_noctty); ABSOLUTE SUCCESS!!!!!
=====================================
Allow system_server wf_bt_device:chr_file rw_file_perms;Allows the system_server process to have read and write access to this character device for Wf_bt_device.
How Android obtains access to a kernel node in SELinux "Go"