From: Paul Floyd Date: Tue, 26 Aug 2025 11:32:07 +0000 (+0200) Subject: Bug 508638 - Self-hosting not working on FreeBSD X-Git-Tag: VALGRIND_3_26_0~195 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=17978c5520903586aa069bd5e5fde9105658c953;p=thirdparty%2Fvalgrind.git Bug 508638 - Self-hosting not working on FreeBSD --- diff --git a/NEWS b/NEWS index 853ba47d2..66912d73b 100644 --- a/NEWS +++ b/NEWS @@ -85,6 +85,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. 508030 Add several missing syscall hooks to ppc64-linux 508093 VALGRIND_CLO_CHANGE does not update vex_control 508154 PRE(sys_fchownat) not handling VKI_AT_FDCWD +508638 Self-hosting not working on FreeBSD To see details of a given bug, visit https://bugs.kde.org/show_bug.cgi?id=XXXXXX diff --git a/coregrind/m_syswrap/syswrap-amd64-freebsd.c b/coregrind/m_syswrap/syswrap-amd64-freebsd.c index 71d1bc8b9..4d3c17848 100644 --- a/coregrind/m_syswrap/syswrap-amd64-freebsd.c +++ b/coregrind/m_syswrap/syswrap-amd64-freebsd.c @@ -983,12 +983,15 @@ POST(sys_procctl) // int mknodat(int fd, const char *path, mode_t mode, dev_t dev); PRE(sys_mknodat) { + Int arg_1 = (Int)ARG1; + const HChar *path = (const HChar*)ARG2; PRINT("sys_mknodat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), 0x%" FMT_REGWORD "x, 0x%" FMT_REGWORD "x )", ARG1,ARG2,(char*)ARG2,ARG3,ARG4 ); PRE_REG_READ4(long, "mknodat", int, fd, const char *, path, vki_mode_t, mode, vki_dev_t, dev); PRE_MEM_RASCIIZ( "mknodat(pathname)", ARG2 ); - if (!ML_(fd_allowed)(ARG1, "mknodat", tid, False)) - SET_STATUS_Failure(VKI_EBADF); + if ((ML_(safe_to_deref) (path, 1)) && (path[0] != '/')) + if ((arg_1 != VKI_AT_FDCWD) && !ML_(fd_allowed)(arg_1, "mknodat", tid, False) ) + SET_STATUS_Failure(VKI_EBADF); } // SYS_cpuset_getdomain 561 diff --git a/coregrind/m_syswrap/syswrap-freebsd.c b/coregrind/m_syswrap/syswrap-freebsd.c index d92a1a46c..7fc96c7c5 100644 --- a/coregrind/m_syswrap/syswrap-freebsd.c +++ b/coregrind/m_syswrap/syswrap-freebsd.c @@ -5332,11 +5332,14 @@ POST(sys_freebsd11_fstatat) // int futimesat(int fd, const char *path, const struct timeval times[2]); PRE(sys_futimesat) { + Int arg_1 = (Int)ARG1; + const HChar *path = (const HChar*)ARG2; PRINT("sys_futimesat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )", ARG1,ARG2,(char*)ARG2,ARG3); PRE_REG_READ3(int, "futimesat", int, fd, const char *, path, struct timeval *, times); - if (!ML_(fd_allowed)(ARG1, "futimesat", tid, False)) - SET_STATUS_Failure(VKI_EBADF); + if ((ML_(safe_to_deref) (path, 1)) && (path[0] != '/')) + if ((arg_1 != VKI_AT_FDCWD) && !ML_(fd_allowed)(arg_1, "futimesat", tid, False) ) + SET_STATUS_Failure(VKI_EBADF); if (ARG2 != 0) { PRE_MEM_RASCIIZ( "futimesat(path)", ARG2 ); } @@ -6189,11 +6192,15 @@ POST(sys_cap_fcntls_get) // int bindat(int fd, int s, const struct sockaddr *addr, socklen_t addrlen); PRE(sys_bindat) { + Int arg_1 = (Int)ARG1; + const HChar *path = (const HChar*)ARG2; PRINT("sys_bindat ( %" FMT_REGWORD "d, %" FMT_REGWORD "dx, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", SARG1, SARG2, ARG3, ARG4); PRE_REG_READ4(int, "bindat", int, fd, int, s, const struct vki_sockaddr *, name, vki_socklen_t, namelen); - if (!ML_(fd_allowed)(ARG1, "bindat", tid, False)) - SET_STATUS_Failure(VKI_EBADF); + if ((ML_(safe_to_deref) (path, 1)) && (path[0] != '/')) + if ((arg_1 != VKI_AT_FDCWD) && !ML_(fd_allowed)(arg_1, "bindat", tid, False) ) + SET_STATUS_Failure(VKI_EBADF); + PRE_MEM_READ("bindat(name)", ARG3, ARG4); } @@ -6201,11 +6208,14 @@ PRE(sys_bindat) // int connectat(int fd, int s, const struct sockaddr *name, socklen_t namelen); PRE(sys_connectat) { + Int arg_1 = (Int)ARG1; + const HChar *path = (const HChar*)ARG2; PRINT("sys_connectat ( %" FMT_REGWORD "d, %" FMT_REGWORD "dx, %#" FMT_REGWORD "x, %" FMT_REGWORD "u )", SARG1, SARG2, ARG3, ARG4); PRE_REG_READ4(int, "connectat", int, fd, int, s, const struct vki_sockaddr *, name, vki_socklen_t, namelen); - if (!ML_(fd_allowed)(ARG1, "connectat", tid, False)) - SET_STATUS_Failure(VKI_EBADF); + if ((ML_(safe_to_deref) (path, 1)) && (path[0] != '/')) + if ((arg_1 != VKI_AT_FDCWD) && !ML_(fd_allowed)(arg_1, "connectat", tid, False) ) + SET_STATUS_Failure(VKI_EBADF); PRE_MEM_READ("connectat(name)", ARG3, ARG4); } @@ -6213,11 +6223,15 @@ PRE(sys_connectat) // int chflagsat(int fd, const char *path, unsigned long flags, int atflag); PRE(sys_chflagsat) { + Int arg_1 = (Int)ARG1; + const HChar *path = (const HChar*)ARG2; PRINT("sys_chglagsat ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "d )", SARG1, ARG2, ARG3, SARG4); PRE_REG_READ4(int, "chflagsat", int, fd, const char *, path, unsigned long, flags, int, atflag); - if (!ML_(fd_allowed)(ARG1, "chflagsat", tid, False)) - SET_STATUS_Failure(VKI_EBADF); + if ((ML_(safe_to_deref) (path, 1)) && (path[0] != '/')) + if ((arg_1 != VKI_AT_FDCWD) && !ML_(fd_allowed)(arg_1, "chflagsat", tid, False) ) + SET_STATUS_Failure(VKI_EBADF); + PRE_MEM_RASCIIZ("chflagsat(path)", ARG2); }