From: Paul Floyd Date: Mon, 20 Nov 2023 11:59:12 +0000 (+0100) Subject: Bug 390269 - unhandled amd64-darwin syscall: unix:464 (openat_nocancel) X-Git-Tag: VALGRIND_3_23_0~255 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d79897e0aff3f5f3cf3e77760761ace3bb847d0f;p=thirdparty%2Fvalgrind.git Bug 390269 - unhandled amd64-darwin syscall: unix:464 (openat_nocancel) Copied from https://github.com/LouisBrunner/valgrind-macos.git Regtest to come shortly --- diff --git a/NEWS b/NEWS index 1bfdd52615..223d7233cb 100644 --- a/NEWS +++ b/NEWS @@ -24,6 +24,7 @@ than mailing the developers (or mailing lists) directly -- bugs that are not entered into bugzilla tend to get forgotten about or ignored. +390269 unhandled amd64-darwin syscall: unix:464 (openat_nocancel) 401284 False positive "Source and destination overlap in strncat" 428364 Signals inside io_uring_enter not handled 437790 valgrind reports "Conditional jump or move depends on uninitialised diff --git a/coregrind/m_syswrap/priv_syswrap-darwin.h b/coregrind/m_syswrap/priv_syswrap-darwin.h index f31cde0c41..cb31fb51b1 100644 --- a/coregrind/m_syswrap/priv_syswrap-darwin.h +++ b/coregrind/m_syswrap/priv_syswrap-darwin.h @@ -572,8 +572,10 @@ DECL_TEMPLATE(darwin, getattrlistbulk); // 461 // NYI clonefileat // 462 #endif /* DARWIN_VERS >= DARWIN_10_12 */ #if DARWIN_VERS >= DARWIN_10_10 -// NYI openat // 463 -// NYI openat_nocancel // 464 +DECL_TEMPLATE(darwin, openat); // 463 +#if DARWIN_VERS >= DARWIN_10_13 +DECL_TEMPLATE(darwin, openat_nocancel); // 464 +#endif // NYI renameat // 465 DECL_TEMPLATE(darwin, faccessat); // 466 // NYI fchmodat // 467 diff --git a/coregrind/m_syswrap/syswrap-darwin.c b/coregrind/m_syswrap/syswrap-darwin.c index cc7ee3e70e..d8e88ccb81 100644 --- a/coregrind/m_syswrap/syswrap-darwin.c +++ b/coregrind/m_syswrap/syswrap-darwin.c @@ -9836,6 +9836,48 @@ PRE(guarded_writev_np) ARG1, ARG2, ARG3, (ULong)ARG4); } +PRE(openat) +{ + if (ARG3 & VKI_O_CREAT) { + // 4-arg version + PRINT("sys_openat ( %ld, %#" FMT_REGWORD "x(%s), %ld, %ld )", + SARG1, ARG2, (HChar*)(Addr)ARG2, SARG3, SARG4); + PRE_REG_READ4(long, "openat", + int, dfd, const char *, filename, int, flags, int, mode); + } else { + // 3-arg version + PRINT("sys_openat ( %ld, %#" FMT_REGWORD "x(%s), %ld )", + SARG1, ARG2, (HChar*)(Addr)ARG2, SARG3); + PRE_REG_READ3(long, "openat", + int, dfd, const char *, filename, int, flags); + } + PRE_MEM_RASCIIZ( "openat(filename)", ARG2 ); + + /* For absolute filenames, dfd is ignored. If dfd is AT_FDCWD, + filename is relative to cwd. When comparing dfd against AT_FDCWD, + be sure only to compare the bottom 32 bits. */ + if (ML_(safe_to_deref)( (void*)(Addr)ARG2, 1 ) + && *(Char *)(Addr)ARG2 != '/' + && ((Int)ARG1) != ((Int)VKI_AT_FDCWD) + && !ML_(fd_allowed)(ARG1, "openat", tid, False)) + SET_STATUS_Failure( VKI_EBADF ); + + /* Otherwise handle normally */ + *flags |= SfMayBlock; +} + +POST(openat) +{ + vg_assert(SUCCESS); + if (!ML_(fd_allowed)(RES, "openat", tid, True)) { + VG_(close)(RES); + SET_STATUS_Failure( VKI_EMFILE ); + } else { + if (VG_(clo_track_fds)) + ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)(Addr)ARG2); + } +} + #endif /* DARWIN_VERS >= DARWIN_10_10 */ @@ -10071,6 +10113,54 @@ POST(mach_generate_activity_id) #endif /* DARWIN_VERS >= DARWIN_10_12 */ +/* --------------------------------------------------------------------- + Added for macOS 10.13 (High Sierra) + ------------------------------------------------------------------ */ + +#if DARWIN_VERS >= DARWIN_10_13 + +PRE(openat_nocancel) +{ + if (ARG3 & VKI_O_CREAT) { + // 4-arg version + PRINT("openat_nocancel ( %ld, %#" FMT_REGWORD "x(%s), %ld, %ld )", + SARG1, ARG2, (HChar*)(Addr)ARG2, SARG3, SARG4); + PRE_REG_READ4(long, "openat_nocancel", + int, dfd, const char *, filename, int, flags, int, mode); + } else { + // 3-arg version + PRINT("openat_nocancel ( %ld, %#" FMT_REGWORD "x(%s), %ld )", + SARG1, ARG2, (HChar*)(Addr)ARG2, SARG3); + PRE_REG_READ3(long, "openat_nocancel", + int, dfd, const char *, filename, int, flags); + } + PRE_MEM_RASCIIZ( "openat_nocancel(filename)", ARG2 ); + + /* For absolute filenames, dfd is ignored. If dfd is AT_FDCWD, + filename is relative to cwd. When comparing dfd against AT_FDCWD, + be sure only to compare the bottom 32 bits. */ + if (ML_(safe_to_deref)( (void*)(Addr)ARG2, 1 ) + && *(Char *)(Addr)ARG2 != '/' + && ((Int)ARG1) != ((Int)VKI_AT_FDCWD) + && !ML_(fd_allowed)(ARG1, "openat", tid, False)) + SET_STATUS_Failure( VKI_EBADF ); + + /* Otherwise handle normally */ + *flags |= SfMayBlock; +} +POST(openat_nocancel) +{ + vg_assert(SUCCESS); + if (!ML_(fd_allowed)(RES, "openat_nocancel", tid, True)) { + VG_(close)(RES); + SET_STATUS_Failure( VKI_EMFILE ); + } else { + if (VG_(clo_track_fds)) + ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)(Addr)ARG2); + } +} + +#endif /* DARWIN_VERS >= DARWIN_10_13 */ /* --------------------------------------------------------------------- syscall tables diff --git a/include/vki/vki-scnums-darwin.h b/include/vki/vki-scnums-darwin.h index 7fa442a39c..7af0465c54 100644 --- a/include/vki/vki-scnums-darwin.h +++ b/include/vki/vki-scnums-darwin.h @@ -771,6 +771,10 @@ #endif /* DARWIN_VERS >= DARWIN_10_12 */ #if DARWIN_VERS >= DARWIN_10_10 +#define __NR_openat VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(463) +#if DARWIN_VERS >= DARWIN_10_13 +#define __NR_openat_nocancel VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(464) +#endif #define __NR_faccessat VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(466) #define __NR_fstatat64 VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(470) #define __NR_readlinkat VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(473)