mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
Merge remote-tracking branch 'origin/main' into feat/lse-emu
This commit is contained in:
commit
08cb1fc75d
7 files changed
+87
-18
No files matched your search
@@ -10,6 +10,13 @@
|
||||
// PT_INTERP) literally and failed with "bad interpreter: No such file or directory".
|
||||
// getcwd() is not virtualised, so cwd + path is a real path that starts with DDNATV_ROOT.
|
||||
static const char *absolutize_exec_path(const char *path, char *buffer, size_t bufsize) {
|
||||
if (is_proc_self_exe(path)) {
|
||||
ssize_t n = handle_proc_self_exe(buffer, bufsize - 1);
|
||||
if (n > 0 && buffer[0] == '/') {
|
||||
buffer[n] = '\0';
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
if (!path || path[0] == '\0' || path[0] == '/') return path;
|
||||
char cwd[PATH_MAX];
|
||||
static char *(*real_getcwd)(char *, size_t) = NULL;
|
||||
|
||||
@@ -203,15 +203,10 @@ static void exe_from_cmdline(const char *cmdline_path, char *out, size_t outsz)
|
||||
}
|
||||
|
||||
static ssize_t copy_guest_exe(const char *real_exe, char *buf, size_t bufsiz) {
|
||||
const char *out_path = real_exe;
|
||||
if (g_ddnatv_root[0] != '\0') {
|
||||
size_t rlen = g_ddnatv_root_len;
|
||||
if (strncmp(real_exe, g_ddnatv_root, rlen) == 0 &&
|
||||
(real_exe[rlen] == '/' || real_exe[rlen] == '\0')) {
|
||||
out_path = real_exe + rlen;
|
||||
if (out_path[0] == '\0') out_path = "/";
|
||||
}
|
||||
}
|
||||
char guest[PATH_MAX];
|
||||
char back[PATH_MAX];
|
||||
const char *out_path = guest_path_of_host_dir(real_exe, guest, sizeof(guest));
|
||||
if (!out_path || strcmp(rewrite_path_in_root(out_path, back, sizeof(back)), real_exe) != 0) out_path = real_exe;
|
||||
size_t len = strlen(out_path);
|
||||
size_t copy_len = (len < bufsiz) ? len : bufsiz;
|
||||
memcpy(buf, out_path, copy_len);
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user