首页 > 解决方案 > Android 的 Logcat 在 tmpfs 上使用 selinux avc 拒绝发送垃圾邮件,由 kworker/kernel 键入 1400

问题描述

我的 android 的 logcat 收到了这些警告的垃圾邮件。(以 magisk 为根)

10-15 22:02:29.039 12944 12944 W kworker/0:4: type=1400 audit(0.0:87190): avc: denied { read write } for name="sde73" dev="tmpfs" ino=28978 scontext=u:r:kernel:s0 tcontext=u:object_r:oem_device:s0 tclass=blk_file permissive=0

我正在查看以下文档以了解如何解决此问题,但无法弄清楚。

https://source.android.com/security/selinux/device-policy

https://source.android.com/security/selinux/validate

https://source.android.com/security/selinux/concepts

https://source.android.com/security/selinux/implement

https://gist.github.com/msfjarvis/ec52b48eb2df1688b7cbe32bcd39ee5f

https://android.stackexchange.com/questions/207484/how-to-fix-selinux-avc-denied-errors-when-launching-dnscrypt-as-init-d-script

https://source.android.com/security/selinux/customize#android-o

https://android.stackexchange.com/questions/218911/how-to-add-selinux-policy-on-a-user-debug-rom-that-has-split-policy-scheme

https://android.stackexchange.com/questions/214839/how-to-run-an-android-init-service-with-superuser-selinux-context

https://topjohnwu.github.io/Magisk/tools.html#magiskpolicy

https://topjohnwu.github.io/Magisk/details.html#magisk-booting-process

https://topjohnwu.github.io/Magisk/guides.html#boot-scripts

我看了看/dev,但我没有类似的东西。

android# ls -l /dev/ | grep sd
#returns nothing

inode 解析到这个文件:

find /sys -xdev -inum 28978
/sys/firmware/devicetree/base/__symbols__/sb_7_tx

但是,在下次重新启动时会解析到其他文件,但错误始终与单个 inode 相关。

我想我应该将此规则添加到 .te 文件中

allow kernel oem_device:blk_file {read write};

adb pull /sys/fs/selinux/policy
adb logcat -b all -d | audit2allow -p policy
#this confirms the rule

我在这个转储中找到了一些与 selinux 相关的文件:

https://git.rip/dumps/oneplus/oneplus7tpro/-/find_file/hotdog-user-10-QKQ1.190716.003-2009281542-release-keys

但我不太确定我应该在哪里添加规则..可能在 /vendor/etc/selinux..

有谁知道修复这些警告的步骤是什么,并可能进一步深入调查为什么它们首先发生?

谢谢

标签: androidselinux

解决方案


我设法用这个命令修复了警告:

magiskpolicy --live 'allow kernel oem_device blk_file {read write open}'

'open' 权限也被授予,因为在只允许读/写之后会出现另一个与之相关的警告。

我仍然无法理解:

  1. 为什么内核试图访问它
  2. 究竟试图访问什么
  3. magisk 不应该处理与内核等低级授权相关的 selinux 策略
  4. 不知道我怎样才能使这个修复永久化(在重新启动时持续存在)。从我的研究看来,我必须修改 boot.img 中的某个文件,重新打包并将其推送回 android。

在这个页面上: https ://topjohnwu.github.io/Magisk/tools.html

它指定了一个工具 magiskboot 应该用于此类修补,但我没有它。

A tool to unpack / repack boot images, parse / patch / extract cpio, patch dtb, hex patch binaries, and compress / decompress files with multiple algorithms.

我会带着任何发现回来。

更新:我设法在启动时使用在启动过程中运行的 post-fs-data 脚本永久添加修复程序。它可能不是 100% 修复,因为应该修补引导映像,以便 magiskinit 甚至在执行 init 之前加载策略,但是它仍然在引导过程结束后修复 logcat 中的警告

参考:

https://topjohnwu.github.io/Magisk/details.html#magisk-booting-process https://topjohnwu.github.io/Magisk/guides.html#boot-scripts

su -
cd /data/adb/post-fs-data.d
touch fix_selinux.sh
chmod +x fix_selinux.sh
vi fix_selinux.sh #add this line (and any other rules you need):
/sbin/magiskpolicy --live 'allow kernel oem_device blk_file {read write open}'

推荐阅读