我在我的项目中使用 iMX 8 Mini EVK。我从 AOSP 为该板构建 Android 9.0。 现在我想在启动时运行一个脚本。 我做了以下文件更改,但仍然面临问题。
文件:Android_AOSP_build/device/fsl/imx8m/evk_8mm/init.rc
service gea3appservice /vendor/bin/sh /vendor/bin/run.sh
class late_start
user root system
group root system
oneshot
文件:Android_AOSP_build/device/fsl/imx8m/evk_8mm/sepolicy/gea3appservice.te
type gea3appservice, domain;
type gea3appservice_exec, exec_type, vendor_file_type, file_type;
init_daemon_domain(gea3appservice)
domain_auto_trans(init, vendor_shell_exec, gea3appservice)
文件:Android_AOSP_build/device/fsl/imx8m/evk_8mm/sepolicy/file_contexts
/vendor/bin/run.sh u:object_r:gea3appservice_exec:s0
当我手动运行服务时,出现以下错误:
[ 134.010656] type=1400 audit(1564667688.236:3740): avc: denied { dac_read_search } for pid=1 comm="init" capability=2 scontext=u:r:init:s0 tcontext=u:r:init:s0 tclass=capability permissive=1
有人知道这个问题吗?
我尝试了 Android 开发者网站建议的方法
https://source.android.com/security/selinux/device-policy
但我收到以下错误
libsepol.report_failure: neverallow on line 1002 of system/sepolicy/public/domain.te (or line 11242 of policy.conf) violated by allow gea3appservice gea3appservice_exec:file { execute entrypoint };
最佳答案
这对我有用
在 init.mydevice.rc 中我有
on property:sys.boot_completed=1
start init-myservice-sh
service init-myservice-sh /vendor/bin/init.myscript.sh
class main
user root
group root system
disabled
oneshot
这是 init.myscript.sh
#!/system/bin/sh
echo '################# It works ##################'
cd /system/app
ls -hal
在 device/myvendor/mydevice/sepolicy 文件夹中,我有 file_contexts
/vendor/bin/init\.myscript\.sh u:object_r:init-myservice_exec:s0
和 init-myservice.te
type init-myservice, domain;
type init-myservice_exec, exec_type, vendor_file_type, file_type;
init_daemon_domain(init-myservice)
allow init-myservice vendor_shell_exec:file rx_file_perms;
allow init-myservice vendor_toolbox_exec:file rx_file_perms;
当然你必须将脚本复制到 bin 目录
PRODUCT_COPY_FILES += \
$(LOCAL_PATH)/init.myscript.sh:$(TARGET_COPY_OUT_VENDOR)/bin/init.myscript.sh
以及 BoardConfig.mk 中
BOARD_SEPOLICY_DIRS := device/myvendor/mydevice/sepolicy
在我的控制台中我可以看到这个
console:/ $ dmesg | grep myservice
[ 21.098013] init: starting service 'init-myservice-sh'...
[ 21.148562] init: Command 'start init-myservice-sh' action=sys.boot_completed=1 (/vendor/etc/init/hw/init.mydevice.rc:66) took 51ms and succeeded
试试这个
console:/ $ init.myscript.sh
################# It works ##################
有关摩尔详细信息,请参阅这篇文章 https://source.android.com/security/selinux/device-policy#label_new_services_and_address_denials
关于android - 在 AOSP 中启动时运行 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57370029/