问题描述
我正在用这些警告向我的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://source.android.com/security/selinux/customize#android-o
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有关。
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相关的文件:
但是我不太确定应该在哪里添加规则。可能在/ vendor / etc / selinux中的某个地方。
有人知道要解决这些警告的步骤是什么,也许还可以进一步调查为什么会首先出现这些警告?
谢谢
解决方法
显示该错误的原因很简单。 kernel
尝试读取/写入标有blk_file
类型的oem_device
。
目前,您有两种选择:
- 如果要允许访问发生,请添加
allow
规则。 - 添加
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}'
“打开”权限也被授予,因为在仅允许读/写之后还会出现与其有关的另一条警告。
我还是不明白:
- 内核为什么要尝试访问此内容
- 正在尝试访问的内容
- 不应该处理与诸如内核之类的低级别授权相关的selinux策略
- 不确定如何使此修复程序永久生效(重新启动后仍然存在)。从我的研究看来,我必须在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}'