mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 15:26:04 +00:00
fix(nativeguest): a script interpreter reached through a bind runs as a guest program (#3112)
* fix(nativeguest): a script interpreter reached through a bind runs as a guest program A Flatpak runtime binds its own /usr outside the sandbox root, so the hook took #!/usr/bin/bash there for an Android program and handed it to the kernel, which failed with "bad interpreter". An interpreter whose guest path is a bind now starts like any guest program. * Native hook: keep Android interpreters a bind reaches on the host * Native hook: match the root of an interpreter on a folder boundary
This commit is contained in:
1 parent
5f2699e56b
commit
e349d2544e
3 files changed
+50
-7
No files matched your search
@@ -10,6 +10,9 @@ from tools.tests.test_usr2_preload import runner
|
||||
HOOK_BUILD = Path(__file__).resolve().parents[1] / "nativeguest/build.sh"
|
||||
GUEST_LDSO = "/usr/lib/ld-linux-aarch64.so.1"
|
||||
GUEST_TOOL = "/usr/local/bin/tool"
|
||||
BOUND_DIR = "/opt/runtime"
|
||||
ANDROID_DIR = "/opt/android"
|
||||
HOST_SHELL = "/data/local/tmp/droiddeck-hook-probe-sh"
|
||||
|
||||
RECORDER = r"""
|
||||
#define _GNU_SOURCE
|
||||
@@ -102,13 +105,29 @@ class NativeHookLdsoSpawnTest(unittest.TestCase):
|
||||
shutil.copy(source, host)
|
||||
host.chmod(0o755)
|
||||
(cls.root / "usr/lib/aarch64-linux-gnu").mkdir(parents=True, exist_ok=True)
|
||||
cls.runtime = tmp / "runtime"
|
||||
cls.runtime.mkdir()
|
||||
shutil.copy(cls.probe, cls.runtime / "bash")
|
||||
(cls.runtime / "bash").chmod(0o755)
|
||||
cls.android = tmp / "root-android"
|
||||
cls.android.mkdir()
|
||||
subprocess.run([cls.cc, "-O1", "-Wl,--dynamic-linker=/system/bin/linker64", "-o", str(cls.android / "sh"),
|
||||
str(tmp / "probe.c")], check=True)
|
||||
for name, interpreter in (("bound.sh", f"{BOUND_DIR}/bash"), ("host.sh", HOST_SHELL),
|
||||
("android.sh", f"{ANDROID_DIR}/sh")):
|
||||
script = cls.root / "opt" / name
|
||||
script.parent.mkdir(exist_ok=True)
|
||||
script.write_text(f"#!{interpreter}\n")
|
||||
script.chmod(0o755)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.tmp.cleanup()
|
||||
|
||||
def call(self, how, *argv):
|
||||
def call(self, how, *argv, binds=None):
|
||||
hook_env = {"DDNATV_ROOT": str(self.root), "LD_PRELOAD": f"{self.hook}:{self.recorder}"}
|
||||
if binds:
|
||||
hook_env["DDNATV_BINDS"] = binds
|
||||
env = {k: v for k, v in os.environ.items() if k not in ("LD_PRELOAD", "DDNATV_EXEC", "LD_LIBRARY_PATH")}
|
||||
if self.prefix:
|
||||
cmd = list(self.prefix) + [arg for key, value in hook_env.items() for arg in ("-E", f"{key}={value}")]
|
||||
@@ -158,6 +177,26 @@ class NativeHookLdsoSpawnTest(unittest.TestCase):
|
||||
self.call(how, GUEST_LDSO, "--list", GUEST_TOOL)
|
||||
self.assertEqual([], self.library_paths)
|
||||
|
||||
def test_a_script_interpreter_from_a_bind_runs_as_a_guest_program(self):
|
||||
for how in ("exec", "spawn"):
|
||||
with self.subTest(how=how):
|
||||
call = self.call(how, "/opt/bound.sh", "x", binds=f"{self.runtime}:{BOUND_DIR}")
|
||||
self.assertEqual(str(self.root / GUEST_LDSO.lstrip("/")), call[0])
|
||||
self.assertEqual([str(self.runtime / "bash"), str(self.root / "opt/bound.sh"), "x"], call[-3:])
|
||||
|
||||
def test_a_script_interpreter_outside_the_rootfs_and_its_binds_stays_on_the_host(self):
|
||||
for how in ("exec", "spawn"):
|
||||
with self.subTest(how=how):
|
||||
call = self.call(how, "/opt/host.sh", "x", binds=f"{self.runtime}:{BOUND_DIR}")
|
||||
self.assertEqual([HOST_SHELL, HOST_SHELL, str(self.root / "opt/host.sh"), "x"], call)
|
||||
|
||||
def test_an_android_interpreter_reached_through_a_bind_stays_on_the_host(self):
|
||||
sh = str(self.android / "sh")
|
||||
for how in ("exec", "spawn"):
|
||||
with self.subTest(how=how):
|
||||
call = self.call(how, "/opt/android.sh", "x", binds=f"{self.android}:{ANDROID_DIR}")
|
||||
self.assertEqual([sh, sh, str(self.root / "opt/android.sh"), "x"], call)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user