strace of `./file` command: ...... brk(NULL) = 0x55cec680b000 brk(0x55cec680c000) = 0x55cec680c000 brk(0x55cec680d000) = 0x55cec680d000 brk(0x55cec680e000) = 0x55cec680e000 brk(0x55cec680f000) = 0x55cec680f000 prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) = 0 seccomp(SECCOMP_SET_MODE_STRICT, 1, NULL) = -1 EINVAL (Invalid argument) seccomp(SECCOMP_SET_MODE_FILTER, 0, 0x7faa4aadc680) = 0 stat(0x7faa4ab54020, 0x7ffc5216eef0) = -1 ENOENT (No such file or directory) stat(0x7faa4ab54020, 0x7ffc5216eef0) = -1 ENOENT (No such file or directory) open(0x7faa4aaa94a0, O_RDONLY) = -1 ENOENT (No such file or directory) stat(0x7faa4ab54020, 0x7ffc5216ee80) = -1 ENOENT (No such file or directory) open(0x7faa4ab54020, O_RDONLY) = -1 ENOENT (No such file or directory) sys-apps/file[seccomp] writev(2, 0x7ffc5216ee40, 2) = ? +++ killed by SIGSYS +++ zsh: invalid system call strace ./file gdb with "catch syscall": ... Catchpoint 1 (call to syscall 10), __mprotect (addr=<optimized out>, len=<optimized out>, prot=<optimized out>) at src/mman/mprotect.c:10 10 src/mman/mprotect.c: No such file or directory. (gdb) c Continuing. Catchpoint 1 (returned from syscall 10), __mprotect (addr=<optimized out>, len=<optimized out>, prot=<optimized out>) at src/mman/mprotect.c:10 10 in src/mman/mprotect.c (gdb) Continuing. Catchpoint 1 (call to syscall 20), __stdio_write (f=0x7ffff7ffbd18 <__stderr_FILE>, buf=<optimized out>, len=244) at src/stdio/__stdio_write.c:15 15 src/stdio/__stdio_write.c: No such file or directory. (gdb) c Continuing. Program terminated with signal SIGSYS, Bad system call. The program no longer exists. musl's __stdio_write.c have the following code: size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len) { struct iovec iovs[2] = { { .iov_base = f->wbase, .iov_len = f->wpos-f->wbase }, { .iov_base = (void *)buf, .iov_len = len } }; struct iovec *iov = iovs; size_t rem = iov[0].iov_len + iov[1].iov_len; int iovcnt = 2; ssize_t cnt; for (;;) { cnt = syscall(SYS_writev, f->fd, iov, iovcnt); if (cnt == rem) { f->wend = f->buf + f->buf_size; f->wpos = f->wbase = f->buf; return len; } if (cnt < 0) { f->wpos = f->wbase = f->wend = 0; f->flags |= F_ERR; return iovcnt == 2 ? 0 : len-iov[0].iov_len; } rem -= cnt; if (cnt > iov[0].iov_len) { cnt -= iov[0].iov_len; iov++; iovcnt--; } iov[0].iov_base = (char *)iov[0].iov_base + cnt; iov[0].iov_len -= cnt; } } But file's seccomp.c don't put "writev" in allow list. Add "writev" into allow list fix this issue: diff --git a/src/seccomp.c b/src/seccomp.c index 68c56485..aee9e957 100644 --- a/src/seccomp.c +++ b/src/seccomp.c @@ -226,6 +226,7 @@ enable_sandbox_full(void) ALLOW_RULE(getpid); // Used by glibc in file_pipe2file() ALLOW_RULE(unlink); ALLOW_RULE(write); + ALLOW_RULE(writev); #if 0 Reproducible: Always Steps to Reproduce: 1.emerge sys-apps/file on musl system 2.run `file` command 3. Actual Results: bash: Bad system call zsh: invalid system call Expected Results: show file's usage Portage 2.3.103 (python 3.8.3-final-0, default/linux/amd64/17.0/musl, gcc-10.0.0, musl-1.2.0-r1, 5.7.7-zen+ x86_64) ================================================================= System uname: Linux-5.7.7-zen+-x86_64-Intel-R-_Core-TM-_i9-10900K_CPU_@_3.70GHz-with-libc KiB Mem: 131716948 total, 123726324 free KiB Swap: 16777212 total, 16777212 free Timestamp of repository gentoo: Thu, 02 Jul 2020 23:05:28 +0000 Head commit of repository gentoo: 21cdbb1d04a3040cdb4ed91c72c6dea4055c23c4 Timestamp of repository gentoo-zh: Thu, 02 Jul 2020 08:38:54 +0000 Head commit of repository gentoo-zh: 02359beb21d1c5fa591e297e8521980144503c34 Timestamp of repository jorgicio: Thu, 02 Jul 2020 08:38:58 +0000 Head commit of repository jorgicio: 8bd01f2783805f8a0d07cd5a9b2d2ebb4b5bfbb2 Timestamp of repository lanodanOverlay: Thu, 02 Jul 2020 08:39:24 +0000 Head commit of repository lanodanOverlay: c12852dcc8315c6e74b8f24b004519a9e14f4b29 Timestamp of repository lto-overlay: Thu, 02 Jul 2020 14:35:12 +0000 Head commit of repository lto-overlay: 2da6204db51fb955ffddfb021b54a96980d87f24 Timestamp of repository musl: Thu, 02 Jul 2020 08:39:02 +0000 Head commit of repository musl: e6936b8b4d99a8a1e24cfd23fac8c59927c0a28b Timestamp of repository mv: Thu, 02 Jul 2020 08:39:02 +0000 Head commit of repository mv: 4932a916b610979237f80f555cb58b579098e5b5 Timestamp of repository sorrow: Thu, 02 Jul 2020 14:05:17 +0000 Head commit of repository sorrow: 2d7ed9e21d5817ced16e4e1429c2a9fbfb6e4d8b sh bash 5.0_p17 ld LLD 10.0.0 (compatible with GNU linkers) ccache version 3.7.10 [enabled] app-shells/bash: 5.0_p17::gentoo dev-java/java-config: 2.3.1::gentoo dev-lang/perl: 5.30.3-r1::gentoo dev-lang/python: 2.7.18-r100::lto-overlay, 3.7.8::gentoo, 3.8.3-r1::lto-overlay dev-util/ccache: 3.7.10::gentoo dev-util/cmake: 3.17.3::gentoo dev-util/pkgconfig: 0.29.2::gentoo sys-apps/baselayout: 2.7::gentoo sys-apps/openrc: 0.42.1::gentoo sys-apps/sandbox: 2.20::gentoo sys-devel/autoconf: 2.13-r1::gentoo, 2.69-r5::gentoo sys-devel/automake: 1.16.2::gentoo sys-devel/binutils: 2.34::12101111-overlay sys-devel/libtool: 2.4.6-r6::gentoo sys-devel/make: 4.2.1-r4::gentoo sys-kernel/linux-headers: 5.7::gentoo (virtual/os-headers) sys-libs/musl: 1.2.0-r1::gentoo Repositories: gentoo location: /usr/portage/gentoo sync-type: git sync-uri: https://github.com/gentoo-mirror/gentoo priority: -1000 12101111-overlay location: /usr/portage/local masters: gentoo gentoo-zh location: /usr/portage/gentoo-zh sync-type: git sync-uri: https://github.com/gentoo-mirror/gentoo-zh.git masters: gentoo jorgicio location: /usr/portage/jorgicio sync-type: git sync-uri: https://github.com/gentoo-mirror/jorgicio.git masters: gentoo lanodanOverlay location: /usr/portage/lanodanOverlay sync-type: git sync-uri: https://github.com/gentoo-mirror/lanodanOverlay.git masters: gentoo lto-overlay location: /usr/portage/lto-overlay sync-type: git sync-uri: https://github.com/gentoo-mirror/lto-overlay.git masters: gentoo mv musl location: /usr/portage/musl sync-type: git sync-uri: https://github.com/gentoo-mirror/musl.git masters: gentoo mv location: /usr/portage/mv sync-type: git sync-uri: https://github.com/gentoo-mirror/mv.git masters: gentoo sorrow location: /usr/portage/sorrow sync-type: git sync-uri: https://github.com/gentoo-mirror/sorrow.git masters: gentoo Installed sets: @fcitx5 ACCEPT_KEYWORDS="amd64 ~amd64" ACCEPT_LICENSE="@FREE @BINARY-REDISTRIBUTABLE" CBUILD="x86_64-gentoo-linux-musl" CC="clang" CFLAGS="-march=skylake -mtune=skylake -O3 -pipe -falign-functions=32 -fomit-frame-pointer -ffunction-sections -fdata-sections -flto=thin" CHOST="x86_64-gentoo-linux-musl" CONFIG_PROTECT="/etc /usr/share/config /usr/share/gnupg/qualified.txt" CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo" CXX="clang++" CXXFLAGS="-march=skylake -mtune=skylake -O3 -pipe -falign-functions=32 -fomit-frame-pointer -ffunction-sections -fdata-sections -flto=thin -stdlib=libc++" DISTDIR="/var/cache/distfiles" ENV_UNSET="DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR" FCFLAGS="-O2 -pipe" FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs buildpkg ccache config-protect-if-modified distlocks downgrade-backup ebuild-locks fixlafiles ipc-sandbox merge-sync network-sandbox news parallel-fetch pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr" FFLAGS="-O2 -pipe" GENTOO_MIRRORS="https://mirrors.tuna.tsinghua.edu.cn/gentoo" INSTALL_MASK="charset.alias locale.alias" LANG="zh_CN.UTF-8" LC_ALL="zh_CN.UTF-8" LDFLAGS="-fuse-ld=lld -rtlib=compiler-rt -unwindlib=libunwind -flto=thin -Wl,-O3 -Wl,--gc-sections -march=skylake -mtune=skylake" MAKEOPTS="-j20" PKGDIR="/var/cache/binpkgs" PORTAGE_CONFIGROOT="/" PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git" PORTAGE_TMPDIR="/var/tmp" USE="X acl alsa amd64 bzip2 clang cli compiler-rt crypt default-compiler-rt default-libcxx dri elogind fortran gif iconv ipv6 jpeg libcxx libcxxabi libtirpc libunwind ncurses nls nptl opengl openmp pam pcre png readline seccomp split-usr ssl svg tcpd unicode vaapi vulkan wayland xattr zlib zsh-completion" ABI_X86="64" ADA_TARGET="gnat_2018" ALSA_CARDS="hda-intel usb-audio" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3" ELIBC="musl" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="libinput" KERNEL="linux" L10N="zh-CN" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LLVM_TARGETS="X86 ARM AArch64 RISCV WebAssembly" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-4" POSTGRES_TARGETS="postgres10 postgres11" PYTHON_SINGLE_TARGET="python3_8" PYTHON_TARGETS="python3_8" QEMU_SOFTMMU_TARGETS="arm aarch64 i386 x86_64 riscv32 riscv64" QEMU_USER_TARGETS="arm aarch64" RUBY_TARGETS="ruby27" USERLAND="GNU" VIDEO_CARDS="intel i965 iris" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account" Unset: CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, LINGUAS, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Ran into a similar issue where ALLOW_RULE(statx) was needed as well as for writev. Discovered on MIPS big-endian chroot again sys-libs/musl-1.2.0-r1. Will attach a patch for file-5.39-r2 that can go into the musl overlay to resolve this until changes are sent upstream.
Created attachment 649898 [details, diff] Patch for file-5.39 to add ALLOW_RULE entries for 'statx' and 'writev'
https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=728f8c43b8b540f37871be3080ac63c05a9cf6a7 commit 728f8c43b8b540f37871be3080ac63c05a9cf6a7 Author: Mike Gilbert <floppym@gentoo.org> Date: Mon Sep 7 12:55:11 2020 -0400 sys-apps/file: backport a seccomp fix for musl Closes: https://bugs.gentoo.org/728978 Signed-off-by: Mike Gilbert <floppym@gentoo.org> sys-apps/file/file-5.39-r1.ebuild | 140 --------------------- .../{file-5.39-r2.ebuild => file-5.39-r3.ebuild} | 5 +- sys-apps/file/file-5.39.ebuild | 140 --------------------- .../file/files/file-5.39-add-missing-termios.patch | 35 +++--- ...ndbox.patch => file-5.39-portage-sandbox.patch} | 18 ++- sys-apps/file/files/file-5.39-seccomp-musl.patch | 37 ++++++ .../file/files/file-5.39-seccomp_sandbox.patch | 13 -- 7 files changed, 67 insertions(+), 321 deletions(-)