【问题标题】:Android's Logcat spammed with selinux avc denials on tmpfs, type 1400 by kworker/kernelAndroid 的 Logcat 在 tmpfs 上使用 selinux avc 发送垃圾邮件,由 kworker/kernel 键入 1400
【发布时间】:2020-10-15 21:05:05
【问题描述】:

我的 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..的某个地方..

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

谢谢

【问题讨论】:

    标签: android selinux


    【解决方案1】:

    它显示的原因很简单,从错误中可以看出。 kernel 正在尝试读取/写入标记为 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
    

    并将它们闪存到系统中(如果您是用户调试并且可以重新安装它):

    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
    

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-07
        • 1970-01-01
        • 1970-01-01
        • 2014-09-20
        • 2020-10-29
        • 2021-09-04
        相关资源
        最近更新 更多