fix(proot): a call the filesystem does not implement no longer switches the fast path off (#2509)

Android's FUSE daemon has no symlink or link, so those calls on a storage card return ENOSYS. The fast path read any ENOSYS from its trampoline as a seccomp trap and stopped for the whole process. It now asks again with the same call number and invalid arguments: a trap answers ENOSYS again, anything else means the call reached the kernel and only that call is repeated. Folders opened for a refused call are still closed.
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-12 00:13:00 -05:00
1 parent b303423001
commit cd05c96d10
3 files changed
+51 -3

No files matched your search

+5
View File
@@ -162,6 +162,11 @@ Prototype (inert unless `PROOT_FASTPATH` is set; see `docs/development/proot-per
`ENOSYS`, because its arguments are host paths; the fast path then stops for that process and
repeats the call through a plain `svc`, which the guest's filter traps with the guest path.
`bench/guest-trap.c` installs a tagged `openat` trap and checks its handler answers the call.
The kernel and filesystems also return `ENOSYS` themselves: Android's FUSE daemon has no
`symlink`, so `symlinkat` on a storage card fails with it. The fast path therefore asks again
with the same call number and invalid arguments. A trap answers `ENOSYS` again and the fast path
stops for the process; any other error means the call reached the kernel, so only that one call
is repeated through a plain `svc` and the fast path stays on.
Old kernel fixes:
+2 -2
View File
@@ -59,10 +59,10 @@ static int optional_syscall(long nr) {
nr == SYS_openat2 || nr == SYS_renameat2;
}
static long sc(long nr, long a, long b, long c, long d, long e) {
if (fp_refused) return -ENOSYS;
if (fp_refused && nr != SYS_close) return -ENOSYS;
long r = fp_sys(nr, a, b, c, d, e, 0);
if (r == -ENOSYS && !optional_syscall(nr)) {
__atomic_store_n(&fp_on, 0, __ATOMIC_RELAXED);
if (fp_sys(nr, -1, -1, -1, -1, -1, 0) == -ENOSYS) __atomic_store_n(&fp_on, 0, __ATOMIC_RELAXED);
fp_refused = 1;
}
return r;
+44 -1
View File
@@ -17,7 +17,10 @@ static const char *race_from, *race_to;
static dev_t race_dev;
static ino_t race_ino;
static long trapped_nr = -1, unsupported_nr = -1;
static long host_sys(long nr, long a, long b, long c, long d, long e, long f) {
if (nr == trapped_nr || (nr == unsupported_nr && a != -1)) return -ENOSYS;
long r = syscall(nr, a, b, c, d, e, f);
struct stat fs;
if (r >= 0 && nr == SYS_fcntl && b == F_DUPFD_CLOEXEC && c == DIR_FD_FLOOR && race_from
@@ -72,8 +75,24 @@ int main(int argc, char **argv) {
} else if (!strcmp(op, "stat")) {
struct stat st;
show(fp_stat(AT_FDCWD, argv[++i], AT_SYMLINK_NOFOLLOW, &st));
} else if (!strcmp(op, "symlink")) {
long r = fp_symlink("target", AT_FDCWD, argv[++i]);
if (refused()) puts("REFUSED");
else show(r);
} else if (!strcmp(op, "trap-symlink")) {
trapped_nr = SYS_symlinkat;
} else if (!strcmp(op, "no-symlinks")) {
unsupported_nr = SYS_symlinkat;
} else if (!strcmp(op, "on")) {
printf("%d\n", fp_ready());
} else if (!strcmp(op, "no-folders")) {
unsupported_nr = SYS_mkdirat;
} else if (!strcmp(op, "busy-cache")) {
pthread_mutex_lock(&dir_lock);
} else if (!strcmp(op, "mkdir")) {
show(fp_mkdir(AT_FDCWD, argv[++i], 0755));
long r = fp_mkdir(AT_FDCWD, argv[++i], 0755);
if (refused()) puts("REFUSED");
else show(r);
} else if (!strcmp(op, "mv")) {
show(fp_rename(AT_FDCWD, argv[i + 1], AT_FDCWD, argv[i + 2], 0));
i += 2;
@@ -261,6 +280,30 @@ class FastPathFuseDirsTest(unittest.TestCase):
self.assertEqual(["ok", "ok", "ok", "E2"], out)
self.assertEqual(["under"], [p.name for p in data.iterdir()])
def test_a_call_the_filesystem_does_not_implement_leaves_the_fast_path_on(self):
data = "/mnt/card/Games/steamapps/common/Game/Data"
out = self.ask("fuse", "no-symlinks", "touch", f"{data}/a", "symlink", f"{data}/link", "on",
"stat", f"{data}/a", "symlink", f"{data}/link", "on", "touch", f"{data}/b")
self.assertEqual(["ok", "REFUSED", "1", "ok", "REFUSED", "1", "ok"], out)
self.assertEqual(["a", "b"], sorted(p.name for p in (self.card / "Games/steamapps/common/Game/Data").iterdir()))
def test_repeated_unsupported_calls_close_the_folders_they_opened(self):
data = "/mnt/card/Games/steamapps/common/Game/Data"
ops = [op for n in range(40) for op in ("mkdir", f"{data}/new{n}")]
out = self.ask("fuse", "no-folders", "busy-cache", *ops, "on", "fds")
self.assertEqual(["REFUSED"] * 40 + ["1", "0"], out)
def test_a_trapped_call_still_stops_the_fast_path_for_the_process(self):
data = "/mnt/card/Games/steamapps/common/Game/Data"
out = self.ask("fuse", "trap-symlink", "symlink", f"{data}/link", "on")
self.assertEqual(["REFUSED", "0"], out)
def test_a_symlink_is_made_where_the_filesystem_allows_it(self):
data = "/mnt/card/Games/steamapps/common/Game/Data"
out = self.ask("fuse", "symlink", f"{data}/link", "on")
self.assertEqual(["ok", "1"], out)
self.assertEqual("target", os.readlink(self.card / "Games/steamapps/common/Game/Data/link"))
def test_other_filesystems_keep_absolute_paths_and_open_no_folders(self):
data = "/mnt/card/Games/steamapps/common/Game/Data"
out = self.ask("touch", f"{data}/a", "mv", f"{data}/a", f"{data}/b", "rm", f"{data}/b", "fds")