diff --git a/add-loongarch64-for-libseccomp.patch b/add-loongarch64-for-libseccomp.patch new file mode 100644 index 0000000000000000000000000000000000000000..0ed4d35ac70b043591285c5857430dfbad515a6c --- /dev/null +++ b/add-loongarch64-for-libseccomp.patch @@ -0,0 +1,1228 @@ +From d44e2578753eeae717a78eba6ddc25c874949eff Mon Sep 17 00:00:00 2001 +From: Your Name +Date: Tue, 15 Aug 2023 09:22:42 +0000 +Subject: [PATCH] add loongarch64 for libseccomp + +--- + README.md | 1 + + doc/man/man1/scmp_sys_resolver.1 | 2 +- + include/seccomp-syscalls.h | 1 + + include/seccomp.h.in | 12 +++ + src/Makefile.am | 1 + + src/arch-loongarch64.c | 41 ++++++++++ + src/arch-loongarch64.h | 28 +++++++ + src/arch-syscall-dump.c | 4 + + src/arch-syscall-validate | 55 +++++++++++++ + src/arch.c | 7 ++ + src/gen_pfc.c | 2 + + src/python/libseccomp.pxd | 1 + + src/python/seccomp.pyx | 4 + + src/syscalls.h | 2 + + src/system.c | 1 + + tests/06-sim-actions.tests | 1 - + tests/15-basic-resolver.c | 1 + + tests/16-sim-arch_basic.c | 6 ++ + tests/16-sim-arch_basic.py | 1 + + tests/23-sim-arch_all_le_basic.c | 3 + + tests/23-sim-arch_all_le_basic.py | 1 + + tests/36-sim-ipc_syscalls.c | 3 + + tests/38-basic-pfc_coverage.c | 6 +- + tests/38-basic-pfc_coverage.pfc | 124 ++++++++++++++++++++++------- + tests/53-sim-binary_tree.c | 4 +- + tests/53-sim-binary_tree.py | 1 - + tests/53-sim-binary_tree.tests | 79 +++++++++--------- + tests/55-basic-pfc_binary_tree.c | 4 +- + tests/55-basic-pfc_binary_tree.pfc | 118 +++++++++++++++++++++------ + tests/56-basic-iterate_syscalls.c | 1 + + tests/56-basic-iterate_syscalls.py | 1 + + tests/regression | 4 +- + tools/scmp_arch_detect.c | 3 + + tools/scmp_bpf_disasm.c | 2 + + tools/scmp_bpf_sim.c | 2 + + tools/util.c | 2 + + tools/util.h | 11 +++ + 37 files changed, 438 insertions(+), 102 deletions(-) + create mode 100644 src/arch-loongarch64.c + create mode 100644 src/arch-loongarch64.h + +diff --git a/README.md b/README.md +index e306512..7032802 100644 +--- a/README.md ++++ b/README.md +@@ -33,6 +33,7 @@ The libseccomp library currently supports the architectures listed below: + * 64-bit x86 x32 ABI (x32) + * 32-bit ARM EABI (arm) + * 64-bit ARM (aarch64) ++* 64-bit LoongArch (loongarch64) + * 32-bit MIPS (mips) + * 32-bit MIPS little endian (mipsel) + * 64-bit MIPS (mips64) +diff --git a/doc/man/man1/scmp_sys_resolver.1 b/doc/man/man1/scmp_sys_resolver.1 +index a223607..24518d0 100644 +--- a/doc/man/man1/scmp_sys_resolver.1 ++++ b/doc/man/man1/scmp_sys_resolver.1 +@@ -34,7 +34,7 @@ special manner by libseccomp depending on the operation. + .B \-a \fIARCH + The architecture to use for resolving the system call. Valid + .I ARCH +-values are "x86", "x86_64", "x32", "arm", "aarch64", "mips", "mipsel", "mips64", ++values are "x86", "x86_64", "x32", "arm", "aarch64", "loongarch64", "mips", "mipsel", "mips64", + "mipsel64", "mips64n32", "mipsel64n32", "parisc", "parisc64", "ppc", "ppc64", + "ppc64le", "s390" and "s390x". + .TP +diff --git a/include/seccomp-syscalls.h b/include/seccomp-syscalls.h +index ee46718..a1c6363 100644 +--- a/include/seccomp-syscalls.h ++++ b/include/seccomp-syscalls.h +@@ -276,6 +276,7 @@ + #define __PNR_renameat -10242 + #define __PNR_riscv_flush_icache -10243 + #define __PNR_memfd_secret -10244 ++#define __PNR_fstat -10245 + + /* + * libseccomp syscall definitions +diff --git a/include/seccomp.h.in b/include/seccomp.h.in +index ef4c6e4..1fa7bdc 100644 +--- a/include/seccomp.h.in ++++ b/include/seccomp.h.in +@@ -150,6 +150,18 @@ struct scmp_arg_cmp { + #endif /* AUDIT_ARCH_AARCH64 */ + #define SCMP_ARCH_AARCH64 AUDIT_ARCH_AARCH64 + ++/** ++ * The LoongArch architecture tokens ++ */ ++/* 64-bit LoongArch audit support is not upstream yet */ ++#ifndef AUDIT_ARCH_LOONGARCH64 ++#ifndef EM_LOONGARCH ++#define EM_LOONGARCH 258 ++#endif /* EM_LOONGARCH */ ++#define AUDIT_ARCH_LOONGARCH64 (EM_LOONGARCH|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) ++#endif /* AUDIT_ARCH_LOONGARCH64 */ ++#define SCMP_ARCH_LOONGARCH64 AUDIT_ARCH_LOONGARCH64 ++ + /** + * The MIPS architecture tokens + */ +diff --git a/src/Makefile.am b/src/Makefile.am +index 1e5c092..7d4c354 100644 +--- a/src/Makefile.am ++++ b/src/Makefile.am +@@ -32,6 +32,7 @@ SOURCES_ALL = \ + arch-x32.h arch-x32.c \ + arch-arm.h arch-arm.c \ + arch-aarch64.h arch-aarch64.c \ ++ arch-loongarch64.h arch-loongarch64.c \ + arch-mips.h arch-mips.c \ + arch-mips64.h arch-mips64.c \ + arch-mips64n32.h arch-mips64n32.c \ +diff --git a/src/arch-loongarch64.c b/src/arch-loongarch64.c +new file mode 100644 +index 0000000..8d28274 +--- /dev/null ++++ b/src/arch-loongarch64.c +@@ -0,0 +1,41 @@ ++/** ++ * Enhanced Seccomp 64-bit LoongArch Syscall Table ++ * ++ * Copyright (c) 2021 Xiaotian Wu ++ */ ++ ++/* ++ * This library is free software; you can redistribute it and/or modify it ++ * under the terms of version 2.1 of the GNU Lesser General Public License as ++ * published by the Free Software Foundation. ++ * ++ * This library is distributed in the hope that it will be useful, but WITHOUT ++ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ++ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License ++ * for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public License ++ * along with this library; if not, see . ++ */ ++ ++#include ++#include ++#include ++ ++#include "arch.h" ++#include "arch-loongarch64.h" ++#include "syscalls.h" ++ ++ARCH_DEF(loongarch64) ++ ++const struct arch_def arch_def_loongarch64 = { ++ .token = SCMP_ARCH_LOONGARCH64, ++ .token_bpf = AUDIT_ARCH_LOONGARCH64, ++ .size = ARCH_SIZE_64, ++ .endian = ARCH_ENDIAN_LITTLE, ++ .syscall_resolve_name_raw = loongarch64_syscall_resolve_name, ++ .syscall_resolve_num_raw = loongarch64_syscall_resolve_num, ++ .syscall_rewrite = NULL, ++ .rule_add = NULL, ++}; ++ +diff --git a/src/arch-loongarch64.h b/src/arch-loongarch64.h +new file mode 100644 +index 0000000..c3c06af +--- /dev/null ++++ b/src/arch-loongarch64.h +@@ -0,0 +1,28 @@ ++/** ++ * Enhanced Seccomp 64-bit LoongArch Syscall Table ++ * ++ * Copyright (c) 2021 Xiaotian Wu ++ */ ++ ++/* ++ * This library is free software; you can redistribute it and/or modify it ++ * under the terms of version 2.1 of the GNU Lesser General Public License as ++ * published by the Free Software Foundation. ++ * ++ * This library is distributed in the hope that it will be useful, but WITHOUT ++ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ++ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License ++ * for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public License ++ * along with this library; if not, see . ++ */ ++ ++#ifndef _ARCH_LOONGARCH64_H ++#define _ARCH_LOONGARCH64_H ++ ++#include "arch.h" ++ ++ARCH_DECL(loongarch64) ++ ++#endif +diff --git a/src/arch-syscall-dump.c b/src/arch-syscall-dump.c +index 2055d34..cc76e2c 100644 +--- a/src/arch-syscall-dump.c ++++ b/src/arch-syscall-dump.c +@@ -34,6 +34,7 @@ + #include "arch-x86_64.h" + #include "arch-x32.h" + #include "arch-arm.h" ++#include "arch-loongarch64.h" + #include "arch-mips.h" + #include "arch-mips64.h" + #include "arch-mips64n32.h" +@@ -106,6 +107,9 @@ int main(int argc, char *argv[]) + case SCMP_ARCH_AARCH64: + sys = aarch64_syscall_iterate(iter); + break; ++ case SCMP_ARCH_LOONGARCH64: ++ sys = loongarch64_syscall_iterate(iter); ++ break; + case SCMP_ARCH_MIPS: + case SCMP_ARCH_MIPSEL: + sys = mips_syscall_iterate(iter); +diff --git a/src/arch-syscall-validate b/src/arch-syscall-validate +index 3b69e9b..de1bc8c 100755 +--- a/src/arch-syscall-validate ++++ b/src/arch-syscall-validate +@@ -305,6 +305,53 @@ function dump_lib_aarch64() { + dump_lib_arch aarch64 | mangle_lib_syscall aarch64 + } + ++# ++# Dump the loongarch64 syscall table ++# ++# Arguments: ++# 1 path to the kernel source ++# ++# Dump the architecture's syscall table to stdout. ++# ++function dump_sys_loongarch64() { ++ local sed_filter="" ++ ++ sed_filter+='s/__NR3264_fadvise64/223/;' ++ sed_filter+='s/__NR3264_fcntl/25/;' ++ sed_filter+='s/__NR3264_fstatfs/44/;' ++ sed_filter+='s/__NR3264_fstatat/79/;' ++ sed_filter+='s/__NR3264_fstat/80/;' ++ sed_filter+='s/__NR3264_ftruncate/46/;' ++ sed_filter+='s/__NR3264_lseek/62/;' ++ sed_filter+='s/__NR3264_lstat/1039/;' ++ sed_filter+='s/__NR3264_mmap/222/;' ++ sed_filter+='s/__NR3264_sendfile/71/;' ++ sed_filter+='s/__NR3264_statfs/43/;' ++ sed_filter+='s/__NR3264_stat/1038/;' ++ sed_filter+='s/__NR3264_truncate/45/;' ++ ++ gcc -E -dM -I$1/include/uapi \ ++ -D__BITS_PER_LONG=64 \ ++ -D__ARCH_WANT_NEW_STAT \ ++ -D__ARCH_WANT_SYS_CLONE \ ++ -D__ARCH_WANT_SYS_CLONE3 \ ++ $1/arch/loongarch/include/uapi/asm/unistd.h | \ ++ grep "^#define __NR_" | \ ++ sed '/__NR_syscalls/d' | \ ++ sed '/__NR_arch_specific_syscall/d' | \ ++ sed 's/#define[ \t]\+__NR_\([^ \t]\+\)[ \t]\+\(.*\)/\1,\2/' | \ ++ sed $sed_filter | sort ++} ++ ++# ++# Dump the loongarch64 library syscall table ++# ++# Dump the library's syscall table to stdout. ++# ++function dump_lib_loongarch64() { ++ dump_lib_arch loongarch64 | mangle_lib_syscall loongarch64 ++} ++ + # + # Dump the mips system syscall table + # +@@ -593,6 +640,9 @@ function dump_sys() { + aarch64) + dump_sys_aarch64 "$2" + ;; ++ loongarch64) ++ dump_sys_loongarch64 "$2" ++ ;; + mips) + dump_sys_mips "$2" + ;; +@@ -657,6 +707,9 @@ function dump_lib() { + aarch64) + dump_lib_aarch64 + ;; ++ loongarch64) ++ dump_lib_loongarch64 ++ ;; + mips) + dump_lib_mips + ;; +@@ -717,6 +770,7 @@ function gen_csv() { + abi_list="" + abi_list+=" x86 x86_64 x32" + abi_list+=" arm aarch64" ++ abi_list+=" loongarch64" + abi_list+=" mips mips64 mips64n32" + abi_list+=" parisc parisc64" + abi_list+=" ppc ppc64" +@@ -806,6 +860,7 @@ if [[ $opt_arches == "" ]]; then + opt_arches=" \ + x86 x86_64 x32 \ + arm aarch64 \ ++ loongarch64 \ + mips mips64 mips64n32 \ + parisc parisc64 \ + ppc ppc64 \ +diff --git a/src/arch.c b/src/arch.c +index 8ef77b1..8c5363a 100644 +--- a/src/arch.c ++++ b/src/arch.c +@@ -35,6 +35,7 @@ + #include "arch-x32.h" + #include "arch-arm.h" + #include "arch-aarch64.h" ++#include "arch-loongarch64.h" + #include "arch-mips.h" + #include "arch-mips64.h" + #include "arch-mips64n32.h" +@@ -62,6 +63,8 @@ const struct arch_def *arch_def_native = &arch_def_x86_64; + const struct arch_def *arch_def_native = &arch_def_arm; + #elif __aarch64__ + const struct arch_def *arch_def_native = &arch_def_aarch64; ++#elif __loongarch64 ++const struct arch_def *arch_def_native = &arch_def_loongarch64; + #elif __mips__ && _MIPS_SIM == _MIPS_SIM_ABI32 + #if __MIPSEB__ + const struct arch_def *arch_def_native = &arch_def_mips; +@@ -134,6 +137,8 @@ const struct arch_def *arch_def_lookup(uint32_t token) + return &arch_def_arm; + case SCMP_ARCH_AARCH64: + return &arch_def_aarch64; ++ case SCMP_ARCH_LOONGARCH64: ++ return &arch_def_loongarch64; + case SCMP_ARCH_MIPS: + return &arch_def_mips; + case SCMP_ARCH_MIPSEL: +@@ -186,6 +191,8 @@ const struct arch_def *arch_def_lookup_name(const char *arch_name) + return &arch_def_arm; + else if (strcmp(arch_name, "aarch64") == 0) + return &arch_def_aarch64; ++ else if (strcmp(arch_name, "loongarch64") == 0) ++ return &arch_def_loongarch64; + else if (strcmp(arch_name, "mips") == 0) + return &arch_def_mips; + else if (strcmp(arch_name, "mipsel") == 0) +diff --git a/src/gen_pfc.c b/src/gen_pfc.c +index 2e38eb6..6f3f16e 100644 +--- a/src/gen_pfc.c ++++ b/src/gen_pfc.c +@@ -61,6 +61,8 @@ static const char *_pfc_arch(const struct arch_def *arch) + return "arm"; + case SCMP_ARCH_AARCH64: + return "aarch64"; ++ case SCMP_ARCH_LOONGARCH64: ++ return "loongarch64"; + case SCMP_ARCH_MIPS: + return "mips"; + case SCMP_ARCH_MIPSEL: +diff --git a/src/python/libseccomp.pxd b/src/python/libseccomp.pxd +index 0629bf1..280143f 100644 +--- a/src/python/libseccomp.pxd ++++ b/src/python/libseccomp.pxd +@@ -38,6 +38,7 @@ cdef extern from "seccomp.h": + SCMP_ARCH_X32 + SCMP_ARCH_ARM + SCMP_ARCH_AARCH64 ++ SCMP_ARCH_LOONGARCH64 + SCMP_ARCH_MIPS + SCMP_ARCH_MIPS64 + SCMP_ARCH_MIPS64N32 +diff --git a/src/python/seccomp.pyx b/src/python/seccomp.pyx +index 2eeabc1..9e08cfd 100644 +--- a/src/python/seccomp.pyx ++++ b/src/python/seccomp.pyx +@@ -204,6 +204,7 @@ cdef class Arch: + X32 - 64-bit x86 using the x32 ABI + ARM - ARM + AARCH64 - 64-bit ARM ++ LOONGARCH64 - 64-bit LoongArch + MIPS - MIPS O32 ABI + MIPS64 - MIPS 64-bit ABI + MIPS64N32 - MIPS N32 ABI +@@ -225,6 +226,7 @@ cdef class Arch: + X32 = libseccomp.SCMP_ARCH_X32 + ARM = libseccomp.SCMP_ARCH_ARM + AARCH64 = libseccomp.SCMP_ARCH_AARCH64 ++ LOONGARCH64 = libseccomp.SCMP_ARCH_LOONGARCH64 + MIPS = libseccomp.SCMP_ARCH_MIPS + MIPS64 = libseccomp.SCMP_ARCH_MIPS64 + MIPS64N32 = libseccomp.SCMP_ARCH_MIPS64N32 +@@ -262,6 +264,8 @@ cdef class Arch: + self._token = libseccomp.SCMP_ARCH_ARM + elif arch == libseccomp.SCMP_ARCH_AARCH64: + self._token = libseccomp.SCMP_ARCH_AARCH64 ++ elif arch == libseccomp.SCMP_ARCH_LOONGARCH64: ++ self._token = libseccomp.SCMP_ARCH_LOONGARCH64 + elif arch == libseccomp.SCMP_ARCH_MIPS: + self._token = libseccomp.SCMP_ARCH_MIPS + elif arch == libseccomp.SCMP_ARCH_MIPS64: +diff --git a/src/syscalls.h b/src/syscalls.h +index af468a1..42e2e14 100644 +--- a/src/syscalls.h ++++ b/src/syscalls.h +@@ -14,6 +14,7 @@ + #include "arch-aarch64.h" + #include "arch-arm.h" + #include "arch.h" ++#include "arch-loongarch64.h" + #include "arch-mips64.h" + #include "arch-mips64n32.h" + #include "arch-mips.h" +@@ -41,6 +42,7 @@ struct arch_syscall_table { + int x32; + int arm; + int aarch64; ++ int loongarch64; + int mips; + int mips64; + int mips64n32; +diff --git a/src/system.c b/src/system.c +index ae445bf..94e9be7 100644 +--- a/src/system.c ++++ b/src/system.c +@@ -126,6 +126,7 @@ int sys_chk_seccomp_syscall(void) + case SCMP_ARCH_X86_64: + case SCMP_ARCH_ARM: + case SCMP_ARCH_AARCH64: ++ case SCMP_ARCH_LOONGARCH64: + case SCMP_ARCH_PPC64: + case SCMP_ARCH_PPC64LE: + case SCMP_ARCH_S390: +diff --git a/tests/06-sim-actions.tests b/tests/06-sim-actions.tests +index 1ef38b3..993d340 100644 +--- a/tests/06-sim-actions.tests ++++ b/tests/06-sim-actions.tests +@@ -12,7 +12,6 @@ test type: bpf-sim + 06-sim-actions all write 1 0x856B008 N N N N ERRNO(1) + 06-sim-actions all close 4 N N N N N TRAP + 06-sim-actions all openat 0 0x856B008 4 N N N TRACE(1234) +-06-sim-actions all fstat N N N N N N KILL_PROCESS + 06-sim-actions all rt_sigreturn N N N N N N LOG + 06-sim-actions x86 0-2 N N N N N N KILL + 06-sim-actions x86 7-107 N N N N N N KILL +diff --git a/tests/15-basic-resolver.c b/tests/15-basic-resolver.c +index 6db69e8..c79894f 100644 +--- a/tests/15-basic-resolver.c ++++ b/tests/15-basic-resolver.c +@@ -32,6 +32,7 @@ unsigned int arch_list[] = { + SCMP_ARCH_X32, + SCMP_ARCH_ARM, + SCMP_ARCH_AARCH64, ++ SCMP_ARCH_LOONGARCH64, + SCMP_ARCH_MIPS, + SCMP_ARCH_MIPS64, + SCMP_ARCH_MIPS64N32, +diff --git a/tests/16-sim-arch_basic.c b/tests/16-sim-arch_basic.c +index 0b141e1..ee1a4a5 100644 +--- a/tests/16-sim-arch_basic.c ++++ b/tests/16-sim-arch_basic.c +@@ -78,6 +78,9 @@ int main(int argc, char *argv[]) + if (rc != 0) + goto out; + rc = seccomp_arch_add(ctx, SCMP_ARCH_AARCH64); ++ if (rc != 0) ++ goto out; ++ rc = seccomp_arch_add(ctx, SCMP_ARCH_LOONGARCH64); + if (rc != 0) + goto out; + rc = seccomp_arch_add(ctx, SCMP_ARCH_MIPSEL); +@@ -145,6 +148,9 @@ int main(int argc, char *argv[]) + if (rc != 0) + goto out; + rc = seccomp_arch_remove(ctx, SCMP_ARCH_AARCH64); ++ if (rc != 0) ++ goto out; ++ rc = seccomp_arch_remove(ctx, SCMP_ARCH_LOONGARCH64); + if (rc != 0) + goto out; + rc = seccomp_arch_remove(ctx, SCMP_ARCH_MIPSEL); +diff --git a/tests/16-sim-arch_basic.py b/tests/16-sim-arch_basic.py +index 846553f..ba38b91 100755 +--- a/tests/16-sim-arch_basic.py ++++ b/tests/16-sim-arch_basic.py +@@ -40,6 +40,7 @@ def test(args): + f.add_arch(Arch("x32")) + f.add_arch(Arch("arm")) + f.add_arch(Arch("aarch64")) ++ f.add_arch(Arch("loongarch64")) + f.add_arch(Arch("mipsel")) + f.add_arch(Arch("mipsel64")) + f.add_arch(Arch("mipsel64n32")) +diff --git a/tests/23-sim-arch_all_le_basic.c b/tests/23-sim-arch_all_le_basic.c +index 32739e5..d10d351 100644 +--- a/tests/23-sim-arch_all_le_basic.c ++++ b/tests/23-sim-arch_all_le_basic.c +@@ -57,6 +57,9 @@ int main(int argc, char *argv[]) + if (rc != 0) + goto out; + rc = seccomp_arch_add(ctx, seccomp_arch_resolve_name("aarch64")); ++ if (rc != 0) ++ goto out; ++ rc = seccomp_arch_add(ctx, seccomp_arch_resolve_name("loongarch64")); + if (rc != 0) + goto out; + rc = seccomp_arch_add(ctx, seccomp_arch_resolve_name("mipsel")); +diff --git a/tests/23-sim-arch_all_le_basic.py b/tests/23-sim-arch_all_le_basic.py +index 33eedb1..0cecbc9 100755 +--- a/tests/23-sim-arch_all_le_basic.py ++++ b/tests/23-sim-arch_all_le_basic.py +@@ -36,6 +36,7 @@ def test(args): + f.add_arch(Arch("x32")) + f.add_arch(Arch("arm")) + f.add_arch(Arch("aarch64")) ++ f.add_arch(Arch("loongarch64")) + f.add_arch(Arch("mipsel")) + f.add_arch(Arch("mipsel64")) + f.add_arch(Arch("mipsel64n32")) +diff --git a/tests/36-sim-ipc_syscalls.c b/tests/36-sim-ipc_syscalls.c +index c9b575e..d3b7093 100644 +--- a/tests/36-sim-ipc_syscalls.c ++++ b/tests/36-sim-ipc_syscalls.c +@@ -57,6 +57,9 @@ int main(int argc, char *argv[]) + if (rc != 0) + goto out; + rc = seccomp_arch_add(ctx, SCMP_ARCH_MIPSEL); ++ if (rc != 0) ++ goto out; ++ rc = seccomp_arch_add(ctx, SCMP_ARCH_LOONGARCH64); + if (rc != 0) + goto out; + +diff --git a/tests/38-basic-pfc_coverage.c b/tests/38-basic-pfc_coverage.c +index c6829ac..b06b05a 100644 +--- a/tests/38-basic-pfc_coverage.c ++++ b/tests/38-basic-pfc_coverage.c +@@ -64,6 +64,9 @@ int main(int argc, char *argv[]) + if (rc < 0) + goto out; + rc = seccomp_arch_add(ctx, SCMP_ARCH_AARCH64); ++ if (rc < 0) ++ goto out; ++ rc = seccomp_arch_add(ctx, SCMP_ARCH_LOONGARCH64); + if (rc < 0) + goto out; + rc = seccomp_arch_add(ctx, SCMP_ARCH_MIPSEL); +@@ -106,9 +109,6 @@ int main(int argc, char *argv[]) + if (rc < 0) + goto out; + rc = seccomp_rule_add(ctx, SCMP_ACT_TRACE(1), SCMP_SYS(exit), 0); +- if (rc < 0) +- goto out; +- rc = seccomp_rule_add(ctx, SCMP_ACT_KILL_PROCESS, SCMP_SYS(fstat), 0); + if (rc < 0) + goto out; + rc = seccomp_rule_add(ctx, SCMP_ACT_LOG, SCMP_SYS(exit_group), 0); +diff --git a/tests/38-basic-pfc_coverage.pfc b/tests/38-basic-pfc_coverage.pfc +index 3109280..c4bec83 100644 +--- a/tests/38-basic-pfc_coverage.pfc ++++ b/tests/38-basic-pfc_coverage.pfc +@@ -9,9 +9,6 @@ if ($arch == 3221225534) + # filter for syscall "exit" (60) [priority: 65535] + if ($syscall == 60) + action TRACE(1); +- # filter for syscall "fstat" (5) [priority: 65535] +- if ($syscall == 5) +- action KILL_PROCESS; + # filter for syscall "close" (3) [priority: 65535] + if ($syscall == 3) + action ERRNO(1); +@@ -103,9 +100,6 @@ if ($arch == 1073741827) + # filter for syscall "exit_group" (252) [priority: 65535] + if ($syscall == 252) + action LOG; +- # filter for syscall "fstat" (108) [priority: 65535] +- if ($syscall == 108) +- action KILL_PROCESS; + # filter for syscall "close" (6) [priority: 65535] + if ($syscall == 6) + action ERRNO(1); +@@ -141,9 +135,6 @@ if ($arch == 3221225534) + # filter for syscall "exit" (1073741884) [priority: 65535] + if ($syscall == 1073741884) + action TRACE(1); +- # filter for syscall "fstat" (1073741829) [priority: 65535] +- if ($syscall == 1073741829) +- action KILL_PROCESS; + # filter for syscall "close" (1073741827) [priority: 65535] + if ($syscall == 1073741827) + action ERRNO(1); +@@ -173,9 +164,6 @@ if ($arch == 1073741864) + # filter for syscall "exit_group" (248) [priority: 65535] + if ($syscall == 248) + action LOG; +- # filter for syscall "fstat" (108) [priority: 65535] +- if ($syscall == 108) +- action KILL_PROCESS; + # filter for syscall "close" (6) [priority: 65535] + if ($syscall == 6) + action ERRNO(1); +@@ -214,9 +202,100 @@ if ($arch == 3221225655) + # filter for syscall "exit" (93) [priority: 65535] + if ($syscall == 93) + action TRACE(1); +- # filter for syscall "fstat" (80) [priority: 65535] +- if ($syscall == 80) +- action KILL_PROCESS; ++ # filter for syscall "close" (57) [priority: 65535] ++ if ($syscall == 57) ++ action ERRNO(1); ++ # filter for syscall "write" (64) [priority: 65527] ++ if ($syscall == 64) ++ if ($a0.hi32 == 0) ++ if ($a0.lo32 == 0) ++ else ++ if ($a1.hi32 > 0) ++ else ++ if ($a1.hi32 == 0) ++ if ($a1.lo32 > 1) ++ else ++ if ($a2.hi32 > 0) ++ else ++ if ($a2.hi32 == 0) ++ if ($a2.lo32 >= 2) ++ else ++ action TRAP; ++ else ++ action TRAP; ++ else ++ if ($a2.hi32 > 0) ++ else ++ if ($a2.hi32 == 0) ++ if ($a2.lo32 >= 2) ++ else ++ action TRAP; ++ else ++ action TRAP; ++ else ++ if ($a1.hi32 > 0) ++ else ++ if ($a1.hi32 == 0) ++ if ($a1.lo32 > 1) ++ else ++ if ($a2.hi32 > 0) ++ else ++ if ($a2.hi32 == 0) ++ if ($a2.lo32 >= 2) ++ else ++ action TRAP; ++ else ++ action TRAP; ++ else ++ if ($a2.hi32 > 0) ++ else ++ if ($a2.hi32 == 0) ++ if ($a2.lo32 >= 2) ++ else ++ action TRAP; ++ else ++ action TRAP; ++ # filter for syscall "read" (63) [priority: 65525] ++ if ($syscall == 63) ++ if ($a0.hi32 == 0) ++ if ($a0.lo32 == 0) ++ if ($a1.hi32 > 0) ++ if ($a2.hi32 > 0) ++ if ($a3.hi32 & 0x00000000 == 0) ++ if ($a3.lo32 & 0x0000000f == 3) ++ action KILL; ++ else ++ if ($a2.hi32 == 0) ++ if ($a2.lo32 > 2) ++ if ($a3.hi32 & 0x00000000 == 0) ++ if ($a3.lo32 & 0x0000000f == 3) ++ action KILL; ++ else ++ if ($a1.hi32 == 0) ++ if ($a1.lo32 >= 1) ++ if ($a2.hi32 > 0) ++ if ($a3.hi32 & 0x00000000 == 0) ++ if ($a3.lo32 & 0x0000000f == 3) ++ action KILL; ++ else ++ if ($a2.hi32 == 0) ++ if ($a2.lo32 > 2) ++ if ($a3.hi32 & 0x00000000 == 0) ++ if ($a3.lo32 & 0x0000000f == 3) ++ action KILL; ++ # default action ++ action ALLOW; ++# filter for arch loongarch64 (3221225730) ++if ($arch == 3221225730) ++ # filter for syscall "open" (4294957130) [priority: 65535] ++ if ($syscall == 4294957130) ++ action KILL; ++ # filter for syscall "exit_group" (94) [priority: 65535] ++ if ($syscall == 94) ++ action LOG; ++ # filter for syscall "exit" (93) [priority: 65535] ++ if ($syscall == 93) ++ action TRACE(1); + # filter for syscall "close" (57) [priority: 65535] + if ($syscall == 57) + action ERRNO(1); +@@ -305,9 +384,6 @@ if ($arch == 1073741832) + # filter for syscall "exit_group" (4246) [priority: 65535] + if ($syscall == 4246) + action LOG; +- # filter for syscall "fstat" (4108) [priority: 65535] +- if ($syscall == 4108) +- action KILL_PROCESS; + # filter for syscall "close" (4006) [priority: 65535] + if ($syscall == 4006) + action ERRNO(1); +@@ -343,9 +419,6 @@ if ($arch == 3221225480) + # filter for syscall "exit" (5058) [priority: 65535] + if ($syscall == 5058) + action TRACE(1); +- # filter for syscall "fstat" (5005) [priority: 65535] +- if ($syscall == 5005) +- action KILL_PROCESS; + # filter for syscall "close" (5003) [priority: 65535] + if ($syscall == 5003) + action ERRNO(1); +@@ -440,9 +513,6 @@ if ($arch == 3758096392) + # filter for syscall "exit" (6058) [priority: 65535] + if ($syscall == 6058) + action TRACE(1); +- # filter for syscall "fstat" (6005) [priority: 65535] +- if ($syscall == 6005) +- action KILL_PROCESS; + # filter for syscall "close" (6003) [priority: 65535] + if ($syscall == 6003) + action ERRNO(1); +@@ -472,9 +542,6 @@ if ($arch == 3221225493) + # filter for syscall "exit_group" (234) [priority: 65535] + if ($syscall == 234) + action LOG; +- # filter for syscall "fstat" (108) [priority: 65535] +- if ($syscall == 108) +- action KILL_PROCESS; + # filter for syscall "close" (6) [priority: 65535] + if ($syscall == 6) + action ERRNO(1); +@@ -575,9 +642,6 @@ if ($arch == 3221225715) + # filter for syscall "exit" (93) [priority: 65535] + if ($syscall == 93) + action TRACE(1); +- # filter for syscall "fstat" (80) [priority: 65535] +- if ($syscall == 80) +- action KILL_PROCESS; + # filter for syscall "close" (57) [priority: 65535] + if ($syscall == 57) + action ERRNO(1); +diff --git a/tests/53-sim-binary_tree.c b/tests/53-sim-binary_tree.c +index 4aa5f13..39acbe7 100644 +--- a/tests/53-sim-binary_tree.c ++++ b/tests/53-sim-binary_tree.c +@@ -48,7 +48,6 @@ struct syscall_errno table[] = { + { SCMP_SYS(open), 2, 0, { 0, 0 } }, + { SCMP_SYS(close), 3, 2, { 100, 101 } }, + { SCMP_SYS(stat), 4, 0, { 0, 0 } }, +- { SCMP_SYS(fstat), 5, 0, { 0, 0 } }, + { SCMP_SYS(lstat), 6, 0, { 0, 0 } }, + { SCMP_SYS(poll), 7, 1, { 102, 0 } }, + { SCMP_SYS(lseek), 8, 2, { 103, 104 } }, +@@ -103,6 +102,9 @@ int main(int argc, char *argv[]) + goto out; + + rc = seccomp_arch_add(ctx, SCMP_ARCH_AARCH64); ++ if (rc != 0) ++ goto out; ++ rc = seccomp_arch_add(ctx, SCMP_ARCH_LOONGARCH64); + if (rc != 0) + goto out; + rc = seccomp_arch_add(ctx, SCMP_ARCH_PPC64LE); +diff --git a/tests/53-sim-binary_tree.py b/tests/53-sim-binary_tree.py +index 8ee58cd..9e45154 100755 +--- a/tests/53-sim-binary_tree.py ++++ b/tests/53-sim-binary_tree.py +@@ -34,7 +34,6 @@ table = [ + {"syscall": "open", "error": 2, "arg_cnt": 0 }, + {"syscall": "close", "error": 3, "arg_cnt": 2, "arg1": 100, "arg2": 101 }, + {"syscall": "stat", "error": 4, "arg_cnt": 0 }, +- {"syscall": "fstat", "error": 5, "arg_cnt": 0 }, + {"syscall": "lstat", "error": 6, "arg_cnt": 0 }, + {"syscall": "poll", "error": 7, "arg_cnt": 1, "arg1": 102 }, + {"syscall": "lseek", "error": 8, "arg_cnt": 2, "arg1": 103, "arg2": 104 }, +diff --git a/tests/53-sim-binary_tree.tests b/tests/53-sim-binary_tree.tests +index 2ebaafd..2cdb076 100644 +--- a/tests/53-sim-binary_tree.tests ++++ b/tests/53-sim-binary_tree.tests +@@ -8,56 +8,55 @@ + test type: bpf-sim + + # Testname Arch Syscall Arg0 Arg1 Arg2 Arg3 Arg4 Arg5 Result +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 read N N N N N N ERRNO(0) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 write N N N N N N ERRNO(1) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 read N N N N N N ERRNO(0) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 write N N N N N N ERRNO(1) + 53-sim-binary_tree +x86_64,+ppc64le open N N N N N N ERRNO(2) +-53-sim-binary_tree +aarch64 open N N N N N N ALLOW +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 close N N N N N N ALLOW +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 close 100 1234 N N N N ALLOW +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 close 100 101 N N N N ERRNO(3) ++53-sim-binary_tree +aarch64,+loongarch64 open N N N N N N ALLOW ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 close N N N N N N ALLOW ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 close 100 1234 N N N N ALLOW ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 close 100 101 N N N N ERRNO(3) + 53-sim-binary_tree +x86_64,+ppc64le stat N N N N N N ERRNO(4) +-53-sim-binary_tree +aarch64 stat N N N N N N ALLOW +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 fstat N N N N N N ERRNO(5) ++53-sim-binary_tree +aarch64,+loongarch64 stat N N N N N N ALLOW + 53-sim-binary_tree +x86_64,+ppc64le lstat N N N N N N ERRNO(6) +-53-sim-binary_tree +aarch64 lstat N N N N N N ALLOW ++53-sim-binary_tree +aarch64,+loongarch64 lstat N N N N N N ALLOW + 53-sim-binary_tree +x86_64,+ppc64le poll 102 N N N N N ERRNO(7) +-53-sim-binary_tree +aarch64 poll 102 N N N N N ALLOW +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 lseek 103 104 N N N N ERRNO(8) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 mmap N N N N N N ERRNO(9) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 mprotect N N N N N N ERRNO(10) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 munmap N N N N N N ERRNO(11) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 brk N N N N N N ERRNO(12) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 rt_sigaction N N N N N N ERRNO(13) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 rt_sigprocmask N N N N N N ERRNO(14) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 rt_sigreturn N N N N N N ERRNO(15) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 ioctl N N N N N N ERRNO(16) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 pread64 105 N N N N N ERRNO(17) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 pwrite64 N N N N N N ERRNO(18) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 readv N N N N N N ERRNO(19) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 writev N N N N N N ERRNO(20) ++53-sim-binary_tree +aarch64,+loongarch64 poll 102 N N N N N ALLOW ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 lseek 103 104 N N N N ERRNO(8) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 mmap N N N N N N ERRNO(9) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 mprotect N N N N N N ERRNO(10) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 munmap N N N N N N ERRNO(11) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 brk N N N N N N ERRNO(12) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 rt_sigaction N N N N N N ERRNO(13) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 rt_sigprocmask N N N N N N ERRNO(14) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 rt_sigreturn N N N N N N ERRNO(15) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 ioctl N N N N N N ERRNO(16) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 pread64 105 N N N N N ERRNO(17) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 pwrite64 N N N N N N ERRNO(18) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 readv N N N N N N ERRNO(19) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 writev N N N N N N ERRNO(20) + 53-sim-binary_tree +x86_64,+ppc64le access N N N N N N ERRNO(21) +-53-sim-binary_tree +aarch64 access N N N N N N ALLOW ++53-sim-binary_tree +aarch64,+loongarch64 access N N N N N N ALLOW + 53-sim-binary_tree +x86_64,+ppc64le pipe N N N N N N ERRNO(22) +-53-sim-binary_tree +aarch64 pipe N N N N N N ALLOW +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 select N N N N N N ALLOW ++53-sim-binary_tree +aarch64,+loongarch64 pipe N N N N N N ALLOW ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 select N N N N N N ALLOW + 53-sim-binary_tree +x86_64,+ppc64le select 106 107 N N N N ERRNO(23) +-53-sim-binary_tree +aarch64 select 106 107 N N N N ALLOW +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 sched_yield N N N N N N ERRNO(24) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 mremap N N N N N N ALLOW +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 mremap 108 109 N N N N ERRNO(25) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 msync N N N N N N ERRNO(26) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 mincore N N N N N N ERRNO(27) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 madvise N N N N N N ERRNO(28) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 dup 112 N N N N N ERRNO(32) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 dup 5678 N N N N N ALLOW ++53-sim-binary_tree +aarch64,+loongarch64 select 106 107 N N N N ALLOW ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 sched_yield N N N N N N ERRNO(24) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 mremap N N N N N N ALLOW ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 mremap 108 109 N N N N ERRNO(25) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 msync N N N N N N ERRNO(26) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 mincore N N N N N N ERRNO(27) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 madvise N N N N N N ERRNO(28) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 dup 112 N N N N N ERRNO(32) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 dup 5678 N N N N N ALLOW + 53-sim-binary_tree +x86_64,+ppc64le dup2 N N N N N N ERRNO(33) +-53-sim-binary_tree +aarch64 dup2 N N N N N N ALLOW ++53-sim-binary_tree +aarch64,+loongarch64 dup2 N N N N N N ALLOW + 53-sim-binary_tree +x86_64,+ppc64le pause N N N N N N ERRNO(34) +-53-sim-binary_tree +aarch64 pause N N N N N N ALLOW +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 nanosleep N N N N N N ERRNO(35) +-53-sim-binary_tree +x86_64,+ppc64le,+aarch64 getitimer N N N N N N ERRNO(36) ++53-sim-binary_tree +aarch64,+loongarch64 pause N N N N N N ALLOW ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 nanosleep N N N N N N ERRNO(35) ++53-sim-binary_tree +x86_64,+ppc64le,+aarch64,+loongarch64 getitimer N N N N N N ERRNO(36) + 53-sim-binary_tree +x86_64,+ppc64le alarm N N N N N N ERRNO(37) +-53-sim-binary_tree +aarch64 alarm N N N N N N ALLOW ++53-sim-binary_tree +aarch64,+loongarch64 alarm N N N N N N ALLOW + + test type: bpf-valgrind + +diff --git a/tests/55-basic-pfc_binary_tree.c b/tests/55-basic-pfc_binary_tree.c +index e364fd6..d542e5b 100644 +--- a/tests/55-basic-pfc_binary_tree.c ++++ b/tests/55-basic-pfc_binary_tree.c +@@ -48,7 +48,6 @@ struct syscall_errno table[] = { + { SCMP_SYS(open), 2, 0, { 0, 0 } }, + { SCMP_SYS(close), 3, 0, { 0, 0 } }, + { SCMP_SYS(stat), 4, 0, { 0, 0 } }, +- { SCMP_SYS(fstat), 5, 1, { 103, 0 } }, + { SCMP_SYS(lstat), 6, 0, { 0, 0 } }, + { SCMP_SYS(poll), 7, 0, { 0, 0 } }, + { SCMP_SYS(lseek), 8, 1, { 104, 0 } }, +@@ -87,6 +86,9 @@ int main(int argc, char *argv[]) + if (rc < 0) + goto out; + rc = seccomp_arch_add(ctx, SCMP_ARCH_AARCH64); ++ if (rc < 0) ++ goto out; ++ rc = seccomp_arch_add(ctx, SCMP_ARCH_LOONGARCH64); + if (rc < 0) + goto out; + rc = seccomp_attr_set(ctx, SCMP_FLTATR_CTL_OPTIMIZE, 2); +diff --git a/tests/55-basic-pfc_binary_tree.pfc b/tests/55-basic-pfc_binary_tree.pfc +index ba3244c..44f8498 100644 +--- a/tests/55-basic-pfc_binary_tree.pfc ++++ b/tests/55-basic-pfc_binary_tree.pfc +@@ -3,7 +3,7 @@ + # + # filter for arch x86_64 (3221225534) + if ($arch == 3221225534) +- if ($syscall > 2) ++ if ($syscall > 1) + if ($syscall > 10) + if ($syscall > 14) + # filter for syscall "pwrite64" (18) [priority: 65531] +@@ -59,21 +59,16 @@ if ($arch == 3221225534) + # filter for syscall "lstat" (6) [priority: 65535] + if ($syscall == 6) + action ERRNO(6); +- # filter for syscall "fstat" (5) [priority: 65533] +- if ($syscall == 5) +- if ($a0.hi32 == 0) +- if ($a0.lo32 == 103) +- action ERRNO(5); + # filter for syscall "stat" (4) [priority: 65535] + if ($syscall == 4) + action ERRNO(4); + # filter for syscall "close" (3) [priority: 65535] + if ($syscall == 3) + action ERRNO(3); +- else # ($syscall <= 2) +- # filter for syscall "open" (2) [priority: 65535] +- if ($syscall == 2) +- action ERRNO(2); ++ # filter for syscall "open" (2) [priority: 65535] ++ if ($syscall == 2) ++ action ERRNO(2); ++ else # ($syscall <= 1) + # filter for syscall "write" (1) [priority: 65533] + if ($syscall == 1) + if ($a0.hi32 == 0) +@@ -90,7 +85,7 @@ if ($arch == 3221225534) + action ALLOW; + # filter for arch aarch64 (3221225655) + if ($arch == 3221225655) +- if ($syscall > 62) ++ if ($syscall > 57) + if ($syscall > 139) + if ($syscall > 226) + # filter for syscall "lstat" (4294957133) [priority: 65535] +@@ -121,7 +116,7 @@ if ($arch == 3221225655) + if ($syscall == 214) + action ERRNO(12); + else # ($syscall <= 139) +- if ($syscall > 68) ++ if ($syscall > 67) + # filter for syscall "rt_sigreturn" (139) [priority: 65535] + if ($syscall == 139) + action ERRNO(15); +@@ -131,12 +126,88 @@ if ($arch == 3221225655) + # filter for syscall "rt_sigaction" (134) [priority: 65535] + if ($syscall == 134) + action ERRNO(13); +- # filter for syscall "fstat" (80) [priority: 65533] +- if ($syscall == 80) ++ # filter for syscall "pwrite64" (68) [priority: 65531] ++ if ($syscall == 68) ++ if ($a0.hi32 == 0) ++ if ($a0.lo32 == 107) ++ if ($a1.hi32 == 0) ++ if ($a1.lo32 == 108) ++ action ERRNO(18); ++ else # ($syscall <= 67) ++ # filter for syscall "pread64" (67) [priority: 65533] ++ if ($syscall == 67) ++ if ($a0.hi32 == 0) ++ if ($a0.lo32 == 106) ++ action ERRNO(17); ++ # filter for syscall "write" (64) [priority: 65533] ++ if ($syscall == 64) ++ if ($a0.hi32 == 0) ++ if ($a0.lo32 == 102) ++ action ERRNO(1); ++ # filter for syscall "read" (63) [priority: 65531] ++ if ($syscall == 63) ++ if ($a0.hi32 == 0) ++ if ($a0.lo32 == 100) ++ if ($a1.hi32 == 0) ++ if ($a1.lo32 == 101) ++ action ERRNO(0); ++ # filter for syscall "lseek" (62) [priority: 65533] ++ if ($syscall == 62) + if ($a0.hi32 == 0) +- if ($a0.lo32 == 103) +- action ERRNO(5); +- else # ($syscall <= 68) ++ if ($a0.lo32 == 104) ++ action ERRNO(8); ++ else # ($syscall <= 57) ++ # filter for syscall "close" (57) [priority: 65535] ++ if ($syscall == 57) ++ action ERRNO(3); ++ # filter for syscall "ioctl" (29) [priority: 65535] ++ if ($syscall == 29) ++ action ERRNO(16); ++ # default action ++ action ALLOW; ++# filter for arch loongarch64 (3221225730) ++if ($arch == 3221225730) ++ if ($syscall > 57) ++ if ($syscall > 139) ++ if ($syscall > 226) ++ # filter for syscall "lstat" (4294957133) [priority: 65535] ++ if ($syscall == 4294957133) ++ action ERRNO(6); ++ # filter for syscall "open" (4294957130) [priority: 65535] ++ if ($syscall == 4294957130) ++ action ERRNO(2); ++ # filter for syscall "poll" (4294957127) [priority: 65535] ++ if ($syscall == 4294957127) ++ action ERRNO(7); ++ # filter for syscall "stat" (4294957122) [priority: 65535] ++ if ($syscall == 4294957122) ++ action ERRNO(4); ++ else # ($syscall <= 226) ++ # filter for syscall "mprotect" (226) [priority: 65533] ++ if ($syscall == 226) ++ if ($a0.hi32 == 0) ++ if ($a0.lo32 == 105) ++ action ERRNO(10); ++ # filter for syscall "mmap" (222) [priority: 65535] ++ if ($syscall == 222) ++ action ERRNO(9); ++ # filter for syscall "munmap" (215) [priority: 65535] ++ if ($syscall == 215) ++ action ERRNO(11); ++ # filter for syscall "brk" (214) [priority: 65535] ++ if ($syscall == 214) ++ action ERRNO(12); ++ else # ($syscall <= 139) ++ if ($syscall > 67) ++ # filter for syscall "rt_sigreturn" (139) [priority: 65535] ++ if ($syscall == 139) ++ action ERRNO(15); ++ # filter for syscall "rt_sigprocmask" (135) [priority: 65535] ++ if ($syscall == 135) ++ action ERRNO(14); ++ # filter for syscall "rt_sigaction" (134) [priority: 65535] ++ if ($syscall == 134) ++ action ERRNO(13); + # filter for syscall "pwrite64" (68) [priority: 65531] + if ($syscall == 68) + if ($a0.hi32 == 0) +@@ -144,6 +215,7 @@ if ($arch == 3221225655) + if ($a1.hi32 == 0) + if ($a1.lo32 == 108) + action ERRNO(18); ++ else # ($syscall <= 67) + # filter for syscall "pread64" (67) [priority: 65533] + if ($syscall == 67) + if ($a0.hi32 == 0) +@@ -161,12 +233,12 @@ if ($arch == 3221225655) + if ($a1.hi32 == 0) + if ($a1.lo32 == 101) + action ERRNO(0); +- else # ($syscall <= 62) +- # filter for syscall "lseek" (62) [priority: 65533] +- if ($syscall == 62) +- if ($a0.hi32 == 0) +- if ($a0.lo32 == 104) +- action ERRNO(8); ++ # filter for syscall "lseek" (62) [priority: 65533] ++ if ($syscall == 62) ++ if ($a0.hi32 == 0) ++ if ($a0.lo32 == 104) ++ action ERRNO(8); ++ else # ($syscall <= 57) + # filter for syscall "close" (57) [priority: 65535] + if ($syscall == 57) + action ERRNO(3); +diff --git a/tests/56-basic-iterate_syscalls.c b/tests/56-basic-iterate_syscalls.c +index 5e7ab67..b514afa 100644 +--- a/tests/56-basic-iterate_syscalls.c ++++ b/tests/56-basic-iterate_syscalls.c +@@ -33,6 +33,7 @@ unsigned int arch_list[] = { + SCMP_ARCH_X32, + SCMP_ARCH_ARM, + SCMP_ARCH_AARCH64, ++ SCMP_ARCH_LOONGARCH64, + SCMP_ARCH_MIPS, + SCMP_ARCH_MIPS64, + SCMP_ARCH_MIPS64N32, +diff --git a/tests/56-basic-iterate_syscalls.py b/tests/56-basic-iterate_syscalls.py +index 77a5b89..d69dd0c 100755 +--- a/tests/56-basic-iterate_syscalls.py ++++ b/tests/56-basic-iterate_syscalls.py +@@ -33,6 +33,7 @@ arch_list = ["x86", + "x32", + "arm", + "aarch64", ++ "loongarch64", + "mipsel", + "mipsel64", + "mipsel64n32", +diff --git a/tests/regression b/tests/regression +index f938b1b..19f9323 100755 +--- a/tests/regression ++++ b/tests/regression +@@ -24,6 +24,7 @@ + GLBL_ARCH_LE_SUPPORT=" \ + x86 x86_64 x32 \ + arm aarch64 \ ++ loongarch64 \ + mipsel mipsel64 mipsel64n32 \ + ppc64le \ + riscv64" +@@ -44,6 +45,7 @@ GLBL_ARCH_32B_SUPPORT=" \ + GLBL_ARCH_64B_SUPPORT=" \ + x86_64 \ + aarch64 \ ++ loongarch64 \ + mips64 \ + parisc64 \ + ppc64 \ +@@ -796,7 +798,7 @@ function run_test_live() { + + # setup the arch specific return values + case "$arch" in +- x86|x86_64|x32|arm|aarch64|parisc|parisc64|ppc|ppc64|ppc64le|ppc|s390|s390x|riscv64) ++ x86|x86_64|x32|arm|aarch64|loongarch64|parisc|parisc64|ppc|ppc64|ppc64le|ppc|s390|s390x|riscv64) + rc_kill_process=159 + rc_kill=159 + rc_allow=160 +diff --git a/tools/scmp_arch_detect.c b/tools/scmp_arch_detect.c +index b844a68..320b1af 100644 +--- a/tools/scmp_arch_detect.c ++++ b/tools/scmp_arch_detect.c +@@ -81,6 +81,9 @@ int main(int argc, char *argv[]) + case SCMP_ARCH_AARCH64: + printf("aarch64\n"); + break; ++ case SCMP_ARCH_LOONGARCH64: ++ printf("loongarch64\n"); ++ break; + case SCMP_ARCH_MIPS: + printf("mips\n"); + break; +diff --git a/tools/scmp_bpf_disasm.c b/tools/scmp_bpf_disasm.c +index b682de7..4572659 100644 +--- a/tools/scmp_bpf_disasm.c ++++ b/tools/scmp_bpf_disasm.c +@@ -484,6 +484,8 @@ int main(int argc, char *argv[]) + arch = AUDIT_ARCH_ARM; + else if (strcmp(optarg, "aarch64") == 0) + arch = AUDIT_ARCH_AARCH64; ++ else if (strcmp(optarg, "loongarch64") == 0) ++ arch = AUDIT_ARCH_LOONGARCH64; + else if (strcmp(optarg, "mips") == 0) + arch = AUDIT_ARCH_MIPS; + else if (strcmp(optarg, "mipsel") == 0) +diff --git a/tools/scmp_bpf_sim.c b/tools/scmp_bpf_sim.c +index a381314..a2b31f1 100644 +--- a/tools/scmp_bpf_sim.c ++++ b/tools/scmp_bpf_sim.c +@@ -259,6 +259,8 @@ int main(int argc, char *argv[]) + arch = AUDIT_ARCH_ARM; + else if (strcmp(optarg, "aarch64") == 0) + arch = AUDIT_ARCH_AARCH64; ++ else if (strcmp(optarg, "loongarch64") == 0) ++ arch = AUDIT_ARCH_LOONGARCH64; + else if (strcmp(optarg, "mips") == 0) + arch = AUDIT_ARCH_MIPS; + else if (strcmp(optarg, "mipsel") == 0) +diff --git a/tools/util.c b/tools/util.c +index 5687b30..433bbfa 100644 +--- a/tools/util.c ++++ b/tools/util.c +@@ -44,6 +44,8 @@ + #define ARCH_NATIVE AUDIT_ARCH_ARM + #elif __aarch64__ + #define ARCH_NATIVE AUDIT_ARCH_AARCH64 ++#elif __loongarch64 ++#define ARCH_NATIVE AUDIT_ARCH_LOONGARCH64 + #elif __mips__ && _MIPS_SIM == _MIPS_SIM_ABI32 + #if __MIPSEB__ + #define ARCH_NATIVE AUDIT_ARCH_MIPS +diff --git a/tools/util.h b/tools/util.h +index 6c2ca33..551eeb4 100644 +--- a/tools/util.h ++++ b/tools/util.h +@@ -37,6 +37,17 @@ + #define AUDIT_ARCH_AARCH64 (EM_AARCH64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) + #endif /* AUDIT_ARCH_AARCH64 */ + ++/** ++ * The 64-bit LoongArch architecture tokens ++ */ ++/* 64-bit LoongArch audit support is not upstream yet */ ++#ifndef AUDIT_ARCH_LOONGARCH64 ++#ifndef EM_LOONGARCH ++#define EM_LOONGARCH 258 ++#endif /* EM_LOONGARCH */ ++#define AUDIT_ARCH_LOONGARCH64 (EM_LOONGARCH|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) ++#endif /* AUDIT_ARCH_LOONGARCH64 */ ++ + /** + * The MIPS architecture tokens + */ +-- +2.40.1 + diff --git a/libseccomp.spec b/libseccomp.spec index 830696190e50e8e3e2b8bfb3528edcb950e3f5f7..9b2d564530059ab0a490917f1ea73e8710274b43 100644 --- a/libseccomp.spec +++ b/libseccomp.spec @@ -1,4 +1,4 @@ -%define anolis_release 1 +%define anolis_release 2 Name: libseccomp Version: 2.5.4 @@ -8,6 +8,8 @@ License: LGPLv2 URL: https://github.com/seccomp/libseccomp Source0: https://github.com/seccomp/releases/download/v%{version}/%{name}-%{version}.tar.gz +Patch001: add-loongarch64-for-libseccomp.patch + BuildRequires: gcc BuildRequires: gperf BuildRequires: make @@ -53,6 +55,7 @@ Kernel. %autosetup -p1 %build +autoreconf %configure %make_build @@ -82,6 +85,9 @@ Kernel. %{_libdir}/libseccomp.a %changelog +* Wed Aug 16 2023 Wenlong Zhang - 2.5.4-2 +- add loongarch64 for libseccomp + * Mon Dec 5 2022 Funda Wang - 2.5.4-1 - New version 2.5.4