How to close Selinux in android11

adb shell getenforce Check whether the current Selinux function is permissive (closed) or enforce (open)    
adb shell setenforce 0 open Selinux: set to permissive mode    
adb shell setenforce 1 close Selinux: set to mode enforce    

Android 11

diff --git a/alps/system/core/init/selinux.cpp b/alps/system/core/init/selinux.cpp
index ce8348e..1b87d60 100644
--- a/alps/system/core/init/selinux.cpp
+++ b/alps/system/core/init/selinux.cpp
@@ -104,6 +104,8 @@ EnforcingStatus StatusFromCmdline() {
 }
 
 bool IsEnforcing() {
+       return false;
+       
     if (ALLOW_PERMISSIVE_SELINUX) {
         return StatusFromCmdline() == SELINUX_ENFORCING;
     }

Extended, other version methods:

Android 10

bool IsEnforcing() {
    {
        int fd(open("/mboot/selinux", O_RDONLY | O_CLOEXEC | O_BINARY));
        if (fd != -1) {
            char v = 0xff;
            if (read(fd, &v, 1) < 0)
                PLOG(ERROR) << "Failed to read /mboot/selinux";
            close(fd);
            LOG(WARNING) << "/mboot/selinux is " << v;
            return v == '1';
        }
    }
    + return false; //add to close selinux
    if (ALLOW_PERMISSIVE_SELINUX) {
        return StatusFromCmdline() == SELINUX_ENFORCING;
    }
    return true;
}

Android 9.0

/system/core/init/selinux.cpp

bool IsEnforcing() {
+ return false; //add to close selinux
  if (ALLOW_PERMISSIVE_SELINUX) {
    return StatusFromCmdline() == SELINUX_ENFORCING;
   }
  return true;
}

Android 8.1

/system/core/init/init.cpp

static bool selinux_is_enforcing(void)
{
+  return false; //add to close selinux
   if (ALLOW_PERMISSIVE_SELINUX) {
     return selinux_status_from_cmdline() == SELINUX_ENFORCING;
}

Android 4.4

/system/core/init/init.c

static bool selinux_is_enforcing(void)
{
    char tmp[PROP_VALUE_MAX];
+   return false;//add to close selinux
    if (property_get("ro.boot.selinux", tmp) == 0) {
        /* Property is not set.  Assume enforcing */
        return true;
    }
    if (strcmp(tmp, "permissive") == 0) {
        /* SELinux is in the kernel, but we've been told to go into permissive mode */
        return false;
    }
    if (strcmp(tmp, "enforcing") != 0) {
        ERROR("SELinux: Unknown value of ro.boot.selinux. Got: \"%s\". Assuming enforcing.\n", tmp);
    }
    return true;
}

Guess you like

Origin blog.csdn.net/lwz622/article/details/122014647