Skip to content

Commit 7d2c363

Browse files
Fix statx not being allowed on rpath/wpath pledges (#1291)
While always blocking statx did not lead to particularly bad results for most cases (most code that uses statx appears to utilize a fallback when statx is unavailable), it does lead to using usually far less used (thus far less well tested) code: for example, musl's current fstatat fallback for statx fails to set any values for stx_rdev_major and stx_rdev_minor, which the raw syscall wouldn't (I've have sent a patch to musl for this, but this won't fix older versions of musl and binaries/OSes using them). Along with the fact that statx extends stat in several useful ways, this seems to indicate it is far better to simply allow statx whenever pledge also allows stat-family syscalls, i.e. for both rpath and wpath pledges.
1 parent 462ba69 commit 7d2c363

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

libc/calls/pledge-linux.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ static const uint16_t kPledgeRpath[] = {
712712
#endif //
713713
__NR_linux_fstat, //
714714
__NR_linux_fstatat, //
715+
__NR_linux_statx, //
715716
#ifdef __NR_linux_access //
716717
__NR_linux_access, //
717718
#endif //
@@ -739,6 +740,7 @@ static const uint16_t kPledgeWpath[] = {
739740
__NR_linux_lstat, //
740741
#endif //
741742
__NR_linux_fstatat, //
743+
__NR_linux_statx, //
742744
#ifdef __NR_linux_access //
743745
__NR_linux_access, //
744746
#endif //
@@ -1005,16 +1007,15 @@ static const struct sock_filter kPledgeStart[] = {
10051007
BPF_STMT(BPF_LD | BPF_W | BPF_ABS, OFF(nr)),
10061008
#ifdef __NR_linux_memfd_secret
10071009
// forbid some system calls with ENOSYS (rather than EPERM)
1008-
BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, __NR_linux_memfd_secret, 5, 0),
1010+
BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, __NR_linux_memfd_secret, 4, 0),
10091011
#else
10101012
BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, __NR_linux_landlock_restrict_self + 1,
1011-
5, 0),
1013+
4, 0),
10121014
#endif
1013-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_linux_rseq, 4, 0),
1014-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_linux_memfd_create, 3, 0),
1015-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_linux_openat2, 2, 0),
1016-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_linux_clone3, 1, 0),
1017-
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_linux_statx, 0, 1),
1015+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_linux_rseq, 3, 0),
1016+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_linux_memfd_create, 2, 0),
1017+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_linux_openat2, 1, 0),
1018+
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_linux_clone3, 0, 1),
10181019
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ERRNO | (Enosys & SECCOMP_RET_DATA)),
10191020
};
10201021

0 commit comments

Comments
 (0)