Search code examples
androidandroid-ndkjava-native-interface

Android privileged app gets permission denied when writing to sysfs in JNI


I'm running into an issue where my system app (residing in /system/priv-app/) runs into a 'errno 13' when trying to open a sysfs node through JNI. The node is owned by "system:system". I can see that the app itself is running with system ID but I don't understand why it would run into permissions problems.

The sysfs node the app is trying to access is /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq

Any ideas would be appreciated! Thanks.


Solution

  • It looks like there are multiple levels of permissions we have to be aware of.

    • Android manifest permissions
    • Linux filesystem permissions
    • SELinux policies

    I had the first two, however I was missing the sepolicy for this particular sysfs node. Though this is unique to my custom ROM and shouldn't apply to most android developers...

    More can be read here: https://source.android.com/security/selinux/