Android 的 Logcat 被 tmpfs 上的 selinux avc 拒绝垃圾邮件,由 kworker/kernel 键入 1400

Android's Logcat spammed with selinux avc denials on tmpfs, type 1400 by kworker/kernel

我的 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

索引节点解析为这个文件:

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..

中的某处

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

谢谢

它显示的原因很简单,就是错误。 kernel 正在尝试 read/write 带有 oem_device 类型标签的 blk_file

此时您有两个选择:

  1. 如果要允许访问,请添加 allow 规则。
  2. 添加dontaudit规则,如果你只想抑制日志。看 here

应将规则添加到 kernel.te
通常这些自​​定义的东西会进入 device/XXXXXX,具体取决于供应商。例如在我的树中,对于 rockchip 设备,我会修改 /device/rockchip/common/sepolicy/vendor/kernel.te

要重建策略,您将:

source build/envsetup.sh
lunch-yourTarget
mmm system/sepolicy

并将它们刷入系统(如果您是 userdebug 并且可以重新安装):

adb root
adb remount
adb push out/target/product/YOUR_DEVICE/vendor/etc/selinux /vendor/etc/
adb push out/target/product/YOUR_DEVICE/system/etc/selinux /system/etc/
adb shell sync

adb reboot

如果无法推送它们,则需要重建并刷新系统

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

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

'open' 权限也被授予了,因为只允许 read/write.

之后会出现与之相关的另一个警告

还是看不懂:

  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}'