]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Disable linux madvise MADV_GUARD_INSTALL
authorMark Wielaard <mark@klomp.org>
Wed, 7 Jan 2026 21:20:49 +0000 (22:20 +0100)
committerMark Wielaard <mark@klomp.org>
Wed, 7 Jan 2026 21:20:49 +0000 (22:20 +0100)
glibc 2.42+ (with linux 6.13+) uses MADV_GUARD_INSTALL to setup stack
guard pages. valgrind currently isn't able to track this and such
guard pages also don't show up in /proc maps (only in /proc pagemap
since linux 6.14). For now valgrind fails a madvise MADV_GUARD_INSTALL
syscall with EINVAL. This causes glibc to fall back to mprotect
PROT_NONE which valgrind is able to track.

https://bugs.kde.org/show_bug.cgi?id=511717

NEWS
coregrind/m_syswrap/syswrap-generic.c
include/vki/vki-linux.h

diff --git a/NEWS b/NEWS
index 1da711b2698d7001435c3f63a45527e785a3a34f..d5188f7c68715e175baa29c54c16e768ab6e03b7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,7 +8,17 @@ X86/Android, X86/Solaris, AMD64/Solaris, X86/macOS, AMD64/macOS.
 X86/FreeBSD, AMD64/FreeBSD and ARM64/FreeBSD. There is preliminary support
 for nanoMIPS/Linux. macOS is supported up to version 12 Monterey (amd64 only).
 
- ==================== CORE CHANGES ===================
+* ==================== CORE CHANGES ===================
+
+* linux madvise MADV_GUARD_INSTALL unsupported
+
+  glibc 2.42+ (with linux 6.13+) uses MADV_GUARD_INSTALL to setup
+  stack guard pages. valgrind currently isn't able to track this and
+  such guard pages also don't show up in /proc maps (only in /proc
+  pagemap since linux 6.14). For now valgrind fails a madvise
+  MADV_GUARD_INSTALL syscall with EINVAL. This causes glibc to fall
+  back to mprotect PROT_NONE which valgrind is able to track.
+  See also https://bugs.kde.org/show_bug.cgi?id=514297
 
 * ================== PLATFORM CHANGES =================
 
@@ -45,6 +55,8 @@ are not entered into bugzilla tend to get forgotten about or ignored.
 511329  Darwin and FreeBSD: Move setting of carry flag out of
         ML_(do_syscall_for_client_WRK)
 511713  Refactor syscall argument handling
+511717  gdbserver (valgrind_read_memory) the 'impossible' happened:
+        Killed by fatal signal (SIGSEGV)
 511972  valgrind-3.26.0 tests fail to build on upcomig gcc-16:
         unrecognized command-line option
         '-Wno-alloc-size-larger-than=18446744073709551615'
index aa4a0caf11f9bece83ee658aecebbdcb97241e2a..d8910fdbaf944ff8e9e02632524691e546f7fe9d 100644 (file)
@@ -3112,6 +3112,16 @@ PRE(sys_madvise)
                         ARG1, ARG2, SARG3);
    PRE_REG_READ3(long, "madvise",
                  unsigned long, start, vki_size_t, length, int, advice);
+   /* Ugly hack to try to bypass the problem of guard pages not being
+      understood by valgrind aspace manager.
+      By making the syscall fail, we expect glibc to fallback
+      on implementing guard pages with mprotect PROT_NONE to ensure
+      the valgrind address space manager is not confused wrongly
+      believing the guard page is rw. */
+#ifdef VKI_MADV_GUARD_INSTALL
+   if (ARG3 == VKI_MADV_GUARD_INSTALL)
+      SET_STATUS_Failure( VKI_EINVAL );
+#endif
 }
 
 #if HAVE_MREMAP
index bb6b8d72d784df97b08aa21f69be34cb4b5271d3..00e228a8365ed364e98105edc71add48f8507654 100644 (file)
@@ -1364,6 +1364,13 @@ struct  vki_seminfo {
 #define VKI_MREMAP_MAYMOVE     1
 #define VKI_MREMAP_FIXED       2
 
+//----------------------------------------------------------------------
+// Common madvise flags mman-common.h
+//----------------------------------------------------------------------
+
+#define VKI_MADV_GUARD_INSTALL 102
+#define VKI_MADV_GUARD_REMOVE  103
+
 //----------------------------------------------------------------------
 // From linux-2.6.31-rc4/include/linux/futex.h
 //----------------------------------------------------------------------