Skip to content

Commit

Permalink
arch: Add 32-bit Motorola 68000 support
Browse files Browse the repository at this point in the history
Signed-off-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Acked-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
  • Loading branch information
glaubitz authored and drakenclimber committed Apr 25, 2023
1 parent 744c9a8 commit dd5c9c2
Show file tree
Hide file tree
Showing 22 changed files with 190 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The libseccomp library currently supports the architectures listed below:
* 32-bit ARM EABI (arm)
* 64-bit ARM (aarch64)
* 64-bit LoongArch (loongarch64)
* 32-bit Motorola 68000 (m68k)
* 32-bit MIPS (mips)
* 32-bit MIPS little endian (mipsel)
* 64-bit MIPS (mips64)
Expand Down
4 changes: 2 additions & 2 deletions doc/man/man1/scmp_sys_resolver.1
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ 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", "loongarch64", "mips",
"mipsel", "mips64", "mipsel64", "mips64n32", "mipsel64n32", "parisc",
values are "x86", "x86_64", "x32", "arm", "aarch64", "loongarch64", "m68k",
"mips", "mipsel", "mips64", "mipsel64", "mips64n32", "mipsel64n32", "parisc",
"parisc64", "ppc", "ppc64", "ppc64le", "s390", "s390x", "sheb" and "sh".
.TP
.B \-t
Expand Down
21 changes: 21 additions & 0 deletions include/seccomp-syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@
#define __PNR_riscv_flush_icache -10243
#define __PNR_memfd_secret -10244
#define __PNR_fstat -10245
#define __PNR_atomic_barrier -10246
#define __PNR_atomic_cmpxchg_32 -10247
#define __PNR_getpagesize -10248

/*
* libseccomp syscall definitions
Expand Down Expand Up @@ -354,6 +357,18 @@
#define __SNR_arch_prctl __PNR_arch_prctl
#endif

#ifdef __NR_atomic_barrier
#define __SNR_atomic_barrier __NR_atomic_barrier
#else
#define __SNR_atomic_barrier __PNR_atomic_barrier
#endif

#ifdef __NR_atomic_cmpxchg_32
#define __SNR_atomic_cmpxchg_32 __NR_atomic_cmpxchg_32
#else
#define __SNR_atomic_cmpxchg_32 __PNR_atomic_cmpxchg_32
#endif

#ifdef __NR_bdflush
#define __SNR_bdflush __NR_bdflush
#else
Expand Down Expand Up @@ -824,6 +839,12 @@

#define __SNR_getitimer __NR_getitimer

#ifdef __NR_getpagesize
#define __SNR_getpagesize __NR_getpagesize
#else
#define __SNR_getpagesize __PNR_getpagesize
#endif

#ifdef __NR_getpeername
#define __SNR_getpeername __NR_getpeername
#else
Expand Down
5 changes: 5 additions & 0 deletions include/seccomp.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ struct scmp_arg_cmp {
#endif /* AUDIT_ARCH_LOONGARCH64 */
#define SCMP_ARCH_LOONGARCH64 AUDIT_ARCH_LOONGARCH64

/**
* The Motorola 68000 architecture tokens
*/
#define SCMP_ARCH_M68K AUDIT_ARCH_M68K

/**
* The MIPS architecture tokens
*/
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ SOURCES_ALL = \
arch-arm.h arch-arm.c \
arch-aarch64.h arch-aarch64.c \
arch-loongarch64.h arch-loongarch64.c \
arch-m68k.h arch-m68k.c \
arch-mips.h arch-mips.c \
arch-mips64.h arch-mips64.c \
arch-mips64n32.h arch-mips64n32.c \
Expand Down
58 changes: 58 additions & 0 deletions src/arch-m68k.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Enhanced Seccomp m68k Specific Code
*
* Copyright (c) 2015 Freescale <bogdan.purcareata@freescale.com>
* 2017-2023 John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
* Author: Bogdan Purcareata <bogdan.purcareata@freescale.com>
* John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
*
* Derived from the PPC-specific code
*
*/

/*
* 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 <http://www.gnu.org/licenses>.
*/

#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <linux/audit.h>

#include "db.h"
#include "syscalls.h"
#include "arch.h"
#include "arch-m68k.h"

/* m68k syscall numbers */
#define __m68k_NR_socketcall 102
#define __m68k_NR_ipc 117

ARCH_DEF(m68k)

const struct arch_def arch_def_m68k = {
.token = SCMP_ARCH_M68K,
.token_bpf = AUDIT_ARCH_M68K,
.size = ARCH_SIZE_32,
.endian = ARCH_ENDIAN_BIG,
.sys_socketcall = __m68k_NR_socketcall,
.sys_ipc = __m68k_NR_ipc,
.syscall_resolve_name = abi_syscall_resolve_name_munge,
.syscall_resolve_name_raw = m68k_syscall_resolve_name,
.syscall_resolve_num = abi_syscall_resolve_num_munge,
.syscall_resolve_num_raw = m68k_syscall_resolve_num,
.syscall_rewrite = abi_syscall_rewrite,
.rule_add = abi_rule_add,
.syscall_name_kver = m68k_syscall_name_kver,
.syscall_num_kver = m68k_syscall_num_kver,
};
34 changes: 34 additions & 0 deletions src/arch-m68k.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Enhanced Seccomp m68k Specific Code
*
* Copyright (c) 2015 Freescale <bogdan.purcareata@freescale.com>
* 2017-2023 John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
* Author: Bogdan Purcareata <bogdan.purcareata@freescale.com>
* John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
*
* Derived from the PPC-specific code
*
*/

/*
* 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 <http://www.gnu.org/licenses>.
*/

#ifndef _ARCH_M68K_H
#define _ARCH_M68K_H

#include "arch.h"

ARCH_DECL(m68k)

#endif
3 changes: 3 additions & 0 deletions src/arch-syscall-dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "arch-x32.h"
#include "arch-arm.h"
#include "arch-loongarch64.h"
#include "arch-m68k.h"
#include "arch-mips.h"
#include "arch-mips64.h"
#include "arch-mips64n32.h"
Expand Down Expand Up @@ -110,6 +111,8 @@ int main(int argc, char *argv[])
break;
case SCMP_ARCH_LOONGARCH64:
sys = loongarch64_syscall_iterate(iter);
case SCMP_ARCH_M68K:
sys = m68k_syscall_iterate(iter);
break;
case SCMP_ARCH_MIPS:
case SCMP_ARCH_MIPSEL:
Expand Down
32 changes: 32 additions & 0 deletions src/arch-syscall-validate
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,30 @@ function dump_lib_loongarch64() {
dump_lib_arch loongarch64 | mangle_lib_syscall loongarch64
}

# Dump the m68k system syscall table
#
# Arguments:
# 1 path to the kernel source
#
# Dump the architecture's syscall table to stdout.
#
function dump_sys_m68k() {
cat $1/arch/m68k/kernel/syscalls/syscall.tbl | \
grep -v "^#" | \
sed -n "/[0-9]\+[ \t]\+\(common\)/p" | \
awk '{ print $3","$1 }' | \
sort
}

#
# Dump the m68k library syscall table
#
# Dump the library's syscall table to stdout.
#
function dump_lib_m68k() {
dump_lib_arch m68k | mangle_lib_syscall m68k
}

#
# Dump the mips system syscall table
#
Expand Down Expand Up @@ -664,6 +688,9 @@ function dump_sys() {
loongarch64)
dump_sys_loongarch64 "$2"
;;
m68k)
dump_sys_m68k "$2"
;;
mips)
dump_sys_mips "$2"
;;
Expand Down Expand Up @@ -734,6 +761,9 @@ function dump_lib() {
loongarch64)
dump_lib_loongarch64
;;
m68k)
dump_lib_m68k
;;
mips)
dump_lib_mips
;;
Expand Down Expand Up @@ -799,6 +829,7 @@ function gen_csv() {
abi_list+=" x86 x86_64 x32"
abi_list+=" arm aarch64"
abi_list+=" loongarch64"
abi_list+=" m68k"
abi_list+=" mips mips64 mips64n32"
abi_list+=" parisc parisc64"
abi_list+=" ppc ppc64"
Expand Down Expand Up @@ -911,6 +942,7 @@ if [[ $opt_arches == "" ]]; then
x86 x86_64 x32 \
arm aarch64 \
loongarch64 \
m68k \
mips mips64 mips64n32 \
parisc parisc64 \
ppc ppc64 \
Expand Down
7 changes: 7 additions & 0 deletions src/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "arch-arm.h"
#include "arch-aarch64.h"
#include "arch-loongarch64.h"
#include "arch-m68k.h"
#include "arch-mips.h"
#include "arch-mips64.h"
#include "arch-mips64n32.h"
Expand Down Expand Up @@ -66,6 +67,8 @@ const struct arch_def *arch_def_native = &arch_def_arm;
const struct arch_def *arch_def_native = &arch_def_aarch64;
#elif __loongarch_lp64
const struct arch_def *arch_def_native = &arch_def_loongarch64;
#elif __m68k__
const struct arch_def *arch_def_native = &arch_def_m68k;
#elif __mips__ && _MIPS_SIM == _MIPS_SIM_ABI32
#if __MIPSEB__
const struct arch_def *arch_def_native = &arch_def_mips;
Expand Down Expand Up @@ -146,6 +149,8 @@ const struct arch_def *arch_def_lookup(uint32_t token)
return &arch_def_aarch64;
case SCMP_ARCH_LOONGARCH64:
return &arch_def_loongarch64;
case SCMP_ARCH_M68K:
return &arch_def_m68k;
case SCMP_ARCH_MIPS:
return &arch_def_mips;
case SCMP_ARCH_MIPSEL:
Expand Down Expand Up @@ -204,6 +209,8 @@ const struct arch_def *arch_def_lookup_name(const char *arch_name)
return &arch_def_aarch64;
else if (strcmp(arch_name, "loongarch64") == 0)
return &arch_def_loongarch64;
else if (strcmp(arch_name, "m68k") == 0)
return &arch_def_m68k;
else if (strcmp(arch_name, "mips") == 0)
return &arch_def_mips;
else if (strcmp(arch_name, "mipsel") == 0)
Expand Down
2 changes: 2 additions & 0 deletions src/gen_pfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ static const char *_pfc_arch(const struct arch_def *arch)
return "aarch64";
case SCMP_ARCH_LOONGARCH64:
return "loongarch64";
case SCMP_ARCH_M68K:
return "m68k";
case SCMP_ARCH_MIPS:
return "mips";
case SCMP_ARCH_MIPSEL:
Expand Down
1 change: 1 addition & 0 deletions src/python/libseccomp.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ cdef extern from "seccomp.h":
SCMP_ARCH_ARM
SCMP_ARCH_AARCH64
SCMP_ARCH_LOONGARCH64
SCMP_ARCH_M68K
SCMP_ARCH_MIPS
SCMP_ARCH_MIPS64
SCMP_ARCH_MIPS64N32
Expand Down
4 changes: 4 additions & 0 deletions src/python/seccomp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ cdef class Arch:
ARM - ARM
AARCH64 - 64-bit ARM
LOONGARCH64 - 64-bit LoongArch
M68K - 32-bit Motorola 68000
MIPS - MIPS O32 ABI
MIPS64 - MIPS 64-bit ABI
MIPS64N32 - MIPS N32 ABI
Expand All @@ -229,6 +230,7 @@ cdef class Arch:
ARM = libseccomp.SCMP_ARCH_ARM
AARCH64 = libseccomp.SCMP_ARCH_AARCH64
LOONGARCH64 = libseccomp.SCMP_ARCH_LOONGARCH64
M68K = libseccomp.SCMP_ARCH_M68K
MIPS = libseccomp.SCMP_ARCH_MIPS
MIPS64 = libseccomp.SCMP_ARCH_MIPS64
MIPS64N32 = libseccomp.SCMP_ARCH_MIPS64N32
Expand Down Expand Up @@ -268,6 +270,8 @@ cdef class Arch:
self._token = libseccomp.SCMP_ARCH_AARCH64
elif arch == libseccomp.SCMP_ARCH_LOONGARCH64:
self._token = libseccomp.SCMP_ARCH_LOONGARCH64
elif arch == libseccomp.SCMP_ARCH_M68K:
self._token = libseccomp.SCMP_ARCH_M68K
elif arch == libseccomp.SCMP_ARCH_MIPS:
self._token = libseccomp.SCMP_ARCH_MIPS
elif arch == libseccomp.SCMP_ARCH_MIPS64:
Expand Down
4 changes: 4 additions & 0 deletions src/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "arch-arm.h"
#include "arch.h"
#include "arch-loongarch64.h"
#include "arch-m68k.h"
#include "arch-mips64.h"
#include "arch-mips64n32.h"
#include "arch-mips.h"
Expand Down Expand Up @@ -55,6 +56,9 @@ struct arch_syscall_table {
int loongarch64;
enum scmp_kver loongarch64_kver;

int m68k;
enum scmp_kver m68k_kver;

int mips;
enum scmp_kver mips_kver;
int mips64;
Expand Down
1 change: 1 addition & 0 deletions tests/15-basic-resolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ unsigned int arch_list[] = {
SCMP_ARCH_ARM,
SCMP_ARCH_AARCH64,
SCMP_ARCH_LOONGARCH64,
SCMP_ARCH_M68K,
SCMP_ARCH_MIPS,
SCMP_ARCH_MIPS64,
SCMP_ARCH_MIPS64N32,
Expand Down
3 changes: 3 additions & 0 deletions tests/26-sim-arch_all_be_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ int main(int argc, char *argv[])
if (rc != 0)
goto out;

rc = seccomp_arch_add(ctx, seccomp_arch_resolve_name("m68k"));
if (rc != 0)
goto out;
rc = seccomp_arch_add(ctx, seccomp_arch_resolve_name("mips"));
if (rc != 0)
goto out;
Expand Down
1 change: 1 addition & 0 deletions tests/26-sim-arch_all_be_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
def test(args):
f = SyscallFilter(KILL)
f.remove_arch(Arch())
f.add_arch(Arch("m68k"))
f.add_arch(Arch("mips"))
f.add_arch(Arch("mips64"))
f.add_arch(Arch("mips64n32"))
Expand Down
1 change: 1 addition & 0 deletions tests/56-basic-iterate_syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ unsigned int arch_list[] = {
SCMP_ARCH_ARM,
SCMP_ARCH_AARCH64,
SCMP_ARCH_LOONGARCH64,
SCMP_ARCH_M68K,
SCMP_ARCH_MIPS,
SCMP_ARCH_MIPS64,
SCMP_ARCH_MIPS64N32,
Expand Down
Loading

0 comments on commit dd5c9c2

Please sign in to comment.