From fdb1a4dd886a25eb6ca792220182fad489a4b8cd Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 4 May 2021 12:18:48 +0200 Subject: [PATCH] base-linux: avoid legacy syscalls Until now, Genode's Linux system call bindings were based on original Unix system calls that were later superseded by more flexibile variants. E.g., 'openat' is a modern version of 'open'. Even though Linux upholds the compatiblity with the original versions for existing architectures like x86, the legacy syscalls are absent for the recently added AARCH64 architecture. A good overview of the system calls accross the prominent architectures can be found at https://chromium.googlesource.com/chromiumos/docs/+/master/constants/syscalls.md This patch updates Genode's syscall bindings to avoid legacy versions, thereby easing the support for AARCH64. The used "modern" versions were introduced back in Linux version 2 days. So we are fine to rely on them. The patch slightly changes the signature for lx_stat because this system call is merely used to check for the existance of a file and its size. The new name 'lx_stat_size' draws a closer connection to its use case. That said, the stat syscall has not been updated to the modern statx since statx is still a fairly recent addition. Issue #4136 --- .../src/core/include/core_linux_syscalls.h | 21 +++++++++++------- .../core/spec/linux/dataspace_component.cc | 7 +++--- .../src/core/spec/pc/dataspace_component.cc | 7 +++--- .../spec/x86_32/seccomp_bpf_policy.bin | Bin 352 -> 352 bytes .../spec/x86_64/seccomp_bpf_policy.bin | Bin 376 -> 376 bytes .../src/lib/syscall/linux_syscalls.h | 6 ++--- tool/seccomp/seccomp_bpf_compiler.h | 4 ++-- 7 files changed, 26 insertions(+), 19 deletions(-) diff --git a/repos/base-linux/src/core/include/core_linux_syscalls.h b/repos/base-linux/src/core/include/core_linux_syscalls.h index 842a2c638c..e2f613331e 100644 --- a/repos/base-linux/src/core/include/core_linux_syscalls.h +++ b/repos/base-linux/src/core/include/core_linux_syscalls.h @@ -32,7 +32,7 @@ inline int lx_mkdir(char const *pathname, mode_t mode) { - return lx_syscall(SYS_mkdir, pathname, mode); + return lx_syscall(SYS_mkdirat, AT_FDCWD, pathname, mode); } @@ -44,7 +44,7 @@ inline int lx_ftruncate(int fd, unsigned long length) inline int lx_unlink(const char *fname) { - return lx_syscall(SYS_unlink, fname); + return lx_syscall(SYS_unlinkat, AT_FDCWD, fname, 0); } @@ -52,19 +52,24 @@ inline int lx_unlink(const char *fname) ** Functions used by core's rom-session support code ** *******************************************************/ -inline int lx_open(const char *pathname, int flags, mode_t mode = 0) +inline int lx_open(char const *pathname, int flags, mode_t mode = 0) { - return lx_syscall(SYS_open, pathname, flags, mode); + return lx_syscall(SYS_openat, AT_FDCWD, pathname, flags, mode); } -inline int lx_stat(const char *path, struct stat64 *buf) +inline int lx_stat_size(char const *path, Genode::uint64_t &out_size) { #ifdef _LP64 - return lx_syscall(SYS_stat, path, buf); + struct stat buf { }; + int result = lx_syscall(SYS_stat, path, &buf); + out_size = buf.st_size; #else - return lx_syscall(SYS_stat64, path, buf); + struct stat64 buf { }; + int result = lx_syscall(SYS_stat64, path, &buf); + out_size = buf.st_size; #endif + return result; } @@ -253,7 +258,7 @@ inline int lx_connect(int sockfd, const struct sockaddr *serv_addr, inline int lx_pipe(int pipefd[2]) { - return lx_syscall(SYS_pipe, pipefd); + return lx_syscall(SYS_pipe2, pipefd, 0); } diff --git a/repos/base-linux/src/core/spec/linux/dataspace_component.cc b/repos/base-linux/src/core/spec/linux/dataspace_component.cc index db49d21187..bdc18ddf4d 100644 --- a/repos/base-linux/src/core/spec/linux/dataspace_component.cc +++ b/repos/base-linux/src/core/spec/linux/dataspace_component.cc @@ -54,10 +54,11 @@ Linux_dataspace::Filename Dataspace_component::_file_name(const char *args) size_t Dataspace_component::_file_size() { - struct stat64 s; - if (lx_stat(_fname.buf, &s) < 0) throw Service_denied(); + uint64_t size = 0; + if (lx_stat_size(_fname.buf, size) < 0) + throw Service_denied(); - return align_addr(s.st_size, 12); + return align_addr(size, 12); } diff --git a/repos/base-linux/src/core/spec/pc/dataspace_component.cc b/repos/base-linux/src/core/spec/pc/dataspace_component.cc index 18e810f90f..02df2925e3 100644 --- a/repos/base-linux/src/core/spec/pc/dataspace_component.cc +++ b/repos/base-linux/src/core/spec/pc/dataspace_component.cc @@ -53,10 +53,11 @@ Linux_dataspace::Filename Dataspace_component::_file_name(const char *args) Genode::size_t Dataspace_component::_file_size() { - struct stat64 s; - if (lx_stat(_fname.buf, &s) < 0) throw Service_denied(); + uint64_t size = 0; + if (lx_stat_size(_fname.buf, &size) < 0) + throw Service_denied(); - return s.st_size; + return size; } diff --git a/repos/base-linux/src/lib/seccomp/spec/x86_32/seccomp_bpf_policy.bin b/repos/base-linux/src/lib/seccomp/spec/x86_32/seccomp_bpf_policy.bin index a50b51e7f8853c859b00696fad9c86b63eccdde6..2d71040057ff9363db62c1c5e6ebf44dab8ac44a 100644 GIT binary patch delta 27 gcmaFB^nhu?8o~bz3=E5`0BUIl+5i9m delta 27 fcmaFB^nhu?8o_@I3=Epv*Y&T^9hXOb6`% delta 36 lcmeyt^n+=_6{)KX3=E