android11 关闭 Selinux 的方法

adb shell getenforce    查看当前 Selinux 功能是 permissive(关闭)还是 enforce(打开)的    
adb shell setenforce 0    开Selinux:设置成模式permissive    
adb shell setenforce 1    关Selinux:设置成模式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;
     }

扩展,其他版本方法:

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;
}

Andorid 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;
}

你可能感兴趣的:(服务器,linux,centos)