diff --git a/tools/nativeguest/hook/exec.c b/tools/nativeguest/hook/exec.c index 2f92fe9a0d..299751635a 100644 --- a/tools/nativeguest/hook/exec.c +++ b/tools/nativeguest/hook/exec.c @@ -374,6 +374,7 @@ static int ddnatv_execve(const char *filename, char *const argv[], char *const e errno = ENOSYS; return -1; } + if (is_proc_self_exe(filename) && g_real_exe[0] != '\0') filename = g_real_exe; if (depth == 0 && !in_exec_rehearsal()) ddh_try(filename, argv, envp); // Scripts get the path exactly as the caller wrote it ("./x.sh" stays "./x.sh" in $0), diff --git a/tools/nativeguest/hook/privileged.c b/tools/nativeguest/hook/privileged.c index 14ef7c6654..456f6f1858 100644 --- a/tools/nativeguest/hook/privileged.c +++ b/tools/nativeguest/hook/privileged.c @@ -660,6 +660,19 @@ long syscall(long number, ...) { } #endif +#ifdef __NR_execve + if (number == __NR_execve) { + return (long)execve((const char *)arg1, (char *const *)arg2, (char *const *)arg3); + } +#endif + +#ifdef __NR_execveat + if (number == __NR_execveat && arg2 && ((const char *)arg2)[0] != '\0' && + (((const char *)arg2)[0] == '/' || (int)arg1 == AT_FDCWD) && (arg5 & ~(unsigned long)AT_EMPTY_PATH) == 0) { + return (long)execve((const char *)arg2, (char *const *)arg3, (char *const *)arg4); + } +#endif + #ifdef __NR_clone3 if (number == __NR_clone3) { errno = ENOSYS; diff --git a/tools/nativeguest/hook/signals.c b/tools/nativeguest/hook/signals.c index c2999885d4..4245ed75cf 100644 --- a/tools/nativeguest/hook/signals.c +++ b/tools/nativeguest/hook/signals.c @@ -10,6 +10,12 @@ #define SYS_SECCOMP 1 #endif +#if defined(__aarch64__) +#define DDNATV_HOST_AUDIT_ARCH 0xC00000B7U +#else +#define DDNATV_HOST_AUDIT_ARCH 0x40000028U +#endif + static int (*get_real_sigaction(void))(int, const struct sigaction *, struct sigaction *); // A program's own SIGSYS handler, for the traps of a seccomp filter it installed itself (Firefox's @@ -57,6 +63,12 @@ static long sigsys_id_change(int nr, const unsigned long long *regs, long ret_va // Intercept SECCOMP blocked syscalls (SIGSYS), resolve sandbox/landlock gracefully, and advance PC static void ddnatv_sigsys_handler(int sig, siginfo_t *info, void *ctx) { if (!ctx || !info) return; + int host_trap = info->si_code == SYS_SECCOMP && info->si_errno == 0 && info->si_arch == DDNATV_HOST_AUDIT_ARCH; + if (!host_trap && g_app_sigsys_set) { + if (g_app_sigsys.sa_flags & SA_SIGINFO) g_app_sigsys.sa_sigaction(sig, info, ctx); + else g_app_sigsys.sa_handler(sig); + return; + } if (info->si_code != SYS_SECCOMP) { int (*real_sig)(int, const struct sigaction *, struct sigaction *) = get_real_sigaction(); if (real_sig) { @@ -69,11 +81,6 @@ static void ddnatv_sigsys_handler(int sig, siginfo_t *info, void *ctx) { raise(sig); return; } - if (info->si_errno != 0 && g_app_sigsys_set) { - if (g_app_sigsys.sa_flags & SA_SIGINFO) g_app_sigsys.sa_sigaction(sig, info, ctx); - else g_app_sigsys.sa_handler(sig); - return; - } ucontext_t *uctx = (ucontext_t *)ctx; int sys_nr = info->si_syscall;