Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Temporary disable or modify SELinux on Android

Tags:

I'm the developer on a root-app for Android.

Sadly now on some devices/ROMs there is SELinux in enforce-mode and prevents some actions of my app.

Because this is a root-app, the users are granting me root-access!

Now, SELinux is blocking some of my actions and I need to find a solution for this.

I tried to temporary disable SELinux by

setenforce permissive -> no failure, but getenforce still returns "Enforcing" echo 0 > /sys/fs/selinux/enforce -> no failure, but getenforce still returns "Enforcing" 

I play with the idea to edit the sepolicy-file at runtime to allow the blocked commands and trigger a reload of it, but I'm neither sure if & how this could work, nor isn't it a good idea.

Who has some more tips or resources for me?

like image 495
Martin L. Avatar asked Oct 06 '13 09:10

Martin L.


People also ask

How do I disable SELinux on Android?

Change the SELINUX value to SELINUX=disabled in the file /etc/selinux/config. Reboot the server. Reboot the server.

What happens if I disable SELinux?

The main difference between "Permissive" mode and disabling SELinux is that you will not get AVC log messages anymore and that SELinux will not keep files label up-to-date so you will need to relabel your files before enabling it again.

Is it possible to disable SELinux on Android?

I have been trying to disable SELinux on Android 4.3 for a while now and this is what i came up with. On Samsung S4 Android 4.3, setenforce 0 will change to Permissive mode. On Samsung Note 3 Android 4.3, setenforce 0 will NOT change SELinux status. I have tried Nexus 4 Android 4.3, however by default it is Permissive mode

How to enable SELinux temporarily?

Another method that can be use to enable SELinux temporarily is by using SELinux Kernel Parameters. You can pass value 1 to /sys/fs/selinux/enforce parameter to enable enforcing mode as shown in below command. Then you can again check if SELinux is Enabled or not using sestatus command.

How to change your Android SELinux mode to permissive?

Easily Change Your Android SELinux Mode To Permissive 1 Download and install SELinux Mode Changer from the Play Store onto your phone. 2 Run the application and set SELinux to Permissive 3 Restart the phone 4 Check the SELinux status in the About Device menu to see if it has changed. Note: This process will not only downgrade... More ...

Does setenforce 0 change SELinux status?

On Samsung S4 Android 4.3, setenforce 0 will change to Permissive mode. On Samsung Note 3 Android 4.3, setenforce 0 will NOT change SELinux status. I have tried Nexus 4 Android 4.3, however by default it is Permissive mode


2 Answers

You can use supolicy from the SuperSU app, see the link for a detailed description when and how it may be called.

In short:

  • Find out why something is blocked by SELinux by checking the audit messages, e.g. dmesg | grep "audit"
  • Create an allow ... rule that allows the blocked operation. They are similar (identical?) to 'allow' rules in SELinux *.te files.
  • Run supolicy --live "allow ..." in a root shell and check if the operation now succeeds. If not, extend your 'allow' rule(s). You can specify multiple 'allow' rules in a single supolicy call.

Note that supolicy is an expensive operation, so be sure to call it only once.

If you don't want to depend on Chainfire's SuperSU you may try sepolicy-inject. I did not test that myself.

like image 111
Martin Gerczuk Avatar answered Sep 28 '22 10:09

Martin Gerczuk


I have been trying to disable SELinux on Android 4.3 for a while now and this is what i came up with.

On Samsung S4 Android 4.3, setenforce 0 will change to Permissive mode.

On Samsung Note 3 Android 4.3, setenforce 0 will NOT change SELinux status.

I have tried Nexus 4 Android 4.3, however by default it is Permissive mode

like image 38
user1546570 Avatar answered Sep 28 '22 11:09

user1546570