static uint32_t get_hostarch(void) { struct utsname uts; if (uname(&uts) < 0) die("uname() failed"); uint32_t arch = uts_machine_to_seccomp_arch(uts.machine); if (arch > 0) return arch; // Just return the seccomp userspace native arch if we can't detect the // kernel host arch. return seccomp_arch_native(); }
static void sc_add_seccomp_archs(scmp_filter_ctx * ctx) { uint32_t native_arch = seccomp_arch_native(); // seccomp userspace uint32_t host_arch = get_hostarch(); // kernel uint32_t compat_arch = 0; debug("host arch (kernel) is '%d'", host_arch); debug("native arch (userspace) is '%d'", native_arch); // For architectures that support a compat architecture, when the // kernel and userspace match, add the compat arch, otherwise add // the kernel arch to support the kernel's arch (eg, 64bit kernels with // 32bit userspace). if (host_arch == native_arch) { switch (host_arch) { #if defined (SCMP_ARCH_X86_64) case SCMP_ARCH_X86_64: compat_arch = SCMP_ARCH_X86; break; #endif #if defined(SCMP_ARCH_AARCH64) case SCMP_ARCH_AARCH64: compat_arch = SCMP_ARCH_ARM; break; #endif #if defined (SCMP_ARCH_PPC64) case SCMP_ARCH_PPC64: compat_arch = SCMP_ARCH_PPC; break; #endif default: break; } } else compat_arch = host_arch; if (compat_arch > 0 && seccomp_arch_exist(ctx, compat_arch) == -EEXIST) { debug("adding compat arch '%d'", compat_arch); if (seccomp_arch_add(ctx, compat_arch) < 0) die("seccomp_arch_add(..., compat_arch) failed"); } }
/** * main */ int main(int argc, char *argv[]) { int opt; int token = 0; uint32_t arch; /* parse the command line */ while ((opt = getopt(argc, argv, "ht")) > 0) { switch (opt) { case 't': token = 1; break; case 'h': default: /* usage information */ exit_usage(argv[0]); } } arch = seccomp_arch_native(); if (token == 0) { switch (arch) { case SCMP_ARCH_X86: printf("x86\n"); break; case SCMP_ARCH_X86_64: printf("x86_64\n"); break; case SCMP_ARCH_X32: printf("x32\n"); break; case SCMP_ARCH_ARM: printf("arm\n"); break; case SCMP_ARCH_AARCH64: printf("aarch64\n"); break; case SCMP_ARCH_MIPS: printf("mips\n"); break; case SCMP_ARCH_MIPSEL: printf("mipsel\n"); break; case SCMP_ARCH_MIPS64: printf("mips64\n"); break; case SCMP_ARCH_MIPSEL64: printf("mipsel64\n"); break; case SCMP_ARCH_MIPS64N32: printf("mips64n32\n"); break; case SCMP_ARCH_MIPSEL64N32: printf("mipsel64n32\n"); break; case SCMP_ARCH_PARISC: printf("parisc\n"); break; case SCMP_ARCH_PARISC64: printf("parisc64\n"); break; case SCMP_ARCH_PPC: printf("ppc\n"); break; case SCMP_ARCH_PPC64: printf("ppc64\n"); break; case SCMP_ARCH_PPC64LE: printf("ppc64le\n"); break; case SCMP_ARCH_S390: printf("s390\n"); break; case SCMP_ARCH_S390X: printf("s390x\n"); break; default: printf("unknown\n"); } } else printf("%d\n", arch); return 0; }