I want to run an Android init
service. I have a device which has rooted shell (purchased from manufacture as rooted). This device doesn't have Magisk or other su manager but adb shell
is rooted and it has userdebug
ROM installed on it.
I have followed following steps to set up init
service:
- Created
/etc/init/custom.rc
file with following contents:
#/etc/init/custom.rc
# define service, use executable here if script not needed
service custom /system/bin/custom.sh
# don't start unless explicitly asked to
disabled
# run with unrestricted SELinux context to avoid avc denials
# can also use "u:r:su:s0" on userdebug / eng builds if no Magisk
# it's required if SELinux is enforcing and service needs access
# to some system resources not allowed by default sepolicy
# seclabel u:r:magisk:s0
seclabel u:r:su:s0
# start the service when boot is completed
on property:sys.boot_completed=1
start custom
- Created
/system/bin/custom.sh
with following contents:
#!/system/bin/sh
# execute the binary, should run in foreground, otherwise get in loop
echo "$(date): Starting program..."
exec /system/bin/executable
- Placed my executable at
/system/bin/executable
. - Gave permissions to all files as following:
# Give rights to the executable
chown 0.0 /system/bin/executable
chmod 554 /system/bin/executable
chcon u:object_r:system_file:s0 /system/bin/executable
# Give rights to the custom.sh
chown 0.0 /system/bin/custom.sh
chmod 554 /system/bin/custom.sh
chcon u:object_r:system_file:s0 /system/bin/custom.sh
# Give rights to the custom.rc
chown 0.0 /etc/init/custom.rc
chmod 644 /etc/init/custom.rc
chcon u:object_r:system_file:s0 /etc/init/custom.rc
- Reboot the system.
I got following error:
[
55.829099 / 06-09 23:51:09.279][0] init: cannot execve('/system/bin/custom.sh'): Permission denied
[
55.850172 / 06-09 23:51:09.309][6] init: Service 'custom' (pid 7729)
[
55.850224 / 06-09 23:51:09.309][6] init: Service 'custom' (pid 7729) exited with status 127
[
55.850243 / 06-09 23:51:09.309][6] init: Sending signal 9 to service 'custom' (pid 7729) process group...
[
60.830224 / 06-09 23:51:14.289][6] init: starting service 'custom'...
[
60.832073 / 06-09 23:51:14.289][1] init: cannot execve('/system/bin/custom.sh'): Permission denied
[
60.832153 / 06-09 23:51:14.289][3] audit: type=1400 audit(1560142274.289:131): avc: denied {
transition
}
for pid=8035 comm="init" path="/system/bin/custom.sh" dev="sda24" ino=8146 scontext=u:r:init:s0 tcontext=u:r:su:s0 tclass=process permissive=0
I have very little experience with SELinux Policies. Please guide me how can I fix this.