diff --git a/include/claybin/bpf/emit.hpp b/include/claybin/bpf/emit.hpp index dc5f74a..ffd61d0 100644 --- a/include/claybin/bpf/emit.hpp +++ b/include/claybin/bpf/emit.hpp @@ -19,6 +19,7 @@ #pragma once #include +#include #include #include "claybin/core/error.hpp" @@ -78,6 +79,7 @@ inline constexpr std::uint32_t kRetAllow = 0x7fff0000u; // audit arch tokens, needed for the arch guard. inline constexpr std::uint32_t kAuditArchX86_64 = 0xc000003eu; +inline constexpr std::uint32_t kAuditArchI386 = 0x40000003u; inline constexpr std::uint32_t kAuditArchAarch64 = 0xc00000b7u; inline constexpr std::uint32_t kAuditArchRiscv64 = 0xc00000f3u; @@ -136,6 +138,11 @@ std::vector fold_intervals(const SyscallPolicy& policy); // asked for. Result compile(const SyscallPolicy& policy, std::uint32_t arch = native_arch()); +// Explicit compatibility policy: supported only with an x86_64 native policy. +// No policy means the compatibility ABI is killed. i386 notification is unsupported. +Result compile(const SyscallPolicy& native, const std::optional& i386, + std::uint32_t arch = native_arch()); + // tiny reference interpreter over struct seccomp_data, used by tests to // differential-check the tree against a linear lookup. also handy for `explain`. std::uint32_t evaluate(const Program& prog, std::uint32_t nr, std::uint32_t arch); diff --git a/include/claybin/policy/policy.hpp b/include/claybin/policy/policy.hpp index 84b4ce6..6d0c4c8 100644 --- a/include/claybin/policy/policy.hpp +++ b/include/claybin/policy/policy.hpp @@ -10,6 +10,7 @@ #pragma once #include +#include #include #include #include @@ -69,6 +70,8 @@ struct PolicyData { NetAuthority net{}; ResourceLimits resources{}; SyscallPolicy syscalls{}; + // Absent means the i386 ABI is killed, never inferred from native numbers. + std::optional syscalls_i386{}; ProcOps proc{}; Isolation isolation{Isolation::process}; @@ -182,6 +185,8 @@ struct PolicyData { r.net = net.meet(o.net); r.resources = resources.meet(o.resources); r.syscalls = syscalls.meet(o.syscalls); + if (syscalls_i386 && o.syscalls_i386) + r.syscalls_i386 = syscalls_i386->meet(*o.syscalls_i386); r.proc = proc.meet(o.proc); // stronger isolation wins, and stronger is the larger enum value. r.isolation = isolation > o.isolation ? isolation : o.isolation; @@ -233,7 +238,9 @@ struct PolicyData { bool subsumes(const PolicyData& o) const { return fs.subsumes(o.fs) && net.subsumes(o.net) && resources.subsumes(o.resources) && - syscalls.subsumes(o.syscalls) && proc.subsumes(o.proc) && + syscalls.subsumes(o.syscalls) && + (!o.syscalls_i386 || (syscalls_i386 && syscalls_i386->subsumes(*o.syscalls_i386))) && + proc.subsumes(o.proc) && keep_caps.subsumes(o.keep_caps) && isolation <= o.isolation; } @@ -475,6 +482,10 @@ class Policy { data_.syscalls = std::move(p); return std::move(*this); } + Policy&& syscall_profile_i386(SyscallPolicy p) && { + data_.syscalls_i386 = std::move(p); + return std::move(*this); + } // -- process ------------------------------------------------------------ Policy&& allow_fork() && { @@ -642,6 +653,9 @@ class Policy { d.net = NetAuthority::everything(); d.resources = ResourceLimits::everything(); d.syscalls = SyscallPolicy::everything(); +#if defined(__x86_64__) + d.syscalls_i386 = SyscallPolicy::everything(); +#endif d.proc = ProcOps::everything(); d.isolation = Isolation::process; d.env_cleared = false; diff --git a/include/claybin/policy/profiles_i386.hpp b/include/claybin/policy/profiles_i386.hpp new file mode 100644 index 0000000..766ea39 --- /dev/null +++ b/include/claybin/policy/profiles_i386.hpp @@ -0,0 +1,111 @@ +// Native Linux i386 syscall profiles. Numbers from Linux asm/unistd_32.h. +// Deliberately independent of the build host and of the x86_64 syscall table. +#pragma once +#include "claybin/policy/syscalls.hpp" + +namespace clay::profiles_i386 { +inline SyscallPolicy base() { + SyscallPolicy p; + p.set_default(SysAction::errno_, 1); + static constexpr SysNr calls[] = { + 0, 1, // restart_syscall,exit + 3, 4, 6, // read, write, close + 19, 140, // lseek, _llseek + 20, 24, 47, 49, 50, 64, // pid/uid/gid/euid/egid/ppid + 199, 200, 201, 202, // 32-bit uid/gid variants + 33, // access + 13, 27, 104, 105, // time,alarm,setitimer,getitimer + 29, // pause + 43, // times + 57, 65, 66, 132, 147, // setpgid,getpgrp,setsid,getpgid,getsid + 45, // brk + 54, 55, 221, // ioctl, fcntl, fcntl64 + 77, 78, // getrusage,gettimeofday + 91, 125, 163, 192, 218, 219, // munmap,mprotect,mremap,mmap2,mincore,madvise + 106, 107, 108, 195, 196, 197, // stat/lstat/fstat and stat64 variants + 119, 173, 174, 175, 176, 177, 179, 186, // signal handling + 122, // uname + 158, 162, // sched_yield,nanosleep + 180, 181, 183, // pread64,pwrite64,getcwd + 184, // capget + 191, // ugetrlimit + 224, 240, 242, 243, 244, // gettid,futex,affinity,set/get_thread_area + 252, 258, // exit_group,set_tid_address + 265, 266, 267, // clock_gettime/getres/nanosleep + 311, 312, // set/get_robust_list + 42,41,63,330,331, // pipe,dup,dup2,dup3,pipe2 + 254,329,256,319,255, // epoll_create/create1/wait/pwait/ctl + 142,168,309,308, // _newselect,poll,ppoll,pselect6 + 340,116,99,100, // prlimit64,sysinfo,statfs,fstatfs + 414,413, // ppoll_time64,pselect6_time64 + 355, // getrandom + 375, 380, 381, 382, // membarrier,pkey_mprotect/alloc/free + 386, // rseq + 403, 406, 407, 422, // clock_gettime64/getres64/nanosleep64,futex_time64 + 436, // close_range + }; + p.allow(std::span{calls}); + // The old mmap takes a pointer: seccomp cannot inspect its prot field. + p.deny(90, 38); + p.deny(435, 38); // clone3: force inspectable clone fallback + for (SysNr nr : {192u, 125u, 380u}) + p.deny_arg_all(nr, 2, 6, SysAction::errno_, 1); + static constexpr std::uint32_t prctl[] = { + 1,2,3,4,15,16,21,23,27,29,30,36,37,38,39,40,41,42,0x53564d41}; + p.allow(172); + p.allow_arg32_only(172, 0, std::span{prctl}, SysAction::errno_, 1); + static constexpr std::uint32_t personality[] = {0, 0xffffffffu}; + p.allow(136); + p.allow_arg32_only(136, 0, std::span{personality}, SysAction::errno_, 1); + static constexpr std::uint32_t ioctl[] = { + 0x5401,0x5402,0x5403,0x5404,0x5405,0x5409,0x540a,0x540b, + 0x5413,0x5414,0x540f,0x5410,0x541b,0x5421,0x5450,0x5451,0x5411}; + p.allow_arg32_only(54, 1, std::span{ioctl}, SysAction::errno_, 1); + for (SysNr nr : {26u /* ptrace */, 21u /* mount */, 52u /* umount2 */, + 217u /* pivot_root */, 61u /* chroot */, 310u /* unshare */, + 346u /* setns */, 357u /* bpf */, 336u /* perf_event_open */, + 128u,129u,350u /* modules */, 283u, /* kexec_load */ + 101u,110u, /* ioperm,iopl */ 286u,287u,288u, /* keyring */ + 374u /* userfaultfd */, 425u,426u,427u /* io_uring */, + 428u,429u,430u,431u,432u,433u,442u /* mount APIs */}) + p.kill(nr); + return p; +} + +inline SyscallPolicy compiler() { + auto p = base(); + static constexpr SysNr calls[] = { + 2, 11, 114, 120, 190, 284, // fork,execve,wait4,clone,vfork,waitid + 5,8,9,10,12,14,15,16,38,39,40,41,42,60,63,83,85,92,93,94,95, + 118,133,141,145,146,148,193,194,220,229,230,231,232,233,234, + 239,250,254,255,256,268,269,271,272,295,296,297,298,299,300, + 301,302,303,304,305,306,307,308,309,319,324,328,329,330,331, + 333,334,340,353,358,378,379,383,439, + 116,99,100,168,142, // sysinfo,statfs,fstatfs,poll,_newselect + 187, // sendfile + 414,413, // ppoll_time64,pselect6_time64 + }; + p.allow(std::span{calls}); + // No process profile grants keyring access. + p.deny_arg_any(120, 0, 0x00020000ull | 0x02000000ull | 0x04000000ull | + 0x08000000ull | 0x10000000ull | 0x20000000ull | 0x40000000ull, + SysAction::errno_, 1); + // kill/tkill/pidfd_send_signal remain EPERM; no compatibility notify broker. + return p; +} + +inline SyscallPolicy compiler_with_network() { + auto p = compiler(); + // socketcall's pointer arguments cannot be checked for an allowed address + // family. Use the direct i386 socket syscalls instead, matching native + // argument filtering; old multiplexed socket creation stays fail-closed. + p.deny(102, 38); + static constexpr SysNr calls[] = { + 345,337, // sendmmsg,recvmmsg + 359,360,361,362,363,364,365,366,367,368,369,370,371,372,373, + 417, // recvmmsg_time64 + }; + p.allow(std::span{calls}); + return p; +} +} // namespace clay::profiles_i386 diff --git a/src/bpf/emit.cpp b/src/bpf/emit.cpp index 2eeb8cb..2bf9c2f 100644 --- a/src/bpf/emit.cpp +++ b/src/bpf/emit.cpp @@ -148,11 +148,17 @@ Result compile(const SyscallPolicy& policy, std::uint32_t arch) { out.push_back(jeq(0xffffffffu, 0, 1)); out.push_back(ret(kRetAllow)); - if (arch == kAuditArchX86_64) { + if (arch == kAuditArchX86_64 || arch == kAuditArchI386) { // reject the x32 range outright rather than trying to reason about it. out.push_back(jge(kX32SyscallBit, 0, 1)); out.push_back(ret(kRetKillProcess)); } + if (arch == kAuditArchX86_64) { + // Before Linux 5.4 these untagged numbers entered x32 handlers too. + out.push_back(jge(512, 0, 2)); + out.push_back(jgt(547, 1, 0)); + out.push_back(ret(kRetKillProcess)); + } // ---- argument rules, before the interval tree ------------------------ // @@ -355,6 +361,33 @@ Result compile(const SyscallPolicy& policy, std::uint32_t arch) { return prog; } +Result compile(const SyscallPolicy& native, const std::optional& i386, + std::uint32_t arch) { + if (!i386) return compile(native, arch); + if (arch != kAuditArchX86_64) + return std::unexpected(Error{Errc::unsupported, "seccomp: i386 requires x86_64 native ABI"}); + if (i386->default_action() == SysAction::notify || + std::any_of(i386->rules().begin(), i386->rules().end(), + [](const auto& r) { return r.action == SysAction::notify; }) || + std::any_of(i386->arg_rules().begin(), i386->arg_rules().end(), + [](const auto& r) { return r.action == SysAction::notify; })) + return std::unexpected(Error{Errc::unsupported, "seccomp: i386 notification unsupported"}); + auto n = compile(native, arch); + if (!n) return std::unexpected(n.error()); + auto c = compile(*i386, kAuditArchI386); + if (!c) return std::unexpected(c.error()); + // Use long jumps: policy bodies routinely exceed conditional jump reach. + std::vector out{ld_abs(kOffArch), jeq(arch, 0, 1), ja(3), + jeq(kAuditArchI386, 1, 0), ret(kRetKillProcess), + ja(static_cast(n->insns.size()))}; + out.insert(out.end(), n->insns.begin(), n->insns.end()); + out.insert(out.end(), c->insns.begin(), c->insns.end()); + if (out.size() > 4096) + return std::unexpected(Error{Errc::unsupported, "seccomp: combined filter too large"}); + n->insns = std::move(out); + return n; +} + std::uint32_t evaluate(const Program& prog, std::uint32_t nr, std::uint32_t arch) { return evaluate_with_args(prog, nr, arch, nullptr); } diff --git a/src/plan/compile.cpp b/src/plan/compile.cpp index c1994b0..147aa96 100644 --- a/src/plan/compile.cpp +++ b/src/plan/compile.cpp @@ -1208,6 +1208,16 @@ Result compile(const Policy& policy, const HostCapabilities& h // -- phase: seccomp (last wall) --------------------------------------- if (host.seccomp) { SyscallPolicy sys = d.syscalls; + if (d.syscalls_i386) { + const auto& compat = *d.syscalls_i386; + const auto notifies = [](const auto& rule) { return rule.action == SysAction::notify; }; + if (compat.default_action() == SysAction::notify || + std::any_of(compat.rules().begin(), compat.rules().end(), notifies) || + std::any_of(compat.arg_rules().begin(), compat.arg_rules().end(), notifies) || + std::any_of(compat.arg_allow_sets().begin(), compat.arg_allow_sets().end(), notifies)) + return std::unexpected(Error{Errc::unsupported, + "i386 seccomp notifications require an architecture-aware broker"}); + } if (sys.default_action() == SysAction::kill_process && sys.rules().empty()) { // a policy that never named a syscall would kill the child before it // could exec. that is a policy bug, not something to paper over. @@ -1239,7 +1249,7 @@ Result compile(const Policy& policy, const HostCapabilities& h // grant: it has no descriptor to send on once the handshake fd is closed. if (wants_notify) sys.allow(46 /* sendmsg */); - auto prog = bpf::compile(sys); + auto prog = bpf::compile(sys, d.syscalls_i386); if (!prog) return std::unexpected(prog.error()); auto blob = std::span{ @@ -1259,12 +1269,16 @@ Result compile(const Policy& policy, const HostCapabilities& h // compiled to SyscallPolicy::everything() and the report cheerfully // said `strong syscall.filter`, which would have put a green wall on // screen for a filter the user had just turned off. - if (sys.default_action() == SysAction::allow && sys.rules().empty() && - sys.arg_rules().empty() && sys.arg_allow_sets().empty()) { + const auto unfiltered = [](const SyscallPolicy& p) { + return p.default_action() == SysAction::allow && p.rules().empty() && + p.arg_rules().empty() && p.arg_allow_sets().empty(); + }; + if (unfiltered(sys) || (d.syscalls_i386 && unfiltered(*d.syscalls_i386))) { report.record(CapId::syscall_filter, Enforcement::partial, - "seccomp-bpf: arch guard only, all syscalls permitted"); + "seccomp-bpf: arch guard only for an enabled ABI, all its syscalls permitted"); } else { - report.record(CapId::syscall_filter, Enforcement::strong, "seccomp-bpf"); + report.record(CapId::syscall_filter, Enforcement::strong, + d.syscalls_i386 ? "seccomp-bpf: x86_64+i386 (x32 denied)" : "seccomp-bpf"); } out.brokers_syscalls = wants_notify; } else { diff --git a/tests/bpf_emit_test.cpp b/tests/bpf_emit_test.cpp index f4610db..8f49b4e 100644 --- a/tests/bpf_emit_test.cpp +++ b/tests/bpf_emit_test.cpp @@ -7,6 +7,8 @@ #include "claybin/bpf/emit.hpp" #include "claybin/policy/profiles.hpp" +#include "claybin/policy/profiles_i386.hpp" +#include "claybin/policy/policy.hpp" using namespace clay; using namespace clay::bpf; @@ -25,7 +27,7 @@ void differential(const SyscallPolicy& p, std::uint32_t max_nr = 600) { if (!prog) return; for (SysNr nr = 0; nr < max_nr; ++nr) { std::uint32_t got = evaluate(*prog, nr, kAuditArchX86_64); - std::uint32_t want = reference(p, nr); + std::uint32_t want = nr >= 512 && nr <= 547 ? kRetKillProcess : reference(p, nr); if (got != want) { std::fprintf(stderr, " nr=%u got=%#x want=%#x\n", nr, got, want); CHECK_EQ(got, want); @@ -38,6 +40,73 @@ void differential(const SyscallPolicy& p, std::uint32_t max_nr = 600) { } // namespace int main() { + { + auto native = SyscallPolicy::everything(); + auto compat = profiles_i386::compiler(); + auto prog = compile(native, std::optional{compat}, kAuditArchX86_64); + CHECK(prog.has_value()); + if (prog) { + CHECK_EQ(evaluate(*prog, 11, kAuditArchI386), kRetAllow); // execve + for (auto nr : {13u, 27u, 104u, 105u, 29u, 57u, 65u, 66u, 132u, 147u}) + CHECK_EQ(evaluate(*prog, nr, kAuditArchI386), kRetAllow); + CHECK_EQ(evaluate(*prog, 3, 0u), kRetKillProcess); // unknown audit arch + // Upstream's tracer-cancelled syscall exception applies only after + // architecture validation, and must survive multi-ABI dispatch. + CHECK_EQ(evaluate(*prog, 0xffffffffu, kAuditArchX86_64), kRetAllow); + CHECK_EQ(evaluate(*prog, 0xffffffffu, kAuditArchI386), kRetAllow); + CHECK_EQ(evaluate(*prog, 0xffffffffu, 0u), kRetKillProcess); + CHECK_EQ(evaluate(*prog, 59, kAuditArchI386), kRetErrno | 1u); + CHECK_EQ(evaluate(*prog, 59, kAuditArchX86_64), kRetAllow); + CHECK_EQ(evaluate(*prog, 11, kAuditArchAarch64), kRetKillProcess); + for (auto nr : {512u, 513u, 547u, 0x40000000u, 0x40000200u}) + CHECK_EQ(evaluate(*prog, nr, kAuditArchX86_64), kRetKillProcess); + for (auto nr : {511u, 548u}) + CHECK_EQ(evaluate(*prog, nr, kAuditArchX86_64), kRetAllow); + CHECK_EQ(evaluate(*prog, 0x40000003u, kAuditArchI386), kRetKillProcess); + CHECK_EQ(evaluate(*prog, 90, kAuditArchI386), kRetErrno | 38u); + for (auto nr : {192u,125u,380u}) { + std::uint64_t args[6]{}; + args[2] = 6; + CHECK_EQ(evaluate_with_args(*prog, nr, kAuditArchI386, args), kRetErrno | 1u); + args[2] = 5; + CHECK_EQ(evaluate_with_args(*prog, nr, kAuditArchI386, args), kRetAllow); + } + std::uint64_t args[6]{0x10000000u}; + CHECK_EQ(evaluate_with_args(*prog, 120, kAuditArchI386, args), kRetErrno | 1u); + args[0] = 0x100; + CHECK_EQ(evaluate_with_args(*prog, 120, kAuditArchI386, args), kRetAllow); + CHECK_EQ(evaluate(*prog, 37, kAuditArchI386), kRetErrno | 1u); // kill + CHECK_EQ(evaluate(*prog, 26, kAuditArchI386), kRetKillProcess); // ptrace + CHECK_EQ(evaluate(*prog, 288, kAuditArchI386), kRetKillProcess); // keyctl + args[1] = 0x100005401ull; // ioctl ignores upper register bits + CHECK_EQ(evaluate_with_args(*prog, 54, kAuditArchI386, args), kRetAllow); + args[1] = 0x5412; // TIOCSTI + CHECK_EQ(evaluate_with_args(*prog, 54, kAuditArchI386, args), kRetErrno | 1u); + } + auto only_native = compile(native, std::optional{}, kAuditArchX86_64); + CHECK(only_native.has_value()); + CHECK_EQ(evaluate(*only_native, 11, kAuditArchI386), kRetKillProcess); + compat.notify(3); + CHECK(!compile(native, std::optional{compat}, kAuditArchX86_64)); + auto network = profiles_i386::compiler_with_network(); + CHECK_EQ(network.action_for(102), SysAction::errno_); + CHECK_EQ(network.errno_for(102), std::uint16_t{38}); + auto network_prog = compile(native, std::optional{network}, kAuditArchX86_64); + CHECK(network_prog.has_value()); + if (network_prog) { + CHECK_EQ(evaluate(*network_prog, 102, kAuditArchI386), kRetErrno | 38u); + CHECK_EQ(evaluate(*network_prog, 359, kAuditArchI386), kRetAllow); // socket + } + PolicyData a, b; + a.syscalls_i386 = profiles_i386::compiler(); + CHECK(a.subsumes(b)); + CHECK(!b.subsumes(a)); + CHECK(!a.meet(b).syscalls_i386); + CHECK(!b.meet(a).syscalls_i386); + b.syscalls_i386 = SyscallPolicy::everything(); + CHECK(b.subsumes(a)); + CHECK(a.meet(b).syscalls_i386.has_value()); + } // -- arch guard -------------------------------------------------------- { SyscallPolicy p; diff --git a/tests/plan_test.cpp b/tests/plan_test.cpp index 816af98..0f76056 100644 --- a/tests/plan_test.cpp +++ b/tests/plan_test.cpp @@ -7,12 +7,49 @@ #include "claybin/plan/compile.hpp" #include "claybin/plan/plan.hpp" #include "claybin/policy/profiles.hpp" +#include "claybin/policy/profiles_i386.hpp" using namespace clay; using namespace clay::test; using namespace clay::literals; int main() { +#if defined(__linux__) && defined(__x86_64__) + // An enabled, unfiltered compat ABI weakens even a filtered native policy. + for (bool compat_filtered : {false, true}) { + auto p = Policy{} + .syscall_profile(profiles::compiler()) + .syscall_profile_i386(compat_filtered ? profiles_i386::compiler() + : SyscallPolicy::everything()) + .seal(); + auto c = compile(p, HostCapabilities::modern_linux()); + CHECK(c.has_value()); + if (!c) continue; + CHECK_EQ(c->guarantees.strength(CapId::syscall_filter), + compat_filtered ? Enforcement::strong : Enforcement::partial); + const std::string_view mechanism = c->guarantees.mechanism(CapId::syscall_filter); + if (compat_filtered) { + CHECK(mechanism.find("x86_64+i386") != std::string_view::npos); + CHECK(mechanism.find("x32 denied") != std::string_view::npos); + } else { + CHECK(mechanism.find("arch guard only") != std::string_view::npos); + } + } + // A native-only broker must never decode a compatibility syscall number. + for (int kind : {0, 1, 2, 3}) { + auto compat = profiles_i386::compiler(); + if (kind == 0) compat.set_default(SysAction::notify); + if (kind == 1) compat.set(26, SysAction::notify); + if (kind == 2) compat.deny_arg_all(125, 2, 6, SysAction::notify); + if (kind == 3) { + static constexpr std::uint32_t allowed[] = {1}; + compat.allow_arg32_only(999, 1, allowed, SysAction::notify); + } + auto policy = Policy{}.syscall_profile(profiles::compiler()) + .syscall_profile_i386(std::move(compat)).seal(); + CHECK(!compile(policy, HostCapabilities::modern_linux()).has_value()); + } +#endif // -- arena: refs resolve, strings are shared -------------------------- { PlanBuilder b; diff --git a/tests/support/i386_table.hpp b/tests/support/i386_table.hpp new file mode 100644 index 0000000..6601141 --- /dev/null +++ b/tests/support/i386_table.hpp @@ -0,0 +1,106 @@ +// Keep asm/unistd_32.h isolated from syscall_table_test's native SYS_* macros. +#pragma once +#include "harness.hpp" +#include "claybin/policy/profiles_i386.hpp" + +#if defined(__linux__) && defined(__x86_64__) && __has_include() +#include +namespace clay::test { +inline void check_i386_table() { + struct Entry { SysNr nr; SysNr kernel; }; +#define I386(name, nr) Entry{nr, __NR_##name} + // Independent names resolve through the host kernel's real i386 table. + // Includes every syscall literal in all three profiles, including denies + // and argument rules. The coverage walk below rejects unreviewed additions. + const Entry expected[] = { + I386(restart_syscall,0), I386(exit,1), I386(fork,2), I386(read,3), + I386(write,4), I386(open,5), I386(close,6), I386(creat,8), I386(link,9), + I386(unlink,10), I386(execve,11), I386(chdir,12), I386(time,13), + I386(mknod,14), I386(chmod,15), I386(lchown,16), I386(lseek,19), + I386(getpid,20), I386(mount,21), I386(getuid,24), I386(ptrace,26), + I386(alarm,27), I386(pause,29), I386(access,33), I386(rename,38), + I386(mkdir,39), I386(rmdir,40), I386(dup,41), I386(pipe,42), + I386(times,43), I386(brk,45), I386(getgid,47), I386(geteuid,49), + I386(getegid,50), I386(umount2,52), I386(ioctl,54), I386(fcntl,55), + I386(setpgid,57), I386(umask,60), I386(chroot,61), I386(dup2,63), + I386(getppid,64), I386(getpgrp,65), I386(setsid,66), + I386(getrusage,77), I386(gettimeofday,78), I386(symlink,83), + I386(readlink,85), I386(mmap,90), I386(munmap,91), I386(truncate,92), + I386(ftruncate,93), I386(fchmod,94), I386(fchown,95), + I386(statfs,99), I386(fstatfs,100), I386(ioperm,101), I386(socketcall,102), + I386(setitimer,104), I386(getitimer,105), I386(stat,106), + I386(lstat,107), I386(fstat,108), I386(iopl,110), I386(wait4,114), + I386(sysinfo,116), I386(fsync,118), I386(sigreturn,119), I386(clone,120), + I386(uname,122), I386(mprotect,125), I386(init_module,128), + I386(delete_module,129), I386(getpgid,132), I386(fchdir,133), + I386(personality,136), I386(_llseek,140), I386(getdents,141), + I386(_newselect,142), I386(readv,145), I386(writev,146), I386(getsid,147), + I386(fdatasync,148), I386(sched_yield,158), I386(nanosleep,162), + I386(mremap,163), I386(poll,168), I386(prctl,172), I386(rt_sigreturn,173), + I386(rt_sigaction,174), I386(rt_sigprocmask,175), I386(rt_sigpending,176), + I386(rt_sigtimedwait,177), I386(rt_sigsuspend,179), I386(capget,184), + I386(pread64,180), I386(pwrite64,181), I386(getcwd,183), + I386(sigaltstack,186), I386(sendfile,187), I386(vfork,190), + I386(ugetrlimit,191), I386(mmap2,192), I386(truncate64,193), + I386(ftruncate64,194), I386(stat64,195), I386(lstat64,196), I386(fstat64,197), + I386(getuid32,199), I386(getgid32,200), I386(geteuid32,201), + I386(getegid32,202), I386(pivot_root,217), I386(mincore,218), + I386(madvise,219), I386(getdents64,220), I386(fcntl64,221), I386(gettid,224), + I386(getxattr,229), I386(lgetxattr,230), I386(fgetxattr,231), + I386(listxattr,232), I386(llistxattr,233), I386(flistxattr,234), + I386(sendfile64,239), I386(futex,240), I386(sched_getaffinity,242), + I386(set_thread_area,243), I386(get_thread_area,244), I386(fadvise64,250), + I386(exit_group,252), I386(epoll_create,254), I386(epoll_ctl,255), + I386(epoll_wait,256), I386(set_tid_address,258), I386(clock_gettime,265), + I386(clock_getres,266), I386(clock_nanosleep,267), I386(statfs64,268), + I386(fstatfs64,269), I386(utimes,271), I386(fadvise64_64,272), + I386(kexec_load,283), I386(waitid,284), I386(add_key,286), + I386(request_key,287), I386(keyctl,288), I386(openat,295), + I386(mkdirat,296), I386(mknodat,297), I386(fchownat,298), + I386(futimesat,299), I386(fstatat64,300), I386(unlinkat,301), + I386(renameat,302), I386(linkat,303), I386(symlinkat,304), + I386(readlinkat,305), I386(fchmodat,306), I386(faccessat,307), + I386(pselect6,308), I386(ppoll,309), I386(unshare,310), + I386(set_robust_list,311), I386(get_robust_list,312), I386(epoll_pwait,319), + I386(fallocate,324), I386(eventfd2,328), I386(epoll_create1,329), + I386(dup3,330), I386(pipe2,331), I386(preadv,333), I386(pwritev,334), + I386(perf_event_open,336), I386(recvmmsg,337), I386(prlimit64,340), + I386(sendmmsg,345), I386(setns,346), I386(finit_module,350), + I386(renameat2,353), I386(getrandom,355), I386(bpf,357), I386(execveat,358), + I386(socket,359), I386(socketpair,360), I386(bind,361), I386(connect,362), + I386(listen,363), I386(accept4,364), I386(getsockopt,365), + I386(setsockopt,366), I386(getsockname,367), I386(getpeername,368), + I386(sendto,369), I386(sendmsg,370), I386(recvfrom,371), I386(recvmsg,372), + I386(shutdown,373), I386(userfaultfd,374), I386(membarrier,375), + I386(preadv2,378), I386(pwritev2,379), I386(pkey_mprotect,380), + I386(pkey_alloc,381), I386(pkey_free,382), I386(statx,383), I386(rseq,386), + I386(clock_gettime64,403), I386(clock_getres_time64,406), + I386(clock_nanosleep_time64,407), I386(pselect6_time64,413), + I386(ppoll_time64,414), I386(recvmmsg_time64,417), I386(futex_time64,422), + I386(io_uring_setup,425), I386(io_uring_enter,426), I386(io_uring_register,427), + I386(open_tree,428), I386(move_mount,429), I386(fsopen,430), + I386(fsconfig,431), I386(fsmount,432), I386(fspick,433), I386(clone3,435), + I386(close_range,436), I386(faccessat2,439), I386(mount_setattr,442), + }; +#undef I386 + for (auto e : expected) CHECK_EQ(e.nr, e.kernel); + const auto reviewed = [&](SysNr nr) { + for (auto e : expected) if (e.nr == nr) return true; + std::fprintf(stderr, "unreviewed i386 syscall number: %u\n", nr); + return false; + }; + for (const auto& p : {profiles_i386::base(), profiles_i386::compiler(), + profiles_i386::compiler_with_network()}) { + for (const auto& r : p.rules()) CHECK(reviewed(r.nr)); + for (const auto& r : p.arg_rules()) CHECK(reviewed(r.nr)); + for (const auto& r : p.arg_allow_sets()) CHECK(reviewed(r.nr)); + } +} +} // namespace clay::test +#else +namespace clay::test { +inline void check_i386_table() { + std::fprintf(stderr, "skip i386 kernel table: asm/unistd_32.h unavailable\n"); +} +} +#endif diff --git a/tests/syscall_table_test.cpp b/tests/syscall_table_test.cpp index dc0b8bf..7e0a033 100644 --- a/tests/syscall_table_test.cpp +++ b/tests/syscall_table_test.cpp @@ -251,7 +251,10 @@ bool permitted(const SyscallPolicy& p, long nr) { } // namespace +namespace clay::test { void check_i386_table(); } + int main() { + check_i386_table(); // -- the syscalls a sandbox must never allow -------------------------- // // spelled by NAME here, resolved through the kernel's headers. that is the @@ -573,3 +576,6 @@ int main() { } #endif + +// Must follow native SYS_* uses: unistd_32 intentionally replaces __NR_*. +#include "i386_table.hpp"