te文件语法
type: 用于定义一个 SELinux 类型,语法为 type <typename>, <sensitivity>;
typeattribute: 用于定义类型属性,语法为 typeattribute <typename> <attribute1,attribute2...>;
typealias: 用于定义类型别名,语法为 typealias <aliasname>, <realname>;
common: 用于定义共享属性,语法为 common <typename>;
allow: 用于定义允许访问的规则,语法为 allow <sourcetype> <targettype>:<class> { permissions };
根据selinux提示的权限报错,添加对应权限,log格式:
avc: denied { 操作权限 } for pid=7201 comm=“进程名” scontext=u:r:源类型:s0 tcontext=u:r:目标类型:s0 tclass=访问类型 permissive=0
规则格式:
allow 源类型 目标类型:访问类型 {操作权限};
auditallow: 用于定义审核允许的规则,语法为 auditallow <sourcetype> <targettype>:<class> { permissions };
neverallow: 用于定义永远不允许的规则,语法为 neverallow <sourcetype> <targettype>:<class> { permissions };
dontaudit: 用于定义不进行审核的规则,语法为 dontaudit <sourcetype> <targettype>:<class> { permissions };
type_transition: 用于定义类型转换规则,语法为 type_transition <sourcetype> <targettype>:<class>;
myshell.te例程
type myshell, domain;
type myshell_exec, exec_type, vendor_file_type, file_type;
init_daemon_domain(myshell)
allow myshell vendor_shell_exec:file { rx_file_perms };
allow myshell vendor_toolbox_exec:file { rx_file_perms };
allow myshell console_device:chr_file { open write };
allow myshell myshell:capability { sys_module };
allow myshell vendor_file:system { module_load };
//myshell.te 定义了 myshell 服务的 SELinux 上下文类型。
//type 命令用于为服务定义一个新的 SELinux 上下文类型,并指定该服务所属的域(domain)。在该命令中,myshell 是服务的名称,domain 是服务的 SELinux 域名。
//type myshell_exec 定义了 myshell 服务的执行上下文类型。exec_type 表示该上下文类型是可执行文件类型,vendor_file_type 和 file_type 表示该上下文类型是厂商文件类型和普通文件类型。
//init_daemon_domain(myshell) 命令用于将 myshell 服务的 SELinux 域名与 init 进程绑定。这意味着当系统启动时,init 进程将会启动 myshell 服务,并将其置于 myshell 域中。
audit2allow工具
sudo apt install policycoreutils
adb shell logcat | grep avc > avc_log.txt
audit2allow -i avc_log.txt