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中的某个地方。

有人知道要解决这些警告的步骤是什么,也许还可以进一步调查为什么会首先出现这些警告?

谢谢

解决方法

显示该错误的原因很简单。 kernel尝试读取/写入标有blk_file类型的oem_device

目前,您有两种选择:

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

“打开”权限也被授予,因为在仅允许读/写之后还会出现与其有关的另一条警告。

我还是不明白:

  1. 内核为什么要尝试访问此内容
  2. 正在尝试访问的内容
  3. 不应该处理与诸如内核之类的低级别授权相关的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.

任何发现我都会回来的。

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

REF:

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...