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 的工作原理和相关规则有足够的了解,并且备份重要的系统文件。

相关推荐
小政同学35 分钟前
【NFS故障】共享的文件无法执行
linux·运维·服务器
AI木马人1 小时前
3.【Prompt工程实战】如何设计一个可复用的Prompt系统?(避免每次手写提示词)
linux·服务器·人工智能·深度学习·prompt
ch3nyuyu1 小时前
Ubuntu(乌班图)基础指令
linux·运维·网络
鹏晨互联1 小时前
《Android 自定义 WebView 组件:从封装到路由,打造灵活可复用的混合开发利器》
android
程序员陆业聪2 小时前
AI Code Review:让每一行代码都有AI审查员
android
minglie12 小时前
gcc编译器汇总
linux
程序员陆业聪2 小时前
AI Bug修复与测试生成:从崩溃日志到修复PR的自动化 | AI提效Android开发(5)
android
诸神黄昏EX2 小时前
Android Google Widevine
android
白菜欣3 小时前
Linux —《开发三件套:gcc/g++、gdb、make/Makefile 全解析》
linux·运维
senijusene4 小时前
基于 imx6ull平台按键驱动开发:input子系统+中断子系统+platform总线
linux·驱动开发