From bde8c9fbedbe449ed33a7db6091bb2ed9afdd049 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:23:11 -0500 Subject: [PATCH] fix(native): __getcwd_chk checks its buffer, and seccomp-sim -a takes only call numbers --- tools/nativeguest/hook/fileops.c | 2 ++ tools/nativeguest/seccomp-sim.c | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/nativeguest/hook/fileops.c b/tools/nativeguest/hook/fileops.c index ae4e523b4..063b852e8 100644 --- a/tools/nativeguest/hook/fileops.c +++ b/tools/nativeguest/hook/fileops.c @@ -596,7 +596,9 @@ char *getcwd(char *buf, size_t size) { return res; } +extern void __chk_fail(void) __attribute__((__noreturn__)); char *__getcwd_chk(char *buf, size_t size, size_t buflen) { + if (size > buflen) __chk_fail(); return getcwd(buf, size); } diff --git a/tools/nativeguest/seccomp-sim.c b/tools/nativeguest/seccomp-sim.c index b68336845..7cea6b168 100644 --- a/tools/nativeguest/seccomp-sim.c +++ b/tools/nativeguest/seccomp-sim.c @@ -22,7 +22,15 @@ static const int blocked[] = {99, 100, 97, 217, 218, 219, 268, 277, 280, 293, 14 int main(int argc, char **argv) { int skip[MAX_ALLOWED], nskip = 0, arg = 1; if (argc > 3 && strcmp(argv[1], "-a") == 0) { - for (char *p = strtok(argv[2], ","); p && nskip < MAX_ALLOWED; p = strtok(NULL, ",")) skip[nskip++] = atoi(p); + for (char *p = strtok(argv[2], ","); p; p = strtok(NULL, ",")) { + char *end = NULL; + long nr = strtol(p, &end, 10); + if (end == p || *end != '\0' || nr < 0 || nr > 1023 || nskip == MAX_ALLOWED) { + fprintf(stderr, "seccomp-sim: -a takes up to %d system call numbers, not %s\n", MAX_ALLOWED, p); + return 2; + } + skip[nskip++] = (int)nr; + } arg = 3; } if (arg >= argc) return 2;