Files
DroidDeck/tools/proot/patches/0008-fchmodat2-openat2.patch
maxjivi05 866cfbd17a proot: port WinNative's seccomp and tracee performance fixes
Brings the proot patch set up to WinNative 53836ca9 on top of the #772 port:

- trace prctl, setrlimit and prlimit64 in the seccomp filter only for the
  arguments proot acts on, and uname only where the core rewrites it
- answer a seccomp stop's filter flags from the registers fetched for its
  translation, reuse those registers, and skip the sysexit stop of wait4 left
  to the kernel and accept without a sockaddr; the flags come from proot's list
  merged with the enabled extensions, and a syscall an extension replaced
  keeps its exit stop
- take a clone3 child's flags and exit signal from struct clone_args
- name a thread's /proc/self by its thread group and resolve /proc/thread-self
- translate fchmodat2, send openat2 callers to openat, and bound sysnum lookups
  by the table length
- sweep relatives only for tracees that have children or ptracees, and empty
  the per-stop memory collector instead of reallocating it
2026-09-27 08:10:58 -04:00

121 lines
3.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: maxjivi05 <maxjividen@gmail.com>
Date: Sun, 27 Sep 2026 07:58:30 -0400
Subject: [PATCH] syscall: translate fchmodat2, send openat2 callers to openat,
bound sysnum lookups by the table length
---
src/syscall/enter.c | 18 ++++++++++++++++++
src/syscall/seccomp.c | 2 ++
src/syscall/sysnum.c | 2 +-
src/syscall/sysnums-arm.h | 2 ++
src/syscall/sysnums-arm64.h | 2 ++
src/syscall/sysnums.list | 2 ++
6 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/src/syscall/enter.c b/src/syscall/enter.c
index b84fdc3..1d3b3fd 100644
--- a/src/syscall/enter.c
+++ b/src/syscall/enter.c
@@ -447,6 +447,24 @@ int translate_syscall_enter(Tracee *tracee)
status = translate_path2(tracee, dirfd, path, SYSARG_2, REGULAR);
break;
+ case PR_fchmodat2:
+ dirfd = peek_reg(tracee, CURRENT, SYSARG_1);
+ flags = peek_reg(tracee, CURRENT, SYSARG_4);
+
+ status = get_sysarg_path(tracee, path, SYSARG_2);
+ if (status < 0)
+ break;
+
+ if ((flags & AT_SYMLINK_NOFOLLOW) != 0)
+ status = translate_path2(tracee, dirfd, path, SYSARG_2, SYMLINK);
+ else
+ status = translate_path2(tracee, dirfd, path, SYSARG_2, REGULAR);
+ break;
+
+ case PR_openat2:
+ status = -ENOSYS;
+ break;
+
case PR_inotify_add_watch:
flags = peek_reg(tracee, CURRENT, SYSARG_3);
diff --git a/src/syscall/seccomp.c b/src/syscall/seccomp.c
index cec4330..0b381bb 100644
--- a/src/syscall/seccomp.c
+++ b/src/syscall/seccomp.c
@@ -419,6 +419,7 @@ static FilteredSysnum proot_sysnums[] = {
{ PR_faccessat2, FILTER_SYSEXIT },
{ PR_fchdir, FILTER_SYSEXIT },
{ PR_fchmodat, 0 },
+ { PR_fchmodat2, 0 },
{ PR_fchownat, 0 },
{ PR_fstatat64, 0 },
{ PR_futimesat, 0 },
@@ -455,6 +456,7 @@ static FilteredSysnum proot_sysnums[] = {
{ PR_oldstat, 0 },
{ PR_open, 0 },
{ PR_openat, 0 },
+ { PR_openat2, 0 },
{ PR_pivot_root, 0 },
{ PR_prctl, 0 },
{ PR_prlimit64, FILTER_SYSEXIT },
diff --git a/src/syscall/sysnum.c b/src/syscall/sysnum.c
index b5440a6..785593e 100644
--- a/src/syscall/sysnum.c
+++ b/src/syscall/sysnum.c
@@ -92,7 +92,7 @@ static Sysnum translate_sysnum(Abi abi, word_t sysnum)
index = sysnum - sysnums.offset;
/* Sanity checks. */
- if (index > sysnums.length)
+ if (index >= sysnums.length)
return PR_void;
return sysnums.table[index];
diff --git a/src/syscall/sysnums-arm.h b/src/syscall/sysnums-arm.h
index 0503fdd..e3f6f6b 100644
--- a/src/syscall/sysnums-arm.h
+++ b/src/syscall/sysnums-arm.h
@@ -358,4 +358,6 @@ static const Sysnum sysnums_arm[] = {
[ 397 ] = PR_statx,
[ 439 ] = PR_faccessat2,
[ 435 ] = PR_clone3,
+ [ 437 ] = PR_openat2,
+ [ 452 ] = PR_fchmodat2,
};
diff --git a/src/syscall/sysnums-arm64.h b/src/syscall/sysnums-arm64.h
index 751382f..b257339 100644
--- a/src/syscall/sysnums-arm64.h
+++ b/src/syscall/sysnums-arm64.h
@@ -279,5 +279,7 @@ static const Sysnum sysnums_arm64[] = {
[ 290 ] = PR_pkey_free,
[ 291 ] = PR_statx,
[ 435 ] = PR_clone3,
+ [ 437 ] = PR_openat2,
[ 439 ] = PR_faccessat2,
+ [ 452 ] = PR_fchmodat2,
};
diff --git a/src/syscall/sysnums.list b/src/syscall/sysnums.list
index 8170b6e..c221ddd 100644
--- a/src/syscall/sysnums.list
+++ b/src/syscall/sysnums.list
@@ -72,6 +72,7 @@ SYSNUM(fanotify_mark)
SYSNUM(fchdir)
SYSNUM(fchmod)
SYSNUM(fchmodat)
+SYSNUM(fchmodat2)
SYSNUM(fchown)
SYSNUM(fchown32)
SYSNUM(fchownat)
@@ -221,6 +222,7 @@ SYSNUM(olduname)
SYSNUM(open)
SYSNUM(open_by_handle_at)
SYSNUM(openat)
+SYSNUM(openat2)
SYSNUM(pause)
SYSNUM(pciconfig_iobase)
SYSNUM(pciconfig_read)