]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Bug 506910 - openat2 with RESOLVE_NO_MAGICLINKS succeeds on /proc/self/exe
authorPaul Floyd <pjfloyd@wanadoo.fr>
Sat, 19 Jul 2025 16:17:35 +0000 (18:17 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Sat, 19 Jul 2025 16:17:35 +0000 (18:17 +0200)
Previous change did most of the work but need to return without setting
SfMayBlock. Add a testcase covering /proc/self/exe and /proc/PID/exe.

.gitignore
NEWS
coregrind/m_syswrap/syswrap-generic.c
coregrind/m_syswrap/syswrap-linux.c
none/tests/linux/Makefile.am
none/tests/linux/bug506910.cpp [new file with mode: 0644]
none/tests/linux/bug506910.stderr.exp [new file with mode: 0644]
none/tests/linux/bug506910.vgtest [new file with mode: 0644]

index 44454d08bb32e02de2daabe52f378a779a31595f..0da54a7ebf8d1116bb9ca8faa536aa55056cece4 100644 (file)
 /none/tests/linux/brk-overflow1
 /none/tests/linux/brk-overflow2
 /none/tests/linux/bug498317
+/none/tests/linux/bug506910
 /none/tests/linux/clonev
 /none/tests/linux/Makefile
 /none/tests/linux/Makefile.in
diff --git a/NEWS b/NEWS
index af88103641ab2cb2fae01982ba6ec1b43b788c26..29e2274eaebfb1e68d2df0850a1491d0f9022872 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -58,6 +58,7 @@ are not entered into bugzilla tend to get forgotten about or ignored.
 506499  Unhandled syscall 592 (exterrctl - FreeBSD
 506795  Better report which clone flags are problematic
 506928  Wrap (deprecated) linux specific ustat syscall
+506910  openat2 with RESOLVE_NO_MAGICLINKS succeeds on /proc/self/exe
 506930  valgrind allows SIGKILL being reset to SIG_DFL
 506970  mmap needs an EBADF fd_allowed check
 
index 727766869ff57491881bf88795a0a0f7876c67c3..280b1ccb6aac36421ecf21645a4ab73337f0348b 100644 (file)
@@ -4693,6 +4693,7 @@ PRE(sys_open)
    if (proc_self_exe) {
       // do the syscall with VG_(resolved_exename)
       SET_STATUS_from_SysRes(VG_(do_syscall3)(SYSNO, (Word)VG_(resolved_exename), ARG2, ARG3));
+      return;
    }
 #endif // defined(VGO_linux)
 
index e16d293cd08f09a6c52172cf064a8cb71dc2461a..d1cfdad69addf70e8f1724547c38935eaedbcfc2 100644 (file)
@@ -6095,6 +6095,7 @@ no_client_write:
 
       // do the syscall with VG_(resolved_exename)
       SET_STATUS_from_SysRes(VG_(do_syscall4)(SYSNO, ARG1, (Word)VG_(resolved_exename), ARG3, ARG4));
+      return;
    }
 
    /* Otherwise handle normally */
@@ -14093,9 +14094,9 @@ PRE(sys_openat2)
    }
 
    if (proc_self_exe) {
-
       // do the syscall with VG_(resolved_exename)
       SET_STATUS_from_SysRes(VG_(do_syscall4)(SYSNO, ARG1, (Word)VG_(resolved_exename), ARG3, ARG4));
+      return;
    }
 
    /* Otherwise handle normally */
index c81ffff5488507e21db8230497f9b25e7c044000..c20b2d2d01892fd09488167977ffe169d57d8d08 100644 (file)
@@ -8,6 +8,7 @@ EXTRA_DIST = \
        brk-overflow1.stderr.exp brk-overflow1.vgtest \
        brk-overflow2.stderr.exp brk-overflow2.vgtest \
        bug498317.stderr.exp bug498317.supp bug498317.vgtest \
+       bug506910.stderr.exp bug506910.vgtest \
        clonev.stdout.exp clonev.stderr.exp clonev.vgtest \
         membarrier.stderr.exp membarrier.vgtest \
        mremap.stderr.exp mremap.stderr.exp-glibc27 mremap.stdout.exp \
@@ -26,6 +27,7 @@ check_PROGRAMS = \
        brk-overflow1 \
        brk-overflow2 \
        bug498317 \
+       bug506910 \
        clonev \
        mremap \
        mremap2 \
@@ -46,6 +48,7 @@ AM_CFLAGS   += $(AM_FLAG_M3264_PRI)
 AM_CXXFLAGS += $(AM_FLAG_M3264_PRI)
 
 # Special needs
+bug506910_SOURCES = bug506910.cpp
 clonev_LDADD = -lpthread
 open_client_SOURCES = open_client.cpp
 pthread_stack_LDADD = -lpthread
diff --git a/none/tests/linux/bug506910.cpp b/none/tests/linux/bug506910.cpp
new file mode 100644 (file)
index 0000000..2dbadf5
--- /dev/null
@@ -0,0 +1,44 @@
+// For Bug 5056910
+// openat2 with RESOLVE_NO_MAGICLINKS succeeds on /proc/self/exe
+#include <fcntl.h>
+#include <cerrno>
+#include <stdexcept>
+#include <string>
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <linux/openat2.h>
+
+int main(int argc, char** argv)
+{
+    auto pid = getpid();
+    auto ppe = std::string("/proc/") + std::to_string(pid) + "/exe";
+#if defined(SYS_openat2)
+   struct open_how oh = { .flags=O_RDONLY, .mode=0UL, .resolve=RESOLVE_NO_MAGICLINKS };
+   int res = syscall(SYS_openat2, AT_FDCWD, "/proc/self/exe", &oh, sizeof(oh));
+   if (-1 != res)
+   {
+      throw std::runtime_error("openat2 should have failed");
+   }
+   else
+   {
+      if (errno != ELOOP)
+      {
+         throw std::runtime_error("errno should be ELOOP");
+      }
+   }
+
+   res = syscall(SYS_openat2, AT_FDCWD, ppe.c_str(), &oh, sizeof(oh));
+   if (-1 != res)
+   {
+       throw std::runtime_error("openat2 should have failed");
+   }
+   else
+   {
+       if (errno != ELOOP)
+       {
+           throw std::runtime_error("errno should be ELOOP");
+       }
+   }
+#endif
+}
diff --git a/none/tests/linux/bug506910.stderr.exp b/none/tests/linux/bug506910.stderr.exp
new file mode 100644 (file)
index 0000000..139597f
--- /dev/null
@@ -0,0 +1,2 @@
+
+
diff --git a/none/tests/linux/bug506910.vgtest b/none/tests/linux/bug506910.vgtest
new file mode 100644 (file)
index 0000000..28e3f29
--- /dev/null
@@ -0,0 +1 @@
+prog: bug506910