From: Martin Cermak Date: Tue, 5 Aug 2025 14:54:54 +0000 (+0200) Subject: The futimesat syscall wrapper doesn't handle AT_FDCWD X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=bdbce5686e4204d678814fa861d153c5bc5252f8;p=thirdparty%2Fvalgrind.git The futimesat syscall wrapper doesn't handle AT_FDCWD Update futimesat syscall wrapper so that it doesn't consider the special value AT_FDCWD (-100) an invalid file descriptor. https://bugs.kde.org/show_bug.cgi?id=507868 --- diff --git a/NEWS b/NEWS index 6b21446ec..a38078277 100644 --- a/NEWS +++ b/NEWS @@ -68,6 +68,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. 506967 Implement and override mallinfo2 506970 mmap needs an EBADF fd_allowed check 507173 s390x: Crash when constant folding is disabled +507868 futimesat doesn't handle AT_FDCWD 507873 Make fchmodat and fchmodat2 syscall wrappers accept AT_FDCWD 507897 Allow for patching LTP sources diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index 96d22e6f4..1033d2409 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -6213,16 +6213,23 @@ PRE(sys_fchownat) PRE(sys_futimesat) { FUSE_COMPATIBLE_MAY_BLOCK(); - PRINT("sys_futimesat ( %ld, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )", - SARG1, ARG2, (HChar*)(Addr)ARG2, ARG3); + Int arg_1 = (Int)ARG1; + const HChar *path = (const HChar*) ARG2; + PRINT("sys_futimesat ( %d, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )", + arg_1, ARG2, path, ARG3); PRE_REG_READ3(long, "futimesat", int, dfd, char *, filename, struct timeval *, tvp); if (ARG2 != 0) PRE_MEM_RASCIIZ( "futimesat(filename)", ARG2 ); if (ARG3 != 0) PRE_MEM_READ( "futimesat(tvp)", ARG3, 2 * sizeof(struct vki_timeval) ); - if ( !ML_(fd_allowed)(SARG1, "futimesat", tid, False) ) - SET_STATUS_Failure( VKI_EBADF ); + if (ML_(safe_to_deref) (path, 1)) { + /* If pathname is relative and dirfd is the special value AT_FDCWD, then pathname is interpreted ... */ + if (path[0] != '/') + if ( arg_1 != VKI_AT_FDCWD && !ML_(fd_allowed)(arg_1, "futimesat", tid, False) ) + SET_STATUS_Failure( VKI_EBADF ); + /* If pathname is absolute, then dirfd is ignored. */ + } }