How Android obtains access to a kernel node in SELinux "Go"

Source: Internet
Author: User

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
    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 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
    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;
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
    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. # Chr_file indicates the character device file, if it is a normal file, directory please use Dir
    5. # rw_file_perms represents read and Write permissions
    6. 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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.