1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-10 05:18:17 +03:00

Merge pull request #28734 from loongarch64/dev-wu-main

seccomp: add LoongArch 64bit support
This commit is contained in:
Luca Boccassi 2023-08-09 20:20:03 +01:00 committed by GitHub
commit 4051fc1d54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 55 additions and 30 deletions

View File

@ -70,7 +70,7 @@ Architecture uname_architecture(void) {
{ "parisc64", ARCHITECTURE_PARISC64 },
{ "parisc", ARCHITECTURE_PARISC },
#elif defined(__loongarch64)
#elif defined(__loongarch_lp64)
{ "loongarch64", ARCHITECTURE_LOONGARCH64 },
#elif defined(__m68k__)

View File

@ -14,7 +14,7 @@
# elif defined(__arm__)
# elif defined(__i386__)
# elif defined(__ia64__)
# elif defined(__loongarch64)
# elif defined(__loongarch_lp64)
# elif defined(__m68k__)
# elif defined(_MIPS_SIM)
# if _MIPS_SIM == _MIPS_SIM_ABI32
@ -55,7 +55,7 @@
# define systemd_NR_bpf 357
# elif defined(__ia64__)
# define systemd_NR_bpf 1341
# elif defined(__loongarch64)
# elif defined(__loongarch_lp64)
# define systemd_NR_bpf 280
# elif defined(__m68k__)
# define systemd_NR_bpf 354
@ -123,7 +123,7 @@ assert_cc(__NR_bpf == systemd_NR_bpf);
# define systemd_NR_close_range 436
# elif defined(__ia64__)
# define systemd_NR_close_range 1460
# elif defined(__loongarch64)
# elif defined(__loongarch_lp64)
# define systemd_NR_close_range 436
# elif defined(__m68k__)
# define systemd_NR_close_range 436
@ -191,7 +191,7 @@ assert_cc(__NR_close_range == systemd_NR_close_range);
# define systemd_NR_copy_file_range 377
# elif defined(__ia64__)
# define systemd_NR_copy_file_range 1347
# elif defined(__loongarch64)
# elif defined(__loongarch_lp64)
# define systemd_NR_copy_file_range 285
# elif defined(__m68k__)
# define systemd_NR_copy_file_range 376
@ -259,7 +259,7 @@ assert_cc(__NR_copy_file_range == systemd_NR_copy_file_range);
# define systemd_NR_getrandom 355
# elif defined(__ia64__)
# define systemd_NR_getrandom 1339
# elif defined(__loongarch64)
# elif defined(__loongarch_lp64)
# define systemd_NR_getrandom 278
# elif defined(__m68k__)
# define systemd_NR_getrandom 352
@ -327,7 +327,7 @@ assert_cc(__NR_getrandom == systemd_NR_getrandom);
# define systemd_NR_memfd_create 356
# elif defined(__ia64__)
# define systemd_NR_memfd_create 1340
# elif defined(__loongarch64)
# elif defined(__loongarch_lp64)
# define systemd_NR_memfd_create 279
# elif defined(__m68k__)
# define systemd_NR_memfd_create 353
@ -395,7 +395,7 @@ assert_cc(__NR_memfd_create == systemd_NR_memfd_create);
# define systemd_NR_mount_setattr 442
# elif defined(__ia64__)
# define systemd_NR_mount_setattr 1466
# elif defined(__loongarch64)
# elif defined(__loongarch_lp64)
# define systemd_NR_mount_setattr 442
# elif defined(__m68k__)
# define systemd_NR_mount_setattr 442
@ -463,7 +463,7 @@ assert_cc(__NR_mount_setattr == systemd_NR_mount_setattr);
# define systemd_NR_move_mount 429
# elif defined(__ia64__)
# define systemd_NR_move_mount 1453
# elif defined(__loongarch64)
# elif defined(__loongarch_lp64)
# define systemd_NR_move_mount 429
# elif defined(__m68k__)
# define systemd_NR_move_mount 429
@ -531,7 +531,7 @@ assert_cc(__NR_move_mount == systemd_NR_move_mount);
# define systemd_NR_name_to_handle_at 341
# elif defined(__ia64__)
# define systemd_NR_name_to_handle_at 1326
# elif defined(__loongarch64)
# elif defined(__loongarch_lp64)
# define systemd_NR_name_to_handle_at 264
# elif defined(__m68k__)
# define systemd_NR_name_to_handle_at 340
@ -599,7 +599,7 @@ assert_cc(__NR_name_to_handle_at == systemd_NR_name_to_handle_at);
# define systemd_NR_open_tree 428
# elif defined(__ia64__)
# define systemd_NR_open_tree 1452
# elif defined(__loongarch64)
# elif defined(__loongarch_lp64)
# define systemd_NR_open_tree 428
# elif defined(__m68k__)
# define systemd_NR_open_tree 428
@ -667,7 +667,7 @@ assert_cc(__NR_open_tree == systemd_NR_open_tree);
# define systemd_NR_openat2 437
# elif defined(__ia64__)
# define systemd_NR_openat2 1461
# elif defined(__loongarch64)
# elif defined(__loongarch_lp64)
# define systemd_NR_openat2 437
# elif defined(__m68k__)
# define systemd_NR_openat2 437
@ -735,7 +735,7 @@ assert_cc(__NR_openat2 == systemd_NR_openat2);
# define systemd_NR_pidfd_open 434
# elif defined(__ia64__)
# define systemd_NR_pidfd_open 1458
# elif defined(__loongarch64)
# elif defined(__loongarch_lp64)
# define systemd_NR_pidfd_open 434
# elif defined(__m68k__)
# define systemd_NR_pidfd_open 434
@ -803,7 +803,7 @@ assert_cc(__NR_pidfd_open == systemd_NR_pidfd_open);
# define systemd_NR_pidfd_send_signal 424
# elif defined(__ia64__)
# define systemd_NR_pidfd_send_signal 1448
# elif defined(__loongarch64)
# elif defined(__loongarch_lp64)
# define systemd_NR_pidfd_send_signal 424
# elif defined(__m68k__)
# define systemd_NR_pidfd_send_signal 424
@ -871,7 +871,7 @@ assert_cc(__NR_pidfd_send_signal == systemd_NR_pidfd_send_signal);
# define systemd_NR_pkey_mprotect 380
# elif defined(__ia64__)
# define systemd_NR_pkey_mprotect 1354
# elif defined(__loongarch64)
# elif defined(__loongarch_lp64)
# define systemd_NR_pkey_mprotect 288
# elif defined(__m68k__)
# define systemd_NR_pkey_mprotect 381
@ -939,7 +939,7 @@ assert_cc(__NR_pkey_mprotect == systemd_NR_pkey_mprotect);
# define systemd_NR_renameat2 353
# elif defined(__ia64__)
# define systemd_NR_renameat2 1338
# elif defined(__loongarch64)
# elif defined(__loongarch_lp64)
# define systemd_NR_renameat2 276
# elif defined(__m68k__)
# define systemd_NR_renameat2 351
@ -1007,7 +1007,7 @@ assert_cc(__NR_renameat2 == systemd_NR_renameat2);
# define systemd_NR_setns 346
# elif defined(__ia64__)
# define systemd_NR_setns 1330
# elif defined(__loongarch64)
# elif defined(__loongarch_lp64)
# define systemd_NR_setns 268
# elif defined(__m68k__)
# define systemd_NR_setns 344
@ -1075,7 +1075,7 @@ assert_cc(__NR_setns == systemd_NR_setns);
# define systemd_NR_statx 383
# elif defined(__ia64__)
# define systemd_NR_statx 1350
# elif defined(__loongarch64)
# elif defined(__loongarch_lp64)
# define systemd_NR_statx 291
# elif defined(__m68k__)
# define systemd_NR_statx 379

View File

@ -59,7 +59,7 @@ DEF_TEMPLATE_B = '''\
# define systemd_NR_{syscall} {nr_i386}
# elif defined(__ia64__)
# define systemd_NR_{syscall} {nr_ia64}
# elif defined(__loongarch64)
# elif defined(__loongarch_lp64)
# define systemd_NR_{syscall} {nr_loongarch64}
# elif defined(__m68k__)
# define systemd_NR_{syscall} {nr_m68k}

View File

@ -153,7 +153,7 @@ static Virtualization detect_vm_device_tree(void) {
#endif
}
#if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || defined(__loongarch64)
#if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || defined(__loongarch_lp64)
static Virtualization detect_vm_dmi_vendor(void) {
static const char* const dmi_vendors[] = {
"/sys/class/dmi/id/product_name", /* Test this before sys_vendor to detect KVM over QEMU */
@ -243,10 +243,10 @@ static int detect_vm_smbios(void) {
log_debug("DMI BIOS Extension table does not indicate virtualization.");
return SMBIOS_VM_BIT_UNSET;
}
#endif /* defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || defined(__loongarch64) */
#endif /* defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || defined(__loongarch_lp64) */
static Virtualization detect_vm_dmi(void) {
#if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || defined(__loongarch64)
#if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || defined(__loongarch_lp64)
int r;
r = detect_vm_dmi_vendor();

View File

@ -1643,6 +1643,9 @@ static int oci_seccomp_arch_from_string(const char *name, uint32_t *ret) {
} table[] = {
{ "SCMP_ARCH_AARCH64", SCMP_ARCH_AARCH64 },
{ "SCMP_ARCH_ARM", SCMP_ARCH_ARM },
#ifdef SCMP_ARCH_LOONGARCH64
{ "SCMP_ARCH_LOONGARCH64", SCMP_ARCH_LOONGARCH64 },
#endif
{ "SCMP_ARCH_MIPS", SCMP_ARCH_MIPS },
{ "SCMP_ARCH_MIPS64", SCMP_ARCH_MIPS64 },
{ "SCMP_ARCH_MIPS64N32", SCMP_ARCH_MIPS64N32 },

View File

@ -71,7 +71,7 @@ static const BaseFilesystem table[] = {
"usr/lib\0", "ld-linux-x86-64.so.2" },
# define KNOW_LIB64_DIRS 1
#elif defined(__ia64__)
#elif defined(__loongarch64)
#elif defined(__loongarch_lp64)
# define KNOW_LIB64_DIRS 1
# if defined(__loongarch_double_float)
{ "lib64", 0, "usr/lib/"LIB_ARCH_TUPLE"\0"

View File

@ -47,6 +47,8 @@ uint32_t seccomp_local_archs[] = {
SCMP_ARCH_AARCH64, /* native */
#elif defined(__arm__)
SCMP_ARCH_ARM,
#elif defined(__loongarch_lp64)
SCMP_ARCH_LOONGARCH64,
#elif defined(__mips__) && __BYTE_ORDER == __BIG_ENDIAN && _MIPS_SIM == _MIPS_SIM_ABI32
SCMP_ARCH_MIPSEL,
SCMP_ARCH_MIPS, /* native */
@ -126,6 +128,10 @@ const char* seccomp_arch_to_string(uint32_t c) {
return "arm";
case SCMP_ARCH_AARCH64:
return "arm64";
#ifdef SCMP_ARCH_LOONGARCH64
case SCMP_ARCH_LOONGARCH64:
return "loongarch64";
#endif
case SCMP_ARCH_MIPS:
return "mips";
case SCMP_ARCH_MIPS64:
@ -183,6 +189,10 @@ int seccomp_arch_from_string(const char *n, uint32_t *ret) {
*ret = SCMP_ARCH_ARM;
else if (streq(n, "arm64"))
*ret = SCMP_ARCH_AARCH64;
#ifdef SCMP_ARCH_LOONGARCH64
else if (streq(n, "loongarch64"))
*ret = SCMP_ARCH_LOONGARCH64;
#endif
else if (streq(n, "mips"))
*ret = SCMP_ARCH_MIPS;
else if (streq(n, "mips64"))
@ -1381,6 +1391,9 @@ int seccomp_protect_sysctl(void) {
if (IN_SET(arch,
SCMP_ARCH_AARCH64,
#ifdef SCMP_ARCH_LOONGARCH64
SCMP_ARCH_LOONGARCH64,
#endif
#ifdef SCMP_ARCH_RISCV64
SCMP_ARCH_RISCV64,
#endif
@ -1463,6 +1476,9 @@ int seccomp_restrict_address_families(Set *address_families, bool allow_list) {
case SCMP_ARCH_X32:
case SCMP_ARCH_ARM:
case SCMP_ARCH_AARCH64:
#ifdef SCMP_ARCH_LOONGARCH64
case SCMP_ARCH_LOONGARCH64:
#endif
case SCMP_ARCH_MIPSEL64N32:
case SCMP_ARCH_MIPS64N32:
case SCMP_ARCH_MIPSEL64:
@ -1719,7 +1735,7 @@ static int add_seccomp_syscall_filter(scmp_filter_ctx seccomp,
}
/* For known architectures, check that syscalls are indeed defined or not. */
#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64)
#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || defined(__loongarch_lp64) || (defined(__riscv) && __riscv_xlen == 64)
assert_cc(SCMP_SYS(shmget) > 0);
assert_cc(SCMP_SYS(shmat) > 0);
assert_cc(SCMP_SYS(shmdt) > 0);
@ -1768,16 +1784,19 @@ int seccomp_memory_deny_write_execute(void) {
case SCMP_ARCH_X86_64:
case SCMP_ARCH_X32:
case SCMP_ARCH_AARCH64:
#ifdef SCMP_ARCH_LOONGARCH64
case SCMP_ARCH_LOONGARCH64:
#endif
#ifdef SCMP_ARCH_RISCV64
case SCMP_ARCH_RISCV64:
#endif
filter_syscall = SCMP_SYS(mmap); /* amd64, x32, arm64 and riscv64 have only mmap */
filter_syscall = SCMP_SYS(mmap); /* amd64, x32, arm64, loongarch64 and riscv64 have only mmap */
shmat_syscall = SCMP_SYS(shmat);
break;
/* Please add more definitions here, if you port systemd to other architectures! */
#if !defined(__i386__) && !defined(__x86_64__) && !defined(__hppa__) && !defined(__hppa64__) && !defined(__powerpc__) && !defined(__powerpc64__) && !defined(__arm__) && !defined(__aarch64__) && !defined(__s390__) && !defined(__s390x__) && !(defined(__riscv) && __riscv_xlen == 64)
#if !defined(__i386__) && !defined(__x86_64__) && !defined(__hppa__) && !defined(__hppa64__) && !defined(__powerpc__) && !defined(__powerpc64__) && !defined(__arm__) && !defined(__aarch64__) && !defined(__s390__) && !defined(__s390x__) && !(defined(__riscv) && __riscv_xlen == 64) && !defined(__loongarch_lp64)
#warning "Consider adding the right mmap() syscall definitions here!"
#endif
}

View File

@ -208,7 +208,7 @@ _SD_BEGIN_DECLARATIONS;
# define SD_GPT_USR_NATIVE_VERITY SD_GPT_USR_IA64_VERITY
# define SD_GPT_USR_NATIVE_VERITY_SIG SD_GPT_USR_IA64_VERITY_SIG
#elif defined(__loongarch64)
#elif defined(__loongarch_lp64)
# define SD_GPT_ROOT_NATIVE SD_GPT_ROOT_LOONGARCH64
# define SD_GPT_ROOT_NATIVE_VERITY SD_GPT_ROOT_LOONGARCH64_VERITY
# define SD_GPT_ROOT_NATIVE_VERITY_SIG SD_GPT_ROOT_LOONGARCH64_VERITY_SIG

View File

@ -403,7 +403,7 @@ static void test_exec_personality(Manager *m) {
#elif defined(__i386__)
test(m, "exec-personality-x86.service", 0, CLD_EXITED);
#elif defined(__loongarch64)
#elif defined(__loongarch_lp64)
test(m, "exec-personality-loongarch64.service", 0, CLD_EXITED);
#else
log_notice("Unknown personality, skipping %s", __func__);

View File

@ -126,6 +126,9 @@ TEST(architecture_table) {
"x32\0"
"arm\0"
"arm64\0"
#ifdef SCMP_ARCH_LOONGARCH64
"loongarch64\0"
#endif
"mips\0"
"mips64\0"
"mips64-n32\0"
@ -631,7 +634,7 @@ TEST(memory_deny_write_execute_mmap) {
assert_se(seccomp_memory_deny_write_execute() >= 0);
p = mmap(NULL, page_size(), PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1,0);
#if defined(__x86_64__) || defined(__i386__) || defined(__powerpc64__) || defined(__arm__) || defined(__aarch64__)
#if defined(__x86_64__) || defined(__i386__) || defined(__powerpc64__) || defined(__arm__) || defined(__aarch64__) || defined(__loongarch_lp64)
assert_se(p == MAP_FAILED);
assert_se(errno == EPERM);
#endif
@ -703,7 +706,7 @@ TEST(memory_deny_write_execute_shmat) {
p = shmat(shmid, NULL, SHM_EXEC);
log_debug_errno(p == MAP_FAILED ? errno : 0, "shmat(SHM_EXEC): %m");
#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || defined(__loongarch_lp64)
assert_se(p == MAP_FAILED);
assert_se(errno == EPERM);
#endif