Merge remote-tracking branch 'origin/main' into feat/lse-emu

This commit is contained in:
Kurt Himebauch committed 2026-11-24 02:58:59 -05:00
commit 08cb1fc75d
7 files changed
+87 -18

No files matched your search

+19 -1
View File
@@ -124,10 +124,12 @@ class NativeHookLdsoSpawnTest(unittest.TestCase):
def tearDownClass(cls):
cls.tmp.cleanup()
def call(self, how, *argv, binds=None):
def call(self, how, *argv, binds=None, real_exe=None):
hook_env = {"DDNATV_ROOT": str(self.root), "LD_PRELOAD": f"{self.hook}:{self.recorder}"}
if binds:
hook_env["DDNATV_BINDS"] = binds
if real_exe:
hook_env["DDNATV_REAL_EXE"] = real_exe
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}")]
@@ -177,6 +179,22 @@ class NativeHookLdsoSpawnTest(unittest.TestCase):
self.call(how, GUEST_LDSO, "--list", GUEST_TOOL)
self.assertEqual([], self.library_paths)
def test_a_program_from_a_bind_starts_itself_again_through_proc_self_exe(self):
bash = str(self.runtime / "bash")
for how in ("exec", "spawn"):
with self.subTest(how=how):
call = self.call(how, "/proc/self/exe", "x", binds=f"/proc:/proc|{self.runtime}:{BOUND_DIR}", real_exe=bash)
self.assertEqual(str(self.root / GUEST_LDSO.lstrip("/")), call[0])
self.assertEqual([bash, "x"], call[-2:])
def test_a_rootfs_program_starts_itself_again_through_proc_self_exe(self):
tool = str(self.root / GUEST_TOOL.lstrip("/"))
for how in ("exec", "spawn"):
with self.subTest(how=how):
call = self.call(how, "/proc/self/exe", "x", binds="/proc:/proc", real_exe=tool)
self.assertEqual(str(self.root / GUEST_LDSO.lstrip("/")), call[0])
self.assertEqual([tool, "x"], call[-2:])
def test_a_script_interpreter_from_a_bind_runs_as_a_guest_program(self):
for how in ("exec", "spawn"):
with self.subTest(how=how):
+24 -1
View File
@@ -57,6 +57,16 @@ class NativeHookProcExeTest(unittest.TestCase):
(cls.root / "usr/bin").mkdir(parents=True)
cls.kwin = cls.root / "usr/bin/kwin_wayland"
shutil.copy(tmp / "sleeper", cls.kwin)
cls.runtime = tmp / "runtime"
cls.runtime.mkdir()
cls.bound = cls.runtime / "chrome"
shutil.copy(tmp / "sleeper", cls.bound)
cls.shadowed = cls.runtime / "bin/chrome"
cls.shadowed.parent.mkdir()
shutil.copy(tmp / "sleeper", cls.shadowed)
cls.override = tmp / "override"
cls.override.mkdir()
shutil.copy(tmp / "sleeper", cls.override / "chrome")
# The child's /proc/<pid>/exe must name the loader, as DroidDeck's libddexec.so does.
cls.loader = tmp / "lib/libddexec.so"
cls.loader.parent.mkdir()
@@ -85,8 +95,10 @@ class NativeHookProcExeTest(unittest.TestCase):
self.assertEqual("ready", child.stdout.readline().strip())
return child.pid
def readlink(self, *paths):
def readlink(self, *paths, binds=None):
hook_env = {"DDNATV_ROOT": str(self.root), "LD_PRELOAD": str(self.hook)}
if binds:
hook_env["DDNATV_BINDS"] = binds
env = {k: v for k, v in os.environ.items() if k != "LD_PRELOAD"}
if self.prefix:
cmd = list(self.prefix) + [arg for key, value in hook_env.items() for arg in ("-E", f"{key}={value}")]
@@ -108,6 +120,17 @@ class NativeHookProcExeTest(unittest.TestCase):
at = f"at:/proc/{pid}"
self.assertEqual("/usr/bin/kwin_wayland", self.readlink(at)[at])
def test_a_guest_program_from_a_bind_is_named_by_its_guest_path(self):
pid = self.start(loader=True, real_exe=str(self.bound), program=self.bound)
link = f"/proc/{pid}/exe"
self.assertEqual("/app/extra/chrome", self.readlink(link, binds=f"/proc:/proc|{self.runtime}:/app/extra")[link])
def test_a_guest_program_shadowed_by_a_nested_bind_keeps_its_own_path(self):
pid = self.start(loader=True, real_exe=str(self.shadowed), program=self.shadowed)
link = f"/proc/{pid}/exe"
binds = f"/proc:/proc|{self.runtime}:/app|{self.override}:/app/bin"
self.assertEqual(str(self.shadowed), self.readlink(link, binds=binds)[link])
def test_a_program_named_only_in_the_environment_is_not_believed(self):
pid = self.start(loader=True, real_exe=str(self.kwin))
link = f"/proc/{pid}/exe"