mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 15:26:04 +00:00
fix(nativeguest): keep parent lookups inside the guest root (#3094)
* fix(nativeguest): keep the parent of the guest root inside the rootfs
* fix(nativeguest): keep every .. walk inside the guest root and its mounts
Absolute paths that climb above /, relative paths from the working
directory or any descriptor, and paths that climb out of a mount were
resolved by the kernel from the rootfs folder or the mount's real place,
so /.., chdir("..") from / and fstatat(fd, "../..") listed the app's
files folder. The walk is now resolved in the guest's view first.
* fix(nativeguest): .. from a linked mount ancestor follows the real directory
---------
Co-authored-by: maxjivi05 <6025299+maxjivi05@users.noreply.github.com>
This commit is contained in:
1 parent
ba3f840b8d
commit
f539660650
3 files changed
+114
-24
No files matched your search
@@ -26,6 +26,19 @@ int main(int argc, char **argv) {
|
||||
printf("%s\t%s\n", argv[i], value ? value : "-");
|
||||
continue;
|
||||
}
|
||||
if (strncmp(argv[i], "parent:", 7) == 0) {
|
||||
char dir[4096];
|
||||
snprintf(dir, sizeof(dir), "%s", argv[i] + 7);
|
||||
char *rel = strchr(dir, '|'), *want = NULL;
|
||||
if (rel) *rel++ = 0;
|
||||
if (rel && (want = strchr(rel, '|'))) *want++ = 0;
|
||||
int fd = open(dir, O_RDONLY | O_DIRECTORY);
|
||||
struct stat expected;
|
||||
int ok = fd >= 0 && fstatat(fd, rel ? rel : "..", &st, 0) == 0 && stat(want ? want : "/", &expected) == 0;
|
||||
printf("%s\t%d\n", argv[i], ok && st.st_dev == expected.st_dev && st.st_ino == expected.st_ino);
|
||||
if (fd >= 0) close(fd);
|
||||
continue;
|
||||
}
|
||||
if (strncmp(argv[i], "cd:", 3) == 0) {
|
||||
int ok = chdir(argv[i] + 3) == 0 && getcwd(cwd, sizeof(cwd)) != NULL;
|
||||
printf("%s\t%s\n", argv[i], ok ? cwd : "-");
|
||||
@@ -82,6 +95,8 @@ class NativeHookMountTest(unittest.TestCase):
|
||||
cls.root = tmp / "root"
|
||||
cls.library = tmp / "storage/PC GAMES"
|
||||
(cls.root / "etc").mkdir(parents=True)
|
||||
(cls.root / "deep/er/est").mkdir(parents=True)
|
||||
(cls.root / "linked").symlink_to("deep/er/est")
|
||||
(cls.root / "etc/hostname").write_text("rootfs")
|
||||
(cls.root / "mnt/library/Some Game").mkdir(parents=True)
|
||||
(cls.root / "mnt/library/Some Game/game.txt").write_text("mount point")
|
||||
@@ -123,8 +138,9 @@ class NativeHookMountTest(unittest.TestCase):
|
||||
def tearDownClass(cls):
|
||||
cls.tmp.cleanup()
|
||||
|
||||
def run_probe(self, *args):
|
||||
binds = f"{self.library}:/mnt/library|{self.private}:/mnt/private|{self.eqlen_src}:{self.eqlen_dst}"
|
||||
def run_probe(self, *args, binds=None):
|
||||
if binds is None:
|
||||
binds = f"{self.library}:/mnt/library|{self.private}:/mnt/private|{self.eqlen_src}:{self.eqlen_dst}"
|
||||
hook_env = {"DDNATV_ROOT": str(self.root), "DDNATV_BINDS": binds, "LD_PRELOAD": str(self.hook)}
|
||||
env = {k: v for k, v in os.environ.items() if k not in ("LD_PRELOAD", "LOCPATH", "GCONV_PATH")}
|
||||
if self.prefix:
|
||||
@@ -158,6 +174,37 @@ class NativeHookMountTest(unittest.TestCase):
|
||||
self.assertEqual(result["env:LOCPATH"], [f"{self.root}/usr/lib/locale"])
|
||||
self.assertEqual(result["env:GCONV_PATH"], [f"{self.root}/usr/lib/aarch64-linux-gnu/gconv"])
|
||||
|
||||
def test_parent_of_root_stays_at_root(self):
|
||||
self.assertEqual(self.run_probe("parent:/")["parent:/"], ["1"])
|
||||
|
||||
def test_parent_of_root_without_mounts_stays_at_root(self):
|
||||
self.assertEqual(self.run_probe("parent:/", binds="")["parent:/"], ["1"])
|
||||
|
||||
def test_parent_of_mount_ancestor_is_guest_root(self):
|
||||
self.assertEqual(self.run_probe("parent:/mnt")["parent:/mnt"], ["1"])
|
||||
|
||||
def test_parent_walks_from_any_directory_stay_at_root(self):
|
||||
cases = ["parent:/etc|../..", "parent:/mnt/library|../../..", "parent:/|../etc/.."]
|
||||
self.assertEqual(self.run_probe(*cases), {case: ["1"] for case in cases})
|
||||
|
||||
def test_parent_walk_from_a_linked_mount_ancestor_follows_the_real_directory(self):
|
||||
binds = f"{self.library}:/linked/library"
|
||||
case = "parent:/linked|../..|/deep"
|
||||
self.assertEqual(self.run_probe(case, binds=binds)[case], ["1"])
|
||||
|
||||
def test_absolute_paths_above_root_stay_at_root(self):
|
||||
result = self.run_probe("cd:/..", "cd:/etc/../..", "/../etc/hostname")
|
||||
self.assertEqual(result["cd:/.."], [str(self.root)])
|
||||
self.assertEqual(result["cd:/etc/../.."], [str(self.root)])
|
||||
self.assertEqual(result["/../etc/hostname"], ["1", "rootfs"])
|
||||
|
||||
def test_relative_parent_of_cwd_stays_in_guest(self):
|
||||
result = self.run_probe("cd:/", "cd:..", "cd:./../..", "../etc/hostname", f"cd:{GAME}", "cd:../..")
|
||||
self.assertEqual(result["cd:.."], [str(self.root)])
|
||||
self.assertEqual(result["cd:./../.."], [str(self.root)])
|
||||
self.assertEqual(result["cd:../.."], [str(self.root / "mnt")])
|
||||
self.assertEqual(result["../etc/hostname"], ["1", "rootfs"])
|
||||
|
||||
def test_rootfs_paths_outside_mounts_are_unchanged(self):
|
||||
paths = ["/pfx/native/dosdevices/z:/etc/hostname", f"{self.root}/etc/hostname", "/etc/hostname"]
|
||||
result = self.run_probe(*paths)
|
||||
|
||||
Reference in new issue
Block a user