From: Mark Wielaard Date: Wed, 7 Jan 2026 21:20:49 +0000 (+0100) Subject: Disable linux madvise MADV_GUARD_INSTALL X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19a34d1d9376f459cf0a19feb39ea4ab27690390;p=thirdparty%2Fvalgrind.git Disable linux madvise MADV_GUARD_INSTALL 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 --- diff --git a/NEWS b/NEWS index 1da711b26..d5188f7c6 100644 --- 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' diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c index aa4a0caf1..d8910fdba 100644 --- a/coregrind/m_syswrap/syswrap-generic.c +++ b/coregrind/m_syswrap/syswrap-generic.c @@ -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 diff --git a/include/vki/vki-linux.h b/include/vki/vki-linux.h index bb6b8d72d..00e228a83 100644 --- a/include/vki/vki-linux.h +++ b/include/vki/vki-linux.h @@ -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 //----------------------------------------------------------------------