Android 12中配置Selinux相关权限问题

1. 从logcat中过滤avc信息

avc: denied { read write } for comm="vendor.demo" name="ttyHW5" dev="tmpfs" ino=610 scontext=u:r:hal_gnss_default:s0 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1
avc: denied { ioctl } for comm="vendor.demo" path="/dev/ttyHW5" dev="tmpfs" ino=610 ioctlcmd=0x5401 scontext=u:r:hal_gnss_default:s0 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1
avc: denied { ioctl } for comm="vendor.demo" path="/dev/ttyHW5" dev="tmpfs" ino=610 ioctlcmd=0x5401 scontext=u:r:hal_gnss_default:s0 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1

  2. 从avc中配置相关规则

allow hal_gnss_default device:chr_file rw_file_perms;

        但上面的规则无法生效。如上规则,放在系统里编译,会出现如下错误:

libsepol.report_failure: neverallow on line 681 of sepolicy/private/domain.te violated by allow hal_gnss_default
system/sepolicy/private/domain.te

3. 解决拒绝提供核心服务的问题

3.1 权限过大问题

        要解决这类问题,可以给文件一个更具体的标签,在本例中就是: gnss_device。不需要其他权限,因为hal_gnss_default已经在核心策略中拥有访问 gnss_device 的必要权限。

allow hal_gnss_default gnss_device:chr_file rw_file_perms;

3.2 从file_contents中定义新的label

avc: denied { map } for comm="vendor.demo" path="/dev/__properties__/u:object_r:default_prop:s0" dev="tmpfs" ino=212 scontext=u:r:hal_gnss_default:s0 tcontext=u:object_r:default_prop:s0 tclass=file permissive=1

        从avc信息看,需要配置:

allow hal_gnss_default default_prop:file { map };

        但如上规则,放在系统里依然无法编译。原因是Google定义了相关规则,不允许按上述方法配置;

system/sepolicy/microdroid/system/public/property.te

system/sepolicy/private/property.te

处理方案是:

        ①.  在file_contexts文件中新增label,如下图所示;

device/google/coral-sepolicy/vendor/google/property_contexts

        ②. 在*.te文件中,通过set_prop/get_prop方法来配置;

device/google/coral-sepolicy/vendor/google/property_contexts

        编辑/添加策略和file_contexts后,更新 /device/manufacturer/device-name/BoardConfig.mk 以引用 sepolicy 子目录和每个新策略文件。

        有关 BOARD_SEPOLICY 变量的更多信息,请参见:system/sepolicy/README文件。

BOARD_SEPOLICY_DIRS += \
        <root>/device/manufacturer/device-name/sepolicy

BOARD_SEPOLICY_UNION += \
        genfs_contexts \
        file_contexts \
        sepolicy.te
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值