From: Earl Chew Date: Fri, 14 Apr 2023 20:56:16 +0000 (+0200) Subject: Support Linux syscall 434 pidfd_open X-Git-Tag: VALGRIND_3_21_0~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d387566dd7dbb2ebe6fea5bfb4b2353bd5ab86ba;p=thirdparty%2Fvalgrind.git Support Linux syscall 434 pidfd_open --- diff --git a/NEWS b/NEWS index 68acfff7cf..b8d5e333d7 100644 --- a/NEWS +++ b/NEWS @@ -140,6 +140,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. 462830 WARNING: unhandled amd64-freebsd syscall: 474 463027 broken check for MPX instruction support in assembler 464476 Firefox fails to start under Valgrind +464609 Valgrind memcheck should support Linux pidfd_open 464680 Show issues caused by memory policies like selinux deny_execmem 464859 Build failures with GCC-13 (drd tsan_unittest) 464969 D language demangling diff --git a/coregrind/m_syswrap/priv_syswrap-linux.h b/coregrind/m_syswrap/priv_syswrap-linux.h index 4f85069476..a73b6247e7 100644 --- a/coregrind/m_syswrap/priv_syswrap-linux.h +++ b/coregrind/m_syswrap/priv_syswrap-linux.h @@ -320,6 +320,9 @@ DECL_TEMPLATE(linux, sys_io_uring_setup); DECL_TEMPLATE(linux, sys_io_uring_enter); DECL_TEMPLATE(linux, sys_io_uring_register); +// Linux-specific (new in Linux 5.3) +DECL_TEMPLATE(linux, sys_pidfd_open); + // Linux-specific (new in Linux 5.9) DECL_TEMPLATE(linux, sys_close_range); DECL_TEMPLATE(linux, sys_openat2); diff --git a/coregrind/m_syswrap/syswrap-amd64-linux.c b/coregrind/m_syswrap/syswrap-amd64-linux.c index 9054199857..1aeebd274b 100644 --- a/coregrind/m_syswrap/syswrap-amd64-linux.c +++ b/coregrind/m_syswrap/syswrap-amd64-linux.c @@ -876,6 +876,7 @@ static SyscallTableEntry syscall_table[] = { LINXY(__NR_io_uring_enter, sys_io_uring_enter), // 426 LINXY(__NR_io_uring_register, sys_io_uring_register), // 427 + LINXY(__NR_pidfd_open, sys_pidfd_open), // 434 GENX_(__NR_clone3, sys_ni_syscall), // 435 LINXY(__NR_close_range, sys_close_range), // 436 LINXY(__NR_openat2, sys_openat2), // 437 diff --git a/coregrind/m_syswrap/syswrap-arm-linux.c b/coregrind/m_syswrap/syswrap-arm-linux.c index d583cef0c7..8b1a8fe702 100644 --- a/coregrind/m_syswrap/syswrap-arm-linux.c +++ b/coregrind/m_syswrap/syswrap-arm-linux.c @@ -1052,6 +1052,7 @@ static SyscallTableEntry syscall_main_table[] = { LINXY(__NR_io_uring_enter, sys_io_uring_enter), // 426 LINXY(__NR_io_uring_register, sys_io_uring_register), // 427 + LINXY(__NR_pidfd_open, sys_pidfd_open), // 434 GENX_(__NR_clone3, sys_ni_syscall), // 435 LINXY(__NR_close_range, sys_close_range), // 436 diff --git a/coregrind/m_syswrap/syswrap-arm64-linux.c b/coregrind/m_syswrap/syswrap-arm64-linux.c index 3ed71e143b..9532360007 100644 --- a/coregrind/m_syswrap/syswrap-arm64-linux.c +++ b/coregrind/m_syswrap/syswrap-arm64-linux.c @@ -831,6 +831,7 @@ static SyscallTableEntry syscall_main_table[] = { LINXY(__NR_io_uring_enter, sys_io_uring_enter), // 426 LINXY(__NR_io_uring_register, sys_io_uring_register), // 427 + LINXY(__NR_pidfd_open, sys_pidfd_open), // 434 GENX_(__NR_clone3, sys_ni_syscall), // 435 LINXY(__NR_close_range, sys_close_range), // 436 diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index 34d4cf1f55..26f1fbee3c 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -13605,6 +13605,22 @@ POST(sys_openat2) } } +PRE(sys_pidfd_open) +{ + PRINT("sys_pidfd_open ( %ld, %lu )", SARG1, ARG2); +} + +POST(sys_pidfd_open) +{ + if (!ML_(fd_allowed)(RES, "pidfd", tid, True)) { + VG_(close)(RES); + SET_STATUS_Failure( VKI_EMFILE ); + } else { + if (VG_(clo_track_fds)) + ML_(record_fd_open_nameless) (tid, RES); + } +} + #undef PRE #undef POST diff --git a/coregrind/m_syswrap/syswrap-mips32-linux.c b/coregrind/m_syswrap/syswrap-mips32-linux.c index f556e063f0..de27998b3f 100644 --- a/coregrind/m_syswrap/syswrap-mips32-linux.c +++ b/coregrind/m_syswrap/syswrap-mips32-linux.c @@ -1136,6 +1136,7 @@ static SyscallTableEntry syscall_main_table[] = { LINXY(__NR_io_uring_enter, sys_io_uring_enter), // 426 LINXY(__NR_io_uring_register, sys_io_uring_register), // 427 + LINXY(__NR_pidfd_open, sys_pidfd_open), // 434 GENX_(__NR_clone3, sys_ni_syscall), // 435 LINXY(__NR_close_range, sys_close_range), // 436 diff --git a/coregrind/m_syswrap/syswrap-mips64-linux.c b/coregrind/m_syswrap/syswrap-mips64-linux.c index 41a5404c55..67e7c2c2f6 100644 --- a/coregrind/m_syswrap/syswrap-mips64-linux.c +++ b/coregrind/m_syswrap/syswrap-mips64-linux.c @@ -815,6 +815,7 @@ static SyscallTableEntry syscall_main_table[] = { LINXY (__NR_io_uring_setup, sys_io_uring_setup), LINXY (__NR_io_uring_enter, sys_io_uring_enter), LINXY (__NR_io_uring_register, sys_io_uring_register), + LINXY (__NR_pidfd_open, sys_pidfd_open), GENX_ (__NR_clone3, sys_ni_syscall), LINXY (__NR_close_range, sys_close_range), LINX_ (__NR_faccessat2, sys_faccessat2), diff --git a/coregrind/m_syswrap/syswrap-nanomips-linux.c b/coregrind/m_syswrap/syswrap-nanomips-linux.c index f9d4b19f4a..9c535c68ea 100644 --- a/coregrind/m_syswrap/syswrap-nanomips-linux.c +++ b/coregrind/m_syswrap/syswrap-nanomips-linux.c @@ -824,6 +824,7 @@ static SyscallTableEntry syscall_main_table[] = { LINXY (__NR_io_uring_setup, sys_io_uring_setup), LINXY (__NR_io_uring_enter, sys_io_uring_enter), LINXY (__NR_io_uring_register, sys_io_uring_register), + LINXY (__NR_pidfd_open, sys_pidfd_open), GENX_ (__NR_clone3, sys_ni_syscall), LINXY (__NR_close_range, sys_close_range), LINX_ (__NR_faccessat2, sys_faccessat2), diff --git a/coregrind/m_syswrap/syswrap-ppc32-linux.c b/coregrind/m_syswrap/syswrap-ppc32-linux.c index 637b2504e1..12c0730271 100644 --- a/coregrind/m_syswrap/syswrap-ppc32-linux.c +++ b/coregrind/m_syswrap/syswrap-ppc32-linux.c @@ -1056,6 +1056,7 @@ static SyscallTableEntry syscall_table[] = { LINXY(__NR_io_uring_enter, sys_io_uring_enter), // 426 LINXY(__NR_io_uring_register, sys_io_uring_register), // 427 + LINXY(__NR_pidfd_open, sys_pidfd_open), // 434 GENX_(__NR_clone3, sys_ni_syscall), // 435 LINXY(__NR_close_range, sys_close_range), // 436 diff --git a/coregrind/m_syswrap/syswrap-ppc64-linux.c b/coregrind/m_syswrap/syswrap-ppc64-linux.c index 93956d3cc2..3c33d1267e 100644 --- a/coregrind/m_syswrap/syswrap-ppc64-linux.c +++ b/coregrind/m_syswrap/syswrap-ppc64-linux.c @@ -1025,6 +1025,7 @@ static SyscallTableEntry syscall_table[] = { LINXY(__NR_io_uring_enter, sys_io_uring_enter), // 426 LINXY(__NR_io_uring_register, sys_io_uring_register), // 427 + LINXY(__NR_pidfd_open, sys_pidfd_open), // 434 GENX_(__NR_clone3, sys_ni_syscall), // 435 LINXY(__NR_close_range, sys_close_range), // 436 diff --git a/coregrind/m_syswrap/syswrap-s390x-linux.c b/coregrind/m_syswrap/syswrap-s390x-linux.c index 73f9684c46..a377cb7315 100644 --- a/coregrind/m_syswrap/syswrap-s390x-linux.c +++ b/coregrind/m_syswrap/syswrap-s390x-linux.c @@ -866,6 +866,7 @@ static SyscallTableEntry syscall_table[] = { LINXY(__NR_io_uring_enter, sys_io_uring_enter), // 426 LINXY(__NR_io_uring_register, sys_io_uring_register), // 427 + LINXY(__NR_pidfd_open, sys_pidfd_open), // 434 GENX_(__NR_clone3, sys_ni_syscall), // 435 LINXY(__NR_close_range, sys_close_range), // 436 diff --git a/coregrind/m_syswrap/syswrap-x86-linux.c b/coregrind/m_syswrap/syswrap-x86-linux.c index 5968d49dbf..a9ba15dfe6 100644 --- a/coregrind/m_syswrap/syswrap-x86-linux.c +++ b/coregrind/m_syswrap/syswrap-x86-linux.c @@ -1647,6 +1647,7 @@ static SyscallTableEntry syscall_table[] = { LINXY(__NR_io_uring_enter, sys_io_uring_enter), // 426 LINXY(__NR_io_uring_register, sys_io_uring_register),// 427 + LINXY(__NR_pidfd_open, sys_pidfd_open), // 434 GENX_(__NR_clone3, sys_ni_syscall), // 435 LINXY(__NR_close_range, sys_close_range), // 436 LINXY(__NR_openat2, sys_openat2), // 437 diff --git a/include/vki/vki-scnums-shared-linux.h b/include/vki/vki-scnums-shared-linux.h index 048460d0b2..d90cdd3124 100644 --- a/include/vki/vki-scnums-shared-linux.h +++ b/include/vki/vki-scnums-shared-linux.h @@ -39,6 +39,7 @@ #define __NR_fsmount 432 #define __NR_fspick 433 +#define __NR_pidfd_open 434 #define __NR_clone3 435 #define __NR_close_range 436 #define __NR_openat2 437