Skip to content

Commit

Permalink
Add support for RISC-V RV64 (64-bit, riscv64)
Browse files Browse the repository at this point in the history
The patch adds support for riscv64 architecture. It also enables
the following syscalls:
- riscv_flush_icache (RISC-V RV32/RV64 specific)
- preadv2
- pwritev2
- renameat
- renameat2
- io_pgetevents
- rseq

This was tested on Fedora 29/RISCV [0] using 4.19 kernel.
Tested on top of libseccomp commit:
1e64feb

Results for testing:

./regression -T live

Regression Test Summary
 tests run: 8
 tests skipped: 0
 tests passed: 8
 tests failed: 0
 tests errored: 0

./regression

Regression Test Summary
 tests run: 5129
 tests skipped: 104
 tests passed: 5129
 tests failed: 0
 tests errored: 0

[0] https://fedoraproject.org/wiki/Architectures/RISC-V

Signed-off-by: David Abdurachmanov <david.abdurachmanov@gmail.com>
  • Loading branch information
davidlt committed Dec 6, 2018
1 parent 1e64feb commit 2a70ad4
Show file tree
Hide file tree
Showing 36 changed files with 878 additions and 89 deletions.
49 changes: 49 additions & 0 deletions include/seccomp.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,19 @@ struct scmp_arg_cmp {
#define SCMP_ARCH_S390 AUDIT_ARCH_S390
#define SCMP_ARCH_S390X AUDIT_ARCH_S390X

/**
* The RISC-V architecture tokens
*/
#ifndef EM_RISCV
#define EM_RISCV 243
#endif /* EM_RISCV */

#ifndef AUDIT_ARCH_RISCV64
#define AUDIT_ARCH_RISCV64 (EM_RISCV|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
#endif /* AUDIT_ARCH_RISCV64 */

#define SCMP_ARCH_RISCV64 AUDIT_ARCH_RISCV64

/**
* The PA-RISC hppa architecture tokens
*/
Expand Down Expand Up @@ -1690,7 +1703,43 @@ int seccomp_export_bpf(const scmp_filter_ctx ctx, int fd);
#define __NR_subpage_prot __PNR_subpage_prot
#endif /* __NR_subpage_prot */

#define __PNR_riscv_flush_icache -10207
#ifndef __NR_riscv_flush_icache
#define __NR_riscv_flush_icache __PNR_riscv_flush_icache
#endif /* __NR_riscv_flush_icache */

#define __PNR_preadv2 -10208
#ifndef __NR_preadv2
#define __NR_preadv2 __PNR_preadv2
#endif /* __NR_preadv2 */

#define __PNR_pwritev2 -10209
#ifndef __NR_pwritev2
#define __NR_pwritev2 __PNR_pwritev2
#endif /* __NR_pwritev2 */

#define __PNR_renameat -10210
#ifndef __NR_renameat
#define __NR_renameat __PNR_renameat
#endif /* __NR_renameat */

#define __PNR_renameat2 -10211
#ifndef __NR_renameat2
#define __NR_renameat2 __PNR_renameat2
#endif /* __NR_renameat2 */

#define __PNR_io_pgetevents -10212
#ifndef __NR_io_pgetevents
#define __NR_io_pgetevents __PNR_io_pgetevents
#endif /* __NR_io_pgetevents */

#define __PNR_rseq -10213
#ifndef __NR_rseq
#define __NR_rseq __PNR_rseq
#endif /* __NR_rseq */

#ifdef __cplusplus

}
#endif

Expand Down
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ SOURCES_ALL = \
arch-parisc.h arch-parisc.c arch-parisc64.c arch-parisc-syscalls.c \
arch-ppc.h arch-ppc.c arch-ppc-syscalls.c \
arch-ppc64.h arch-ppc64.c arch-ppc64-syscalls.c \
arch-riscv64.h arch-riscv64.c arch-riscv64-syscalls.c \
arch-s390.h arch-s390.c arch-s390-syscalls.c \
arch-s390x.h arch-s390x.c arch-s390x-syscalls.c

Expand Down
11 changes: 7 additions & 4 deletions src/arch-aarch64-syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ const struct arch_syscall_def aarch64_syscall_table[] = { \
{ "io_cancel", 3 },
{ "io_destroy", 1 },
{ "io_getevents", 4 },
{ "io_pgetevents", __PNR_io_pgetevents },
{ "io_setup", 0 },
{ "io_submit", 2 },
{ "ioctl", 29 },
Expand Down Expand Up @@ -263,7 +264,7 @@ const struct arch_syscall_def aarch64_syscall_table[] = { \
{ "prctl", 167 },
{ "pread64", 67 },
{ "preadv", 69 },
{ "preadv2", 286 },
{ "preadv2", __PNR_preadv2 },
{ "prlimit64", 261 },
{ "process_vm_readv", 270 },
{ "process_vm_writev", 271 },
Expand All @@ -274,7 +275,7 @@ const struct arch_syscall_def aarch64_syscall_table[] = { \
{ "putpmsg", __PNR_putpmsg },
{ "pwrite64", 68 },
{ "pwritev", 70 },
{ "pwritev2", 287 },
{ "pwritev2", __PNR_pwritev2 },
{ "query_module", __PNR_query_module },
{ "quotactl", 60 },
{ "read", 63 },
Expand All @@ -287,15 +288,17 @@ const struct arch_syscall_def aarch64_syscall_table[] = { \
{ "recv", __PNR_recv },
{ "recvfrom", 207 },
{ "recvmmsg", 243 },
{ "riscv_flush_icache", __PNR_riscv_flush_icache },
{ "recvmsg", 212 },
{ "remap_file_pages", 234 },
{ "removexattr", 14 },
{ "rename", __PNR_rename },
{ "renameat", 38 },
{ "renameat2", 276 },
{ "renameat", __PNR_renameat },
{ "renameat2", __PNR_renameat2 },
{ "request_key", 218 },
{ "restart_syscall", 128 },
{ "rmdir", __PNR_rmdir },
{ "rseq", __PNR_rseq },
{ "rt_sigaction", 134 },
{ "rt_sigpending", 136 },
{ "rt_sigprocmask", 135 },
Expand Down
11 changes: 7 additions & 4 deletions src/arch-arm-syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ const struct arch_syscall_def arm_syscall_table[] = { \
{ "io_cancel", (__SCMP_NR_BASE + 247) },
{ "io_destroy", (__SCMP_NR_BASE + 244) },
{ "io_getevents", (__SCMP_NR_BASE + 245) },
{ "io_pgetevents", __PNR_io_pgetevents },
{ "io_setup", (__SCMP_NR_BASE + 243) },
{ "io_submit", (__SCMP_NR_BASE + 246) },
{ "ioctl", (__SCMP_NR_BASE + 54) },
Expand Down Expand Up @@ -275,7 +276,7 @@ const struct arch_syscall_def arm_syscall_table[] = { \
{ "prctl", (__SCMP_NR_BASE + 172) },
{ "pread64", (__SCMP_NR_BASE + 180) },
{ "preadv", (__SCMP_NR_BASE + 361) },
{ "preadv2", (__SCMP_NR_BASE + 392) },
{ "preadv2", __PNR_preadv2 },
{ "prlimit64", (__SCMP_NR_BASE + 369) },
{ "process_vm_readv", (__SCMP_NR_BASE + 376) },
{ "process_vm_writev", (__SCMP_NR_BASE + 377) },
Expand All @@ -286,7 +287,7 @@ const struct arch_syscall_def arm_syscall_table[] = { \
{ "putpmsg", __PNR_putpmsg },
{ "pwrite64", (__SCMP_NR_BASE + 181) },
{ "pwritev", (__SCMP_NR_BASE + 362) },
{ "pwritev2", (__SCMP_NR_BASE + 393) },
{ "pwritev2", __PNR_pwritev2 },
{ "query_module", __PNR_query_module },
{ "quotactl", (__SCMP_NR_BASE + 131) },
{ "read", (__SCMP_NR_BASE + 3) },
Expand All @@ -299,15 +300,17 @@ const struct arch_syscall_def arm_syscall_table[] = { \
{ "recv", (__SCMP_NR_BASE + 291) },
{ "recvfrom", (__SCMP_NR_BASE + 292) },
{ "recvmmsg", (__SCMP_NR_BASE + 365) },
{ "riscv_flush_icache", __PNR_riscv_flush_icache },
{ "recvmsg", (__SCMP_NR_BASE + 297) },
{ "remap_file_pages", (__SCMP_NR_BASE + 253) },
{ "removexattr", (__SCMP_NR_BASE + 235) },
{ "rename", (__SCMP_NR_BASE + 38) },
{ "renameat", (__SCMP_NR_BASE + 329) },
{ "renameat2", (__SCMP_NR_BASE + 382) },
{ "renameat", __PNR_renameat },
{ "renameat2", __PNR_renameat2 },
{ "request_key", (__SCMP_NR_BASE + 310) },
{ "restart_syscall", (__SCMP_NR_BASE + 0) },
{ "rmdir", (__SCMP_NR_BASE + 40) },
{ "rseq", __PNR_rseq },
{ "rt_sigaction", (__SCMP_NR_BASE + 174) },
{ "rt_sigpending", (__SCMP_NR_BASE + 176) },
{ "rt_sigprocmask", (__SCMP_NR_BASE + 175) },
Expand Down
11 changes: 7 additions & 4 deletions src/arch-mips-syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const struct arch_syscall_def mips_syscall_table[] = { \
{ "io_cancel", (__SCMP_NR_BASE + 245) },
{ "io_destroy", (__SCMP_NR_BASE + 242) },
{ "io_getevents", (__SCMP_NR_BASE + 243) },
{ "io_pgetevents", __PNR_io_pgetevents },
{ "io_setup", (__SCMP_NR_BASE + 241) },
{ "io_submit", (__SCMP_NR_BASE + 244) },
{ "ioctl", (__SCMP_NR_BASE + 54) },
Expand Down Expand Up @@ -267,7 +268,7 @@ const struct arch_syscall_def mips_syscall_table[] = { \
{ "prctl", (__SCMP_NR_BASE + 192) },
{ "pread64", (__SCMP_NR_BASE + 200) },
{ "preadv", (__SCMP_NR_BASE + 330) },
{ "preadv2", (__SCMP_NR_BASE + 361) },
{ "preadv2", __PNR_preadv2 },
{ "prlimit64", (__SCMP_NR_BASE + 338) },
{ "process_vm_readv", (__SCMP_NR_BASE + 345) },
{ "process_vm_writev", (__SCMP_NR_BASE + 346) },
Expand All @@ -278,7 +279,7 @@ const struct arch_syscall_def mips_syscall_table[] = { \
{ "putpmsg", (__SCMP_NR_BASE + 209) },
{ "pwrite64", (__SCMP_NR_BASE + 201) },
{ "pwritev", (__SCMP_NR_BASE + 331) },
{ "pwritev2", (__SCMP_NR_BASE + 362) },
{ "pwritev2", __PNR_pwritev2 },
{ "query_module", (__SCMP_NR_BASE + 187) },
{ "quotactl", (__SCMP_NR_BASE + 131) },
{ "read", (__SCMP_NR_BASE + 3) },
Expand All @@ -291,15 +292,17 @@ const struct arch_syscall_def mips_syscall_table[] = { \
{ "recv", (__SCMP_NR_BASE + 175) },
{ "recvfrom", (__SCMP_NR_BASE + 176) },
{ "recvmmsg", (__SCMP_NR_BASE + 335) },
{ "riscv_flush_icache", __PNR_riscv_flush_icache },
{ "recvmsg", (__SCMP_NR_BASE + 177) },
{ "remap_file_pages", (__SCMP_NR_BASE + 251) },
{ "removexattr", (__SCMP_NR_BASE + 233) },
{ "rename", (__SCMP_NR_BASE + 38) },
{ "renameat", (__SCMP_NR_BASE + 295) },
{ "renameat2", (__SCMP_NR_BASE + 351) },
{ "renameat", __PNR_renameat },
{ "renameat2", __PNR_renameat2 },
{ "request_key", (__SCMP_NR_BASE + 281) },
{ "restart_syscall", (__SCMP_NR_BASE + 253) },
{ "rmdir", (__SCMP_NR_BASE + 40) },
{ "rseq", __PNR_rseq },
{ "rt_sigaction", (__SCMP_NR_BASE + 194) },
{ "rt_sigpending", (__SCMP_NR_BASE + 196) },
{ "rt_sigprocmask", (__SCMP_NR_BASE + 195) },
Expand Down
11 changes: 7 additions & 4 deletions src/arch-mips64-syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const struct arch_syscall_def mips64_syscall_table[] = { \
{ "io_cancel", (__SCMP_NR_BASE + 204) },
{ "io_destroy", (__SCMP_NR_BASE + 201) },
{ "io_getevents", (__SCMP_NR_BASE + 202) },
{ "io_pgetevents", __PNR_io_pgetevents },
{ "io_setup", (__SCMP_NR_BASE + 200) },
{ "io_submit", (__SCMP_NR_BASE + 203) },
{ "ioctl", (__SCMP_NR_BASE + 15) },
Expand Down Expand Up @@ -267,7 +268,7 @@ const struct arch_syscall_def mips64_syscall_table[] = { \
{ "prctl", (__SCMP_NR_BASE + 153) },
{ "pread64", (__SCMP_NR_BASE + 16) },
{ "preadv", (__SCMP_NR_BASE + 289) },
{ "preadv2", (__SCMP_NR_BASE + 321) },
{ "preadv2", __PNR_preadv2 },
{ "prlimit64", (__SCMP_NR_BASE + 297) },
{ "process_vm_readv", (__SCMP_NR_BASE + 304) },
{ "process_vm_writev", (__SCMP_NR_BASE + 305) },
Expand All @@ -278,7 +279,7 @@ const struct arch_syscall_def mips64_syscall_table[] = { \
{ "putpmsg", (__SCMP_NR_BASE + 175) },
{ "pwrite64", (__SCMP_NR_BASE + 17) },
{ "pwritev", (__SCMP_NR_BASE + 290) },
{ "pwritev2", (__SCMP_NR_BASE + 322) },
{ "pwritev2", __PNR_pwritev2 },
{ "query_module", (__SCMP_NR_BASE + 171) },
{ "quotactl", (__SCMP_NR_BASE + 172) },
{ "read", (__SCMP_NR_BASE + 0) },
Expand All @@ -291,15 +292,17 @@ const struct arch_syscall_def mips64_syscall_table[] = { \
{ "recv", __PNR_recv },
{ "recvfrom", (__SCMP_NR_BASE + 44) },
{ "recvmmsg", (__SCMP_NR_BASE + 294) },
{ "riscv_flush_icache", __PNR_riscv_flush_icache },
{ "recvmsg", (__SCMP_NR_BASE + 46) },
{ "remap_file_pages", (__SCMP_NR_BASE + 210) },
{ "removexattr", (__SCMP_NR_BASE + 189) },
{ "rename", (__SCMP_NR_BASE + 80) },
{ "renameat", (__SCMP_NR_BASE + 254) },
{ "renameat2", (__SCMP_NR_BASE + 311) },
{ "renameat", __PNR_renameat },
{ "renameat2", __PNR_renameat2 },
{ "request_key", (__SCMP_NR_BASE + 240) },
{ "restart_syscall", (__SCMP_NR_BASE + 213) },
{ "rmdir", (__SCMP_NR_BASE + 82) },
{ "rseq", __PNR_rseq },
{ "rt_sigaction", (__SCMP_NR_BASE + 13) },
{ "rt_sigpending", (__SCMP_NR_BASE + 125) },
{ "rt_sigprocmask", (__SCMP_NR_BASE + 14) },
Expand Down
11 changes: 7 additions & 4 deletions src/arch-mips64n32-syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const struct arch_syscall_def mips64n32_syscall_table[] = { \
{ "io_cancel", (__SCMP_NR_BASE + 204) },
{ "io_destroy", (__SCMP_NR_BASE + 201) },
{ "io_getevents", (__SCMP_NR_BASE + 202) },
{ "io_pgetevents", __PNR_io_pgetevents },
{ "io_setup", (__SCMP_NR_BASE + 200) },
{ "io_submit", (__SCMP_NR_BASE + 203) },
{ "ioctl", (__SCMP_NR_BASE + 15) },
Expand Down Expand Up @@ -267,7 +268,7 @@ const struct arch_syscall_def mips64n32_syscall_table[] = { \
{ "prctl", (__SCMP_NR_BASE + 153) },
{ "pread64", (__SCMP_NR_BASE + 16) },
{ "preadv", (__SCMP_NR_BASE + 293) },
{ "preadv2", (__SCMP_NR_BASE + 325) },
{ "preadv2", __PNR_preadv2 },
{ "prlimit64", (__SCMP_NR_BASE + 302) },
{ "process_vm_readv", (__SCMP_NR_BASE + 309) },
{ "process_vm_writev", (__SCMP_NR_BASE + 310) },
Expand All @@ -278,7 +279,7 @@ const struct arch_syscall_def mips64n32_syscall_table[] = { \
{ "putpmsg", (__SCMP_NR_BASE + 175) },
{ "pwrite64", (__SCMP_NR_BASE + 17) },
{ "pwritev", (__SCMP_NR_BASE + 294) },
{ "pwritev2", (__SCMP_NR_BASE + 326) },
{ "pwritev2", __PNR_pwritev2 },
{ "query_module", (__SCMP_NR_BASE + 171) },
{ "quotactl", (__SCMP_NR_BASE + 172) },
{ "read", (__SCMP_NR_BASE + 0) },
Expand All @@ -291,15 +292,17 @@ const struct arch_syscall_def mips64n32_syscall_table[] = { \
{ "recv", __PNR_recv },
{ "recvfrom", (__SCMP_NR_BASE + 44) },
{ "recvmmsg", (__SCMP_NR_BASE + 298) },
{ "riscv_flush_icache", __PNR_riscv_flush_icache },
{ "recvmsg", (__SCMP_NR_BASE + 46) },
{ "remap_file_pages", (__SCMP_NR_BASE + 210) },
{ "removexattr", (__SCMP_NR_BASE + 189) },
{ "rename", (__SCMP_NR_BASE + 80) },
{ "renameat", (__SCMP_NR_BASE + 258) },
{ "renameat2", (__SCMP_NR_BASE + 315) },
{ "renameat", __PNR_renameat },
{ "renameat2", __PNR_renameat2 },
{ "request_key", (__SCMP_NR_BASE + 244) },
{ "restart_syscall", (__SCMP_NR_BASE + 214) },
{ "rmdir", (__SCMP_NR_BASE + 82) },
{ "rseq", __PNR_rseq },
{ "rt_sigaction", (__SCMP_NR_BASE + 13) },
{ "rt_sigpending", (__SCMP_NR_BASE + 125) },
{ "rt_sigprocmask", (__SCMP_NR_BASE + 14) },
Expand Down
11 changes: 7 additions & 4 deletions src/arch-parisc-syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const struct arch_syscall_def parisc_syscall_table[] = { \
{ "io_cancel", 219 },
{ "io_destroy", 216 },
{ "io_getevents", 217 },
{ "io_pgetevents", __PNR_io_pgetevents },
{ "io_setup", 215 },
{ "io_submit", 218 },
{ "ioctl", 54 },
Expand Down Expand Up @@ -247,7 +248,7 @@ const struct arch_syscall_def parisc_syscall_table[] = { \
{ "prctl", 172 },
{ "pread64", 108 },
{ "preadv", 315 },
{ "preadv2", 347 },
{ "preadv2", __PNR_preadv2 },
{ "prlimit64", 321 },
{ "process_vm_readv", 330 },
{ "process_vm_writev", 331 },
Expand All @@ -258,7 +259,7 @@ const struct arch_syscall_def parisc_syscall_table[] = { \
{ "putpmsg", 197 },
{ "pwrite64", 109 },
{ "pwritev", 316 },
{ "pwritev2", 348 },
{ "pwritev2", __PNR_pwritev2 },
{ "query_module", 167 },
{ "quotactl", 131 },
{ "read", 3 },
Expand All @@ -271,15 +272,17 @@ const struct arch_syscall_def parisc_syscall_table[] = { \
{ "recv", 98 },
{ "recvfrom", 123 },
{ "recvmmsg", 319 },
{ "riscv_flush_icache", __PNR_riscv_flush_icache },
{ "recvmsg", 184 },
{ "remap_file_pages", 227 },
{ "removexattr", 247 },
{ "rename", 38 },
{ "renameat", 282 },
{ "renameat2", 337 },
{ "renameat", __PNR_renameat },
{ "renameat2", __PNR_renameat2 },
{ "request_key", 265 },
{ "restart_syscall", 0 },
{ "rmdir", 40 },
{ "rseq", __PNR_rseq },
{ "rt_sigaction", 174 },
{ "rt_sigpending", 176 },
{ "rt_sigprocmask", 175 },
Expand Down
11 changes: 7 additions & 4 deletions src/arch-ppc-syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ const struct arch_syscall_def ppc_syscall_table[] = { \
{ "io_cancel", 231 },
{ "io_destroy", 228 },
{ "io_getevents", 229 },
{ "io_pgetevents", __PNR_io_pgetevents },
{ "io_setup", 227 },
{ "io_submit", 230 },
{ "ioctl", 54 },
Expand Down Expand Up @@ -264,7 +265,7 @@ const struct arch_syscall_def ppc_syscall_table[] = { \
{ "prctl", 171 },
{ "pread64", 179 },
{ "preadv", 320 },
{ "preadv2", 380 },
{ "preadv2", __PNR_preadv2 },
{ "prlimit64", 325 },
{ "process_vm_readv", 351 },
{ "process_vm_writev", 352 },
Expand All @@ -275,7 +276,7 @@ const struct arch_syscall_def ppc_syscall_table[] = { \
{ "putpmsg", 188 },
{ "pwrite64", 180 },
{ "pwritev", 321 },
{ "pwritev2", 381 },
{ "pwritev2", __PNR_pwritev2 },
{ "query_module", 166 },
{ "quotactl", 131 },
{ "read", 3 },
Expand All @@ -288,15 +289,17 @@ const struct arch_syscall_def ppc_syscall_table[] = { \
{ "recv", 336 },
{ "recvfrom", 337 },
{ "recvmmsg", 343 },
{ "riscv_flush_icache", __PNR_riscv_flush_icache },
{ "recvmsg", 342 },
{ "remap_file_pages", 239 },
{ "removexattr", 218 },
{ "rename", 38 },
{ "renameat", 293 },
{ "renameat2", 357 },
{ "renameat", __PNR_renameat },
{ "renameat2", __PNR_renameat2 },
{ "request_key", 270 },
{ "restart_syscall", 0 },
{ "rmdir", 40 },
{ "rseq", __PNR_rseq },
{ "rt_sigaction", 173 },
{ "rt_sigpending", 175 },
{ "rt_sigprocmask", 174 },
Expand Down
Loading

0 comments on commit 2a70ad4

Please sign in to comment.