fix(native): a guest's own seccomp filter gets its SIGSYS, so Firefox tabs stop crashing (#2360)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-09 16:42:38 -05:00
1 parent c85b84a964
commit 1b19837fc6
5 files changed
+162 -13

No files matched your search

+10
View File
@@ -152,6 +152,16 @@ Prototype (inert unless `PROOT_FASTPATH` is set; see `docs/development/proot-per
natively reserve 256 GiB above 64 GiB for guest memory: under PRoot the reservation failed and
the first guest instruction faulted forever. 48-bit address spaces and 32-bit programs are
unchanged in practice.
- `0027-guest-seccomp-sigsys.patch` - PRoot treated every seccomp `SIGSYS` as Android's app policy
refusing a call: it emulated the few it knows and answered the rest with `ENOSYS`, so a filter
the guest installs itself never reached its own handler. Firefox's content sandbox traps
`openat` and opens files through a broker in the parent; every font open came back `ENOSYS`,
and each tab crashed in `gfxFontGroup::GetDefaultFont`. Android's policy traps with
`SECCOMP_RET_DATA` 0, while Firefox's and Chromium's filters tag their traps, so a tagged
`SIGSYS` is now delivered to the guest. A trap from the fast path's trampoline still gets
`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.
Old kernel fixes:
+49
View File
@@ -0,0 +1,49 @@
// Run inside a session, with and without the fast path: a seccomp filter the guest installs
// itself must reach its own SIGSYS handler, which answers the trapped openat.
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <linux/filter.h>
#include <linux/seccomp.h>
#include <signal.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <sys/prctl.h>
#include <sys/syscall.h>
#include <ucontext.h>
#include <unistd.h>
#define ANSWER 4242
static volatile int traps, data;
static void on_sigsys(int sig, siginfo_t *info, void *context) {
(void)sig;
ucontext_t *uc = context;
traps++;
data = info->si_errno;
uc->uc_mcontext.regs[0] = ANSWER;
}
int main(void) {
struct sigaction sa;
memset(&sa, 0, sizeof sa);
sa.sa_sigaction = on_sigsys;
sa.sa_flags = SA_SIGINFO;
sigaction(SIGSYS, &sa, NULL);
struct sock_filter code[] = {
BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, nr)),
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_openat, 0, 1),
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_TRAP | 7),
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),
};
struct sock_fprog filter = {.len = sizeof code / sizeof *code, .filter = code};
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) || prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &filter, 0, 0)) {
perror("seccomp");
return 77;
}
int fd = open("/etc/hostname", O_RDONLY);
int err = errno;
printf("open=%d errno=%d traps=%d data=%d\n", fd, fd < 0 ? err : 0, traps, data);
return fd == ANSWER && traps == 1 && data == 7 ? 0 : 1;
}
+38 -10
View File
@@ -49,7 +49,30 @@ static size_t rootlen;
static long long ttl_ns = 2000000000LL;
static unsigned long hits, misses;
static long sc(long nr, long a, long b, long c, long d, long e) { return fp_sys(nr, a, b, c, d, e, 0); }
// A seccomp filter the guest installs itself (Firefox's content sandbox) can trap a trampoline
// syscall that the host allows; proot answers those with ENOSYS. The call is then repeated
// through libc, where the guest's own SIGSYS handler sees the guest path, and the process stops
// using the fast path.
static __thread int fp_refused;
static int optional_syscall(long nr) {
return nr == SYS_statx || nr == SYS_memfd_create || nr == SYS_faccessat2 || nr == SYS_close_range ||
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;
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);
fp_refused = 1;
}
return r;
}
static inline int refused(void) {
if (!fp_refused) return 0;
fp_refused = 0;
return 1;
}
static inline int answered(long r) { return !refused() && r != FP_SLOW; }
static void fp_init(void);
static pthread_once_t init_once = PTHREAD_ONCE_INIT;
static inline int fp_ready(void) {
@@ -788,7 +811,7 @@ static int ret(long r) {
if (!real_##name) real_##name = (type)dlsym(RTLD_NEXT, #name)
#define ANSWER(r, dirfd, path, real_call) \
do { long r_ = (r); if (r_ != FP_SLOW) { hits++; return ret(r_); } missed(__func__, dirfd, path); return real_call; } while (0)
do { long r_ = (r); if (answered(r_)) { hits++; return ret(r_); } missed(__func__, dirfd, path); return real_call; } while (0)
static long fp_open(int dirfd, const char *path, int flags, mode_t mode) {
@@ -805,7 +828,7 @@ static long fp_open(int dirfd, const char *path, int flags, mode_t mode) {
static int do_openat(int dirfd, const char *path, int flags, mode_t mode, int (*real)(int, const char *, int, ...)) {
long r = fp_open(dirfd, path, flags, mode);
if (r != FP_SLOW) { hits++; return ret(r); }
if (answered(r)) { hits++; return ret(r); }
missed(__func__, dirfd, path);
return real(dirfd, path, flags, mode);
}
@@ -870,8 +893,10 @@ int lstat64(const char *p, struct stat64 *st) { return lstat(p, (struct stat *)s
int fstat(int fd, struct stat *st) {
REAL(fstat, int (*)(int, struct stat *));
if (!fp_ready()) return real_fstat(fd, st);
long r = sc(SYS_fstat, fd, (long)st, 0, 0, 0);
if (!answered(r)) return real_fstat(fd, st);
hits++;
return ret(sc(SYS_fstat, fd, (long)st, 0, 0, 0));
return ret(r);
}
int fstat64(int fd, struct stat64 *st) { return fstat(fd, (struct stat *)st); }
@@ -989,7 +1014,7 @@ static long fp_access(int dirfd, const char *path, int mode, int flags) {
static int access_common(int dirfd, const char *path, int mode, int flags) {
REAL(faccessat, int (*)(int, const char *, int, int));
long rs = fp_access(dirfd, path, mode, flags);
if (rs != FP_SLOW) { hits++; return ret(rs); }
if (answered(rs)) { hits++; return ret(rs); }
missed(__func__, dirfd, path);
if (flags == 0) return (int)syscall(SYS_faccessat, dirfd, path, mode);
return real_faccessat(dirfd, path, mode, flags);
@@ -1087,7 +1112,7 @@ char *canonicalize_file_name(const char *path) { return realpath(path, NULL); }
char *getcwd(char *buf, size_t size) {
REAL(getcwd, char *(*)(char *, size_t));
char g[PATH_MAX];
if (!fp_ready() || own_cwd(g) == FP_SLOW) { missed(__func__, AT_FDCWD, "."); return real_getcwd(buf, size); }
if (!fp_ready() || own_cwd(g) == FP_SLOW || refused()) { missed(__func__, AT_FDCWD, "."); return real_getcwd(buf, size); }
hits++;
size_t need = strlen(g) + 1;
if (buf && size == 0) { errno = EINVAL; return NULL; }
@@ -1181,7 +1206,7 @@ static long fp_rename(int olddirfd, const char *old, int newdirfd, const char *n
static int rename_common(int olddirfd, const char *old, int newdirfd, const char *new, unsigned flags) {
REAL(renameat2, int (*)(int, const char *, int, const char *, unsigned));
long rs = fp_rename(olddirfd, old, newdirfd, new, flags);
if (rs != FP_SLOW) { hits++; return ret(rs); }
if (answered(rs)) { hits++; return ret(rs); }
missed(__func__, olddirfd, old);
if (!flags) return (int)syscall(SYS_renameat, olddirfd, old, newdirfd, new);
return real_renameat2(olddirfd, old, newdirfd, new, flags);
@@ -1355,7 +1380,7 @@ static long fp_getxattr(const char *path, const char *name, void *value, size_t
static ssize_t getxattr_common(const char *path, const char *name, void *value, size_t size, int follow,
ssize_t (*real)(const char *, const char *, void *, size_t)) {
long rs = fp_getxattr(path, name, value, size, follow);
if (rs != FP_SLOW) { hits++; return rs < 0 ? ret(rs) : rs; }
if (answered(rs)) { hits++; return rs < 0 ? ret(rs) : rs; }
missed(__func__, AT_FDCWD, path);
return real(path, name, value, size);
}
@@ -1378,7 +1403,7 @@ static long fp_listxattr(const char *path, char *list, size_t size, int follow)
static ssize_t listxattr_common(const char *path, char *list, size_t size, int follow,
ssize_t (*real)(const char *, char *, size_t)) {
long rs = fp_listxattr(path, list, size, follow);
if (rs != FP_SLOW) { hits++; return rs < 0 ? ret(rs) : rs; }
if (answered(rs)) { hits++; return rs < 0 ? ret(rs) : rs; }
missed(__func__, AT_FDCWD, path);
return real(path, list, size);
}
@@ -1581,6 +1606,7 @@ static int accept_common(int fd, struct sockaddr *addr, socklen_t *len, int flag
struct sockaddr_storage got;
socklen_t got_len = sizeof got;
long r = sc(SYS_accept4, fd, addr ? (long)&got : 0, addr ? (long)&got_len : 0, flags, 0);
if (refused()) return real_accept4(fd, addr, len, flags);
if (r >= 0) inherit_long_name(fd, (int)r);
if (!addr) return ret(r);
if (r >= 0) report_address((int)r, LONG_PEER, &got, got_len, addr, len);
@@ -1595,6 +1621,7 @@ static int name_common(long nr, int fd, struct sockaddr *addr, socklen_t *len, i
struct sockaddr_storage got;
socklen_t got_len = sizeof got;
long r = sc(nr, fd, (long)&got, (long)&got_len, 0, 0);
if (refused()) return real(fd, addr, len);
if (r == 0) report_address(fd, nr == SYS_getsockname ? LONG_SELF : LONG_PEER, &got, got_len, addr, len);
return ret(r);
}
@@ -1687,7 +1714,7 @@ static int online_cpus(void) {
int get_nprocs(void) {
REAL(get_nprocs, int (*)(void));
int n = fp_ready() ? online_cpus() : -1;
if (n > 0) { hits++; return n; }
if (n > 0 && !refused()) { hits++; return n; }
missed(__func__, AT_FDCWD, "(nprocs)");
return real_get_nprocs();
}
@@ -1743,6 +1770,7 @@ int isatty(int fd) {
if (!fp_ready()) return real_isatty(fd);
hits++;
long r = sc(SYS_ioctl, fd, TCGETS, (long)&k, 0, 0);
if (refused()) return real_isatty(fd);
if (r < 0) { errno = (int)-r; return 0; }
return r == 0;
}
+6 -3
View File
@@ -74,11 +74,14 @@ long fp_svc_dispatch(const long *r) {
int saved_errno = errno;
long result = svc_blocked(r);
uintptr_t frame = (uintptr_t)r;
if (result == FP_SLOW && (!svc_busy || frame >= svc_busy)) {
if (result == FP_SLOW && __atomic_load_n(&fp_on, __ATOMIC_RELAXED) && (!svc_busy || frame >= svc_busy)) {
uintptr_t previous = svc_busy;
svc_busy = frame;
if (svc_stack_room(frame)) { result = svc_path_call(r); svc_busy = 0; }
else svc_busy = previous;
if (svc_stack_room(frame)) {
result = svc_path_call(r);
if (refused()) result = FP_SLOW;
svc_busy = 0;
} else svc_busy = previous;
}
if (result == FP_SLOW) {
__atomic_fetch_add(&svc_slow, 1, __ATOMIC_RELAXED);
@@ -0,0 +1,59 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kurt Himebauch
Date: Mon, 9 Nov 2026 15:30:00 -0500
Subject: [PATCH] seccomp: hand a guest filter's own SIGSYS back to the guest
---
--- a/src/tracee/seccomp.h
+++ b/src/tracee/seccomp.h
@@ -1,3 +1,4 @@
+#include <signal.h>
#include "tracee/tracee.h"
#include "sys/vfs.h"
@@ -18,5 +19,5 @@
void restart_syscall_after_seccomp(Tracee* tracee);
void set_result_after_seccomp(Tracee *tracee, word_t result);
-int handle_seccomp_event(Tracee* tracee);
+int handle_seccomp_event(Tracee* tracee, const siginfo_t *siginfo);
void fix_and_restart_enosys_syscall(Tracee* tracee);
--- a/src/tracee/seccomp.c
+++ b/src/tracee/seccomp.c
@@ -68,7 +68,7 @@
*
* Return 0 to swallow signal or SIGSYS to deliver it to process.
*/
-int handle_seccomp_event(Tracee* tracee)
+int handle_seccomp_event(Tracee* tracee, const siginfo_t *siginfo)
{
int ret;
@@ -100,6 +100,16 @@
print_current_regs(tracee, 3, "seccomp SIGSYS");
+ /* Android's app policy traps with SECCOMP_RET_DATA 0. A filter the guest
+ * installed itself (Firefox's and Chromium's sandboxes) tags its traps, and
+ * its own SIGSYS handler answers them, usually through a broker process.
+ * A trap from the fast path's trampoline still gets ENOSYS: its arguments
+ * are host paths, and the fast path repeats the call through libc. */
+ if (siginfo->si_errno != 0 && !from_fastpath_stub(tracee)) {
+ VERBOSE(tracee, 4, "SIGSYS from the guest's own seccomp filter (data %d)", siginfo->si_errno);
+ return SIGSYS;
+ }
+
return handle_seccomp_event_common(tracee);
}
--- a/src/tracee/event.c
+++ b/src/tracee/event.c
@@ -676,7 +676,7 @@
tracee->skip_next_seccomp_signal = false;
signal = 0;
} else {
- signal = handle_seccomp_event(tracee);
+ signal = handle_seccomp_event(tracee, &siginfo);
}
} else {
VERBOSE(tracee, 1, "non-seccomp SIGSYS");