
comm="scan" ... scontext=u:r:system_app:s0 tcontext=u:object_r:device:s0 tclass=chr_file permissive=0
在 SELinux 里,tcontext 和 tclass 是访问控制决策的核心概念,我帮你梳理清楚:
tcontext(Target Context)scontext)访问某个资源(文件、设备、socket 等)时,这个资源有自己的 SELinux 类型标签,这就是 tcontext。
tcontext=u:object_r:device:s0u:object_r:device:s0 就是目标的 SELinux 上下文:
u → 用户身份(user)
object_r → 类型角色(role)
device → 类型(type)
s0 → MLS/MCS 安全级别
所以 tcontext 告诉 SELinux:你要访问的对象是 device 类型的字符设备。
tclass(Target Class)class,例如:
file → 普通文件
chr_file → 字符设备
dir → 目录
service_manager → 系统服务
tclass=chr_file表示 system_app 想访问的是一个 字符设备文件。
SELinux 决策依据:
allow <scontext> <tcontext>:<tclass> { <permissions> };scontext → 谁发起访问(process 的 context)
tcontext → 被访问对象的 context
tclass → 被访问对象的类型(class)
{ permissions } → 允许的操作(read/write/ioctl/open 等)
在你的例子中:
allow system_app device:chr_file { read write ioctl };就是允许 system_app 访问类型为 device 的字符设备,并执行 read/write/ioctl 操作。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。