如何在init(Android 8.1)中运行服务

问题描述 投票:1回答:2

我想通过Init运行服务。 (Android 8.1,sepolicy = permissive)

该服务执行脚本文件,脚本文件如下。

tcc898x:/ # cat /system/bin/tcc_dxb_service
#!/system/bin/sh
echo ----------------
echo RICHGOLD.
echo ----------------

初始化中的服务执行如下。

tcc898x:/ # cat init.tcc898x.rc
(...)
on boot
    (...)
    start tcc_dxb_service
(...)
service tcc_dxb_service /system/bin/tcc_dxb_service
    class main
    user root
    u:object_r:tcc_dxb_service_exec:s0

并且要添加域,请按如下所示添加Sepolicy文件。

# cat (Android 8.1 SDK)/device/(vendor)/(product)/sepolicy/tcc_dxb_service.te
type tcc_dxb_service, domain;
type tcc_dxb_service_exec, exec_type, system_file_type, file_type;
init_daemon_domain(tcc_dxb_service)

执行tcc_dxb_service服务时,显示以下输出。

tcc898x:/ # start tcc_dxb_service
init: could not get context while starting 'tcc_dxb_service'

请告诉我如何在Sepolicy中注册域以运行服务。

谢谢。

android service init selinux android-8.1-oreo
2个回答
0
投票

您必须

  • 在服务定义的第二个标签前加上seclabel
  • object_r更改为r,然后
  • 使用tcc_dxb_service类型而不是tcc_dxb_service_exec
service tcc_dxb_service /system/bin/tcc_dxb_service
    class main
    user root
    seclabel u:r:tcc_dxb_service:s0

0
投票

感谢您的回答。

我引用了Android reference site为正在开发的项目添加服务。

  1. 添加了服务,(init。{device} .rc)
service foo /system/bin/foo
    class core
  1. 已添加标签。((Android SDK)/设备/(供应商)/(设备)/ sepolicy / file_contexts)
/system/bin/foo u:object_r:foo_exec:s0
  1. 创建一个新域。((Android SDK)/设备/(供应商)/(设备)/sepolicy/foo.te)
# foo sercie
# Integrated foo process
type foo, domain;
type foo_exec, exec,type, file_type;

# started by init
init_daemon_domain(foo)

(/ system / bin / foo)

echo "-----"
echo "RICHGOLD"
echo "-----"

我这样设置。构建时,发生以下错误。

FAILED: out/target/product/tcc898x/obj/ETC/sepolicy_intermediates/sepolicy 
/bin/bash -c "(out/host/linux-x86/bin/secilc -M true -G -c 30 out/target/product/tcc898x/obj/ETC/plat_sepolicy.cil_intermediates/plat_sepolicy.cil out/target/product/tcc898x/obj/ETC/27.0.cil_intermediates/27.0.cil out/target/product/tcc898x/obj/ETC/nonplat_sepolicy.cil_intermediates/nonplat_sepolicy.cil -o out/target/product/tcc898x/obj/ETC/sepolicy_intermediates/sepolicy.tmp -f /dev/null ) && (out/host/linux-x86/bin/sepolicy-analyze out/target/product/tcc898x/obj/ETC/sepolicy_intermediates/sepolicy.tmp permissive > out/target/product/tcc898x/obj/ETC/sepolicy_intermediates/sepolicy.permissivedomains ) && (if [ \"eng\" = \"user\" -a -s out/target/product/tcc898x/obj/ETC/sepolicy_intermediates/sepolicy.permissivedomains ]; then         echo \"==========\" 1>&2;       echo \"ERROR: permissive domains not allowed in user builds\" 1>&2;         echo \"List of invalid domains:\" 1>&2;         cat out/target/product/tcc898x/obj/ETC/sepolicy_intermediates/sepolicy.permissivedomains 1>&2;      exit 1;         fi ) && (mv out/target/product/tcc898x/obj/ETC/sepolicy_intermediates/sepolicy.tmp out/target/product/tcc898x/obj/ETC/sepolicy_intermediates/sepolicy )"
neverallow check failed at out/target/product/tcc898x/obj/ETC/nonplat_sepolicy.cil_intermediates/nonplat_sepolicy.cil:2715
  (neverallow base_typeattr_56_27_0 base_typeattr_57_27_0 (file (execute execute_no_trans entrypoint)))
    <root>
    allow at out/target/product/tcc898x/obj/ETC/nonplat_sepolicy.cil_intermediates/nonplat_sepolicy.cil:6207
      (allow foo foo_exec (file (read getattr map execute entrypoint open)))

neverallow check failed at out/target/product/tcc898x/obj/ETC/plat_sepolicy.cil_intermediates/plat_sepolicy.cil:4641 from system/sepolicy/public/domain.te:668
  (neverallow base_typeattr_56 base_typeattr_57 (file (execute execute_no_trans entrypoint)))
    <root>
    allow at out/target/product/tcc898x/obj/ETC/nonplat_sepolicy.cil_intermediates/nonplat_sepolicy.cil:6207
      (allow foo foo_exec (file (read getattr map execute entrypoint open)))

Failed to generate binary
Failed to build policydb
[  2% 110/5135] build out/target/product/tcc898x/obj/ETC/precompiled_sepolicy_intermediates/precompiled_sepolicy
FAILED: out/target/product/tcc898x/obj/ETC/precompiled_sepolicy_intermediates/precompiled_sepolicy 
/bin/bash -c "out/host/linux-x86/bin/secilc -M true -G -c 30        out/target/product/tcc898x/obj/ETC/plat_sepolicy.cil_intermediates/plat_sepolicy.cil out/target/product/tcc898x/obj/ETC/27.0.cil_intermediates/27.0.cil out/target/product/tcc898x/obj/ETC/nonplat_sepolicy.cil_intermediates/nonplat_sepolicy.cil -o out/target/product/tcc898x/obj/ETC/precompiled_sepolicy_intermediates/precompiled_sepolicy -f /dev/null"
neverallow check failed at out/target/product/tcc898x/obj/ETC/nonplat_sepolicy.cil_intermediates/nonplat_sepolicy.cil:2715
  (neverallow base_typeattr_56_27_0 base_typeattr_57_27_0 (file (execute execute_no_trans entrypoint)))
    <root>
    allow at out/target/product/tcc898x/obj/ETC/nonplat_sepolicy.cil_intermediates/nonplat_sepolicy.cil:6207
      (allow foo foo_exec (file (read getattr map execute entrypoint open)))

neverallow check failed at out/target/product/tcc898x/obj/ETC/plat_sepolicy.cil_intermediates/plat_sepolicy.cil:4641 from system/sepolicy/public/domain.te:668
  (neverallow base_typeattr_56 base_typeattr_57 (file (execute execute_no_trans entrypoint)))
    <root>
    allow at out/target/product/tcc898x/obj/ETC/nonplat_sepolicy.cil_intermediates/nonplat_sepolicy.cil:6207
      (allow foo foo_exec (file (read getattr map execute entrypoint open)))

Failed to generate binary
Failed to build policydb
ninja: build stopped: subcommand failed.
17:24:01 ninja failed with: exit status 1

#### failed to build some targets (43 seconds) ####

如果创建域时删除了init_daemon_domain(foo),((Android SDK)/设备/(供应商)/(设备)/sepolicy/foo.te)

# foo sercie
# Integrated foo process
type foo, domain;
type foo_exec, exec,type, file_type;

# started by init
# init_daemon_domain(foo)

在正常构建后,将显示以下日志。执行服务后,

# start foo
init: service foo does not have a SELinux domain defined

如何添加域?请给我有关Neverallow的提示。

谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.