gpt4 book ai didi

android - Android 6 中的 SELinux 问题

转载 作者:行者123 更新时间:2023-11-29 02:40:39 26 4
gpt4 key购买 nike

我在允许 Android 6 中不受信任的应用程序访问/dev/HSL1 串行接口(interface)时遇到问题。这是我收到的错误:

[  757.742286] type=1400 audit(156811.349:149): avc: denied { write } for pid=6422 comm="port_api.sample" name="ttyHSL1" dev="tmpfs" ino=7287 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:tty_device:s0 tclass=chr_file permissive=0

有问题的文件是/dev/ttyHSL1:

1|root@msm8909:/dev # ls -alZ ttyHSL1
crwxrwxrwx root root u:object_r:tty_device:s0 ttyHSL1

external/sepolicy/untrusted_app.te 在文件的末尾有以下内容:

allow untrusted_app tty_device:chr_file rw_file_perms;
allow untrusted_app device:dir r_dir_perms;
allow untrusted_app tty_device:chr_file write;

我假设 rw_file_perms 宏允许 rw 访问 ttyHSL1 文件,但从 dmesg 输出(上图)来看并非如此。应用程序也因“您在串行端口上没有读/写权限”而失败。

另外还有来自 global_macros 的 fragment :

#####################################
# Common groupings of permissions.
#
define(`x_file_perms', `{ getattr execute execute_no_trans }')
define(`r_file_perms', `{ getattr open read ioctl lock }')
define(`w_file_perms', `{ open append write }')
define(`rx_file_perms', `{ r_file_perms x_file_perms }')
define(`ra_file_perms', `{ r_file_perms append }')
define(`rw_file_perms', `{ r_file_perms w_file_perms }')
define(`rwx_file_perms', `{ rw_file_perms x_file_perms }')
define(`create_file_perms', `{ create rename setattr unlink rw_file_perms }')

我是否遗漏了一些非常明显的东西?

最佳答案

我遇到了类似的问题,我相信我可以解决您的问题。将其张贴在这里,即使此时您的问题还很陈旧,以便其他遇到相同问题的人可能会得到帮助。

问题是不受信任的应用程序也有一个 MSL 标记您的 avc 错误:

scontext=u:r:untrusted_app:s0:c512,c768

请注意,在“正常”的 se-linux 工作人员之后您有 :c512,c768,这似乎是一个 MLS“标签”。你的 untrusted_app.te/tty_device 不处理这个 - 默认情况下在 SELinux 中通常不允许应用程序访问对象,即使规则的其余部分没问题。此时您有三个选择:

  1. 编写允许 MLS 标记主题到您的设备的规则
  2. 编写以您的应用为目标并去除 MLS 标签的规则
  3. 编写保留 MLS 标记但允许访问设备的规则。 (可能是最安全的)

我采用了第一 (1) 种方式,并在 device/manufacturer/device/sepolicy 下添加了两个文件:

文件上下文

/dev/ttyHSL1 u:object_r:arendi_device:s0

串口.te

type arendi_device, dev_type, mlstrustedobject;

allow untrusted_app_all arendi_device:chr_file rw_file_perms;

注意 mlstrustedobject 标签 - 这告诉 SEAndroid 它应该忽略来自想要访问此标签的主体的 MLS 标签。还有 mlstrustedsubject,您可以按规则将其添加到您的应用中。

我的 BoardConfig.mk 通过添加以下行告诉 Android 查找这些新文件:

BOARD_SEPOLICY_DIRS += device/manufacturer/device/sepolicy

这现在允许我在 Android Oreo 8.1 下访问我的串口。

这个答案让我想到了这个解决方案: My custom selinux policies seem to be ignored by android system

关于android - Android 6 中的 SELinux 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44435812/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com