diff options
author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2025-01-08 15:16:48 -0300 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2025-01-30 10:16:37 -0300 |
commit | a6fbe36b7f31292981422692236465ab56670ea9 (patch) | |
tree | a27781f1cbf95dbba94b325107c54c5e722ecb2b /sysdeps/unix/sysv | |
parent | 8e86549d1417a4618ab98d10aaba427350b321c6 (diff) | |
download | glibc-a6fbe36b7f31292981422692236465ab56670ea9.zip glibc-a6fbe36b7f31292981422692236465ab56670ea9.tar.gz glibc-a6fbe36b7f31292981422692236465ab56670ea9.tar.bz2 |
nptl: Add support for setup guard pages with MADV_GUARD_INSTALL
Linux 6.13 (662df3e5c3766) added a lightweight way to define guard areas
through madvise syscall. Instead of PROT_NONE the guard region through
mprotect, userland can madvise the same area with a special flag, and
the kernel ensures that accessing the area will trigger a SIGSEGV (as for
PROT_NONE mapping).
The madvise way has the advantage of less kernel memory consumption for
the process page-table (one less VMA per guard area), and slightly less
contention on kernel (also due to the fewer VMA areas being tracked).
The pthread_create allocates a new thread stack in two ways: if a guard
area is set (the default) it allocates the memory range required using
PROT_NONE and then mprotect the usable stack area. Otherwise, if a
guard page is not set it allocates the region with the required flags.
For the MADV_GUARD_INSTALL support, the stack area region is allocated
with required flags and then the guard region is installed. If the
kernel does not support it, the usual way is used instead (and
MADV_GUARD_INSTALL is disabled for future stack creations).
The stack allocation strategy is recorded on the pthread struct, and it
is used in case the guard region needs to be resized. To avoid needing
an extra field, the 'user_stack' is repurposed and renamed to 'stack_mode'.
This patch also adds a proper test for the pthread guard.
I checked on x86_64, aarch64, powerpc64le, and hppa with kernel 6.13.0-rc7.
Reviewed-by: DJ Delorie <dj@redhat.com>
Diffstat (limited to 'sysdeps/unix/sysv')
-rw-r--r-- | sysdeps/unix/sysv/linux/bits/mman-linux.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/sysdeps/unix/sysv/linux/bits/mman-linux.h b/sysdeps/unix/sysv/linux/bits/mman-linux.h index 8e072eb..fe0496d 100644 --- a/sysdeps/unix/sysv/linux/bits/mman-linux.h +++ b/sysdeps/unix/sysv/linux/bits/mman-linux.h @@ -113,6 +113,8 @@ locked pages too. */ # define MADV_COLLAPSE 25 /* Synchronous hugepage collapse. */ # define MADV_HWPOISON 100 /* Poison a page for testing. */ +# define MADV_GUARD_INSTALL 102 /* Fatal signal on access to range */ +# define MADV_GUARD_REMOVE 103 /* Unguard range */ #endif /* The POSIX people had to invent similar names for the same things. */ |