SELinux,android自启动自定义程序

rc文件仿照代码:

service test_que /vendor/bin/test_que

user root

group system

oneshot

seclabel u:r:test_que:s0

on boot

start test_que

Android.bp文件仿照:

init_rc: ["test_que.rc"],

product.package.mk文件仿照:

rc文件中定义的模块名字

test_que.rc


te文件有可能的位置:

/home/qyd/h812/device/mediatek/wembley-sepolicy/plat_private

te文件格式模板:

allow test_que socket_device:dir write;

allow test_que tmpfs:lnk_file read;

allow test_que media_rw_data_file:dir {read open};

allow test_que storage_file:lnk_file read;

allow test_que sysfs:file {open read};

allow test_que devpts:chr_file setattr;

allow test_que device:dir {add_name write};

allow test_que device:lnk_file create;

allow test_que serial_device:chr_file {open ioctl read write};

type test_que domain;

type test_que_exec, exec_type, file_type;

init_daemon_domain(test_que)

file_context文件中加的代码:

/vendor/bin/test_que u:test_que_exec:s0

.te文件是做什么的?

.te 文件是用于 SELinux(Security-Enhanced Linux)策略的一个关键文件类型。SELinux 是一种安全模块化的 Linux 安全机制,可以在操作系统级别对进程和资源进行访问控制。

.te 文件包含了 SELinux 策略中的类型声明、权限规则和访问控制规则。它们定义了对于每个安全上下文(security context)的对象或主体,可以执行哪些操作和访问哪些资源。

.te 文件是使用 SELinux 策略语言编写的,该语言具有自己的语法和规则。这些文件通常需要经过编译器的处理,生成二进制的策略模块文件(.pp 文件),然后将其加载到 SELinux 中。

通过修改和编写 .te 文件,可以定义和自定义 SELinux 策略,以实现对系统的细粒度访问控制和安全性增强。

需要注意的是,修改 SELinux 策略文件需要谨慎操作,因为错误的修改可能导致系统不稳定或无法正常工作。在进行任何修改之前,请确保对 SELinux 的工作原理和相关规则有足够的了解,并且备份重要的系统文件。

file_contexts 文件是 SELinux(Security-Enhanced Linux)策略的一个关键文件,用于指定文件系统中每个文件或目录的安全上下文(security context)。

在 SELinux 系统中,每个进程和文件都被赋予一个安全上下文,用于确定它们可以访问的资源和执行的操作。file_contexts 文件中列出了每个文件和目录的路径和对应的安全上下文,以及可选的标签。

当文件或目录被创建或修改时,SELinux 将会使用 file_contexts 文件中的规则来设置对应的安全上下文。这样可以确保文件或目录的安全性,并限制对它们的访问和操作。

除了默认的 file_contexts 文件之外,还可以创建自定义的 .fc 文件,并将其加载到 SELinux 策略中,用于定义特定的文件或目录的安全上下文。这样可以更灵活地配置 SELinux 策略,并满足不同场景下的安全需求。

需要注意的是,修改 file_contexts 文件需要谨慎操作,因为错误的修改可能导致系统不稳定或无法正常工作。在进行任何修改之前,请确保对 SELinux 的工作原理和相关规则有足够的了解,并且备份重要的系统文件。

相关推荐
沧浪之水!7 分钟前
【Linux网络】:套接字之UDP
linux·网络·udp
BranH8 分钟前
Linux系统中命令设定临时IP
linux·运维·服务器
秋风起,再归来~26 分钟前
【Linux庖丁解牛】—进程优先级!
linux·运维·服务器
投笔丶从戎38 分钟前
Kotlin Multiplatform--01:项目结构基础
android·开发语言·kotlin
cosX+sinY1 小时前
ubuntu 20.04 编译运行lio-sam,并保存为pcd
linux·ubuntu·机器人
Lary_Rock2 小时前
Android 编译问题 prebuilts/clang/host/linux-x86
android·linux·运维
熬夜学编程的小王2 小时前
【Linux篇】理解信号:如何通过信号让程序听从操作系统的指令
linux·信号产生·软件条件产生信号
绵绵细雨中的乡音2 小时前
Linux进程学习【基本认知】
linux·运维·学习
Johny_Zhao2 小时前
MySQL 高可用集群搭建部署
linux·人工智能·mysql·信息安全·云计算·shell·yum源·系统运维·itsm