I created a kernel driver as a loadable module for one of my I2C devices. The driver creates several sysfs files in the corresponding I2C folder (/sys/devices/i2c/i2c-0/0-0008/)
, using the instance through the new_device file (/sys/devices/i2c/i2c-0/new_device)
.
Lollipop forcibly uses SELinux, so I need to create rules for my applications that need access to the device sysfs file. These are mainly system applications (they fall into the platform_app definition in Android SELinux). The problem is that applications in any application domain are not allowed to write sysfs files:
neverallow { appdomain -bluetooth -nfc } sysfs:dir_file_class_set write;
Therefore, I decided to create a file context exclusively for my device:
file_context: /sys/devices/i2c-0/0-0008(/.*)? u:object_r:sysfs_mydeviceic:s0
The result is interesting: the default driver files and folders, such as name and uevent, etc., get the correct context, but not the files created by the sysfs part of the I2C driver:
root@android :/sys/devices/i2c-0/0-0008
I am looking for help how to continue this problem: if I still want to convert the sysfs context to sysfs_mydeviceic for the rest of the files, then how to do it? Or is there another way to enable applications to write to sysfs files?
source share