Android 5.x seandroid/selinux kernel node read and Write permissions "learning notes"

Source: Internet
Author: User

This article was reproduced from: http://blog.csdn.net/tung214/article/details/44461985

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_BTAs 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 myself This node is accessed by the System_server process for the second step: Open File Androidl/android/external/sepolicy/file_ contexts.be follow the notation in this file to define a 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. The third step: Open the file Androidl/android/external/sepolicy/device.te in the same style as in this file, the second step has just written Wf_bt_device 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: androidl/android/external/sepolicy/ Many. te files in the directory end with the process name, such as Surfaceflinger for the Surfaceflinger process, with Vold.te for the vold process, just from the first step, the node is accessed by the System_server process, So, we find system_server.te open, join to allow this process to read and write permission to/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;
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!!!!! Acknowledgement: Thank Joly_xie

Android 5.x seandroid/selinux kernel node read and Write permissions "learning notes"

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.