安卓关闭SElinux(安卓关闭selinux好处)

http://www.itjxue.com  2023-01-24 18:53  来源:未知  点击次数: 

安卓代码能不能实现关闭SElinux权限

不可以

1.3 方法1:adb在线修改

关闭 seLinux:

打开seLinux:

Enforcing:seLinux已经打开;

Permissive:seLinux已经关闭;

1.4 方法2: 从kernel中彻底关闭 (用于开机初始化时的seLinux权限问题,要重编bootimage)

修改LINUX/android/kernel/arch/arm64/configs/XXXdefconfig文件(找相应config文件)

去掉CONFIG_SECURITY_SELINUX=y 的配置项

2. 在sepolicy中添加相应权限

2.1 修改依据:

log 信息:

avc: denied { 操作权限 } for pid=7201 comm=“进程名” scontext=u:r:源类型:s0 tcontext=u:r:目标类型:s0 tclass=访问类别 permissive=0

2.2 修改步骤:

找相应的“源类型.te ”文件

有两个位置可能存在相应的te文件:

位置一:LINUX/android/external/sepolicy

位置二:LINUX/android/device/qcom/sepolicy/common

2.3 按如下格式在该文件中添加:

allow 源类型 目标类型:访问类别 {权限};

2.4 举例

Kernel Log:

avc: denied { execheap } for pid=7201 comm="com.baidu.input" scontext=u:r:untrusted_app:s0tcontext=u:r:untrusted_app:s0tclass=processpermissive=0

修改:

在LINUX/android/external/sepolicy/untrusted_app.te 中添加:

[java] view plain copy

span style="font-size:24px;color:#009900;"allow untrusted_app untrusted_app:process { execheap };/span

备注:

在这个例子中,由于源类型和目标类型都是untreated_app, 所以也可以写成:

[java] view plain copy

span style="font-size:24px;color:#009900;"allow untrusted_app self:process { execheap };/span

3. 添加权限后的neverallowed冲突

3.1 编译报错:

libsepol.check_assertion_helper: neverallow on line xxx ofexternal/sepolicy/domain.te ……

3.2 原因:

新添加的sepolicy项目违反了domain.te 中规定的的总策略原则。所以该条权限策略不能添加,如果强行添加的话有CTS测试失败的风险。

3.3 解决方法:

1.从运行log中找到要访问的目标名称,一般是name字段后的名称

avc: denied { read write } for pid=303 comm="mediaserver"name="tfa9890"dev="tmpfs" ino=3880 scontext=u:r:mediaserver:s0tcontext=u:object_r:device:s0tclass=chr_file permissive=0

2.找到相应的*_contexts文件。

一般有file_contexts, genfs_contexts, property_contexts, service_contexts 等文件

3.在contexts文件中指定要访问的目标为一个“源类型 ”有权限访问的“目标类型”

如:在file_contexts中添加: /dev/tfa9890 u:object_r:audio_device:s0

3.4 举例

添加权限:

在mediaserver.te中添加allow mediaserver device:chr_file { read write open};

编译报错:

libsepol.check_assertion_helper: neverallow on line 258 ofexternal/sepolicy/domain.te (or line 5252 of policy.conf) violated byallow mediaserver device:chr_file { read write open};

违反了domain.te 258的:

neverallow {domain –unconfineddomain –ueventd } device:chr_file { open read write}

运行Log:

avc: denied { read write } for pid=303 comm="mediaserver"name="tfa9890" dev="tmpfs" ino=3880 scontext=u:r:mediaserver:s0 tcontext=u:object_r:device:s0tclass=chr_file permissive=0

修改步骤:

1.目标名称是: tfa9890, 其在系统中的路径是: /dev/tfa9890, 是audio相关的设备文件

2.源类型是mediaserver, 在mediaserver.te 文件中发现其具有 audio_device 目标类型的权限

3.所以在file_contexts 中添加 “/dev/tfa9890 u:object_r:audio_device:s0” 可以解决问题

手机关闭selinux面具模块

Eastsea.Chen

码龄12年

关注

有些时候我们添加的外设和接口太多或者我们添加访问了一些系统规则不允许我们访问的资源,我们需要关闭selinux以达到可以正常访问系统资源。

system\core\init\selinux.cpp

bool IsEnforcing() {

return false;//直接返回false

if (ALLOW_PERMISSIVE_SELINUX) {

return StatusFromProperty() == SELINUX_ENFORCING;

}

return true;

}

如果是user版本还需要再kernel的config文件添加以下的配置,否则无法开机

CONFIG_SECURITY_SELINUX_DEVELOP=y

这样子selinux访问权限可以关闭掉了

不过如果访问节点节点还会存在权限问题,在.rc文件中设置节点的权限和组

文章知识点与官方知识档案匹配

安卓关闭selinux好处

你好朋友

1. 禁止selinux

1.1 在内核中关闭selinux编译选项CONFIG_SECURITY_SELINUX

1.2 还可以在system.prop中定义ro.boot.selinux=disable

这两种方法都可以禁用selinux,也可以设置成ro.boot.selinux=permissive

宽容模式

1.3 可以通过setenforce 1 开启enforce模式,setenforce 0 为permissive模式

getenforce获取当前模式

2. 所有安全策略最终编译成sepolicy文件放在root目录下,init进程启动后会读取/sepolicy策略文件,并通过/sys/fs/selinux/load节点

把策略文件内容写入内核

3 安全上下文存放root目录

/etc/security/mac_permissions.xml

/file_contexts //系统中所有file_contexts安全上下文

/seapp_contexts //app安全上下文

/property_contexts //属性的安全上下文

/service_contexts //service文件安全上下文

genfs_contexts //虚拟文件系统安全上下文

4. app在/data/data/文件的安全上下文设置过程

1. 根据uid,pkgname,seinfo在seapp_contexts中匹配.

2. 根据匹配到的contexts,重新设置给相对应文件

5. 系统中所有的object class 定义在external/sepolicy/security_classes中.

object class使用在allow语句中,object class所具有的操作定义在external/sepolicy/access_vectors

文件中

6 allow语句

allow语句用来权限设置

rule_name source_type target_type : class perm_set

rule_name : 有allow,neverallow

source_type : 权限主体,表示source_type对target_type有perm_set描述的权限

如:

allow zygote init:process sigchld

允许zygote域里面的进程可对init域的进程发送sigchld信号

typeattribute表示把属性和type关联起来

7 role定义

Android系统中的role定义在external/sepolicy/roles中,

目前只定义了r

8 socket 使用

以/data/misc/wifi/sockets/wlan0 socket来说明使用方法

1. 定义socket type

type wpa_socket ,file_type

2. 指定安全上下文

/data/misc/wifi/sockets(/.*)? u:object_r:wpa_socket:s0

给/data/misc/wifi/sockets目录下所有的文件统一指定安全上下文为wpa_socket

3.声明socket使用权限

在进程te中使用unix_socket_send(clientdomain, wpa, serverdomain)即可建立socket连接

9 binder使用

在使用binder 进程的te中根据情况使用如下宏:

binder_use(domain)//允许domain域中的进程使用binder通信

binder_call(clientdomain, serverdomain) //允许clientdomain和serverdomain域中的进程通信

binder_service(domain) //标志domain为service端

10 文件的使用

以/dev/wmtWifi来说明:

1.定义type

type wmtWifi_device dev_type //dev_type用来标志/dev/下的文件

2.给/dev/wmtWifi指定完全上下文

/dev/wmtWifi(/.*)? u:object_r:wmtWifi_device:s0

3.进程权限设置

在进程te文件中allow权限

allow netd wmtWifi_device:chr_file { write open };

11 property 属性设置

以蓝牙的各种属性来说明

1.定义type

type bluetooth_prop, property_type;

2 设置安全上下文

bluetooth. u:object_r:bluetooth_prop:s0

3 进程权限设置

allow bluetooth bluetooth_prop:property_service set;

5 专业词汇

MLS :Multi-Level Security

RBAC :Role Based Access Control

DAC :Discretionary Access Control

MAC :Mandatory Access Control

TEAC :Type Enforcement Accesc Control

望采纳祝你好运

小米selinux宽容模式关闭

selinux和如何关闭selinux。#linux专栏#

?

SELinux是安全增强型linux系统,它是一个linux内核模块,也是linux的一个安全子系统。

SELinux一共有3种状态,分别是Enforcing,Permissive和Disabled状态。

Enforcing:强制模式。代表SELinux在运行中,且已经开始限制domain/type之间的验证关系。

Permissive:宽容模式。代表SELinux在运行中,不过不会限制domain/type之间的验证关系,即使验证不正确,进程仍可以对文件进行操作。不过如果验证不正确会发出警告。

Disabled:关闭模式。SELinux并没有实际运行可以通过setenforce命令来设置前面两种状态,而如果想修改为disable状态,需要修改配置文件,同时重启系统。

那么该如何关闭selinux呢?我们编辑/etc/selinux/config配合文件,修改selinux的状态为disabled即可。

Android查看SELinux状态及关闭SELinux

selinux默认配置在/etc/sysconfig/selinux里。

通过getenforce查看selinux的运行级别。

通过 setenforce 0 或者 1 设置selinux的运行级别。

(责任编辑:IT教学网)

更多