Skip to content

Commit df3735c

Browse files
Rik van Rieltorvalds
authored andcommitted
x86,mpx: make mpx depend on x86-64 to free up VMA flag
Patch series "mm,fork,security: introduce MADV_WIPEONFORK", v4. If a child process accesses memory that was MADV_WIPEONFORK, it will get zeroes. The address ranges are still valid, they are just empty. If a child process accesses memory that was MADV_DONTFORK, it will get a segmentation fault, since those address ranges are no longer valid in the child after fork. Since MADV_DONTFORK also seems to be used to allow very large programs to fork in systems with strict memory overcommit restrictions, changing the semantics of MADV_DONTFORK might break existing programs. The use case is libraries that store or cache information, and want to know that they need to regenerate it in the child process after fork. Examples of this would be: - systemd/pulseaudio API checks (fail after fork) (replacing a getpid check, which is too slow without a PID cache) - PKCS#11 API reinitialization check (mandated by specification) - glibc's upcoming PRNG (reseed after fork) - OpenSSL PRNG (reseed after fork) The security benefits of a forking server having a re-inialized PRNG in every child process are pretty obvious. However, due to libraries having all kinds of internal state, and programs getting compiled with many different versions of each library, it is unreasonable to expect calling programs to re-initialize everything manually after fork. A further complication is the proliferation of clone flags, programs bypassing glibc's functions to call clone directly, and programs calling unshare, causing the glibc pthread_atfork hook to not get called. It would be better to have the kernel take care of this automatically. The patchset also adds MADV_KEEPONFORK, to undo the effects of a prior MADV_WIPEONFORK. This is similar to the OpenBSD minherit syscall with MAP_INHERIT_ZERO: https://man.openbsd.org/minherit.2 This patch (of 2): MPX only seems to be available on 64 bit CPUs, starting with Skylake and Goldmont. Move VM_MPX into the 64 bit only portion of vma->vm_flags, in order to free up a VMA flag. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Rik van Riel <[email protected]> Acked-by: Dave Hansen <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: Florian Weimer <[email protected]> Cc: Kees Cook <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Will Drewry <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Colm MacCártaigh <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 493b0e9 commit df3735c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

arch/x86/Kconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,9 @@ config X86_SMAP
18061806
config X86_INTEL_MPX
18071807
prompt "Intel MPX (Memory Protection Extensions)"
18081808
def_bool n
1809-
depends on CPU_SUP_INTEL
1809+
# Note: only available in 64-bit mode due to VMA flags shortage
1810+
depends on CPU_SUP_INTEL && X86_64
1811+
select ARCH_USES_HIGH_VMA_FLAGS
18101812
---help---
18111813
MPX provides hardware features that can be used in
18121814
conjunction with compiler-instrumented code to check

include/linux/mm.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,12 @@ extern unsigned int kobjsize(const void *objp);
208208
#define VM_HIGH_ARCH_BIT_1 33 /* bit only usable on 64-bit architectures */
209209
#define VM_HIGH_ARCH_BIT_2 34 /* bit only usable on 64-bit architectures */
210210
#define VM_HIGH_ARCH_BIT_3 35 /* bit only usable on 64-bit architectures */
211+
#define VM_HIGH_ARCH_BIT_4 36 /* bit only usable on 64-bit architectures */
211212
#define VM_HIGH_ARCH_0 BIT(VM_HIGH_ARCH_BIT_0)
212213
#define VM_HIGH_ARCH_1 BIT(VM_HIGH_ARCH_BIT_1)
213214
#define VM_HIGH_ARCH_2 BIT(VM_HIGH_ARCH_BIT_2)
214215
#define VM_HIGH_ARCH_3 BIT(VM_HIGH_ARCH_BIT_3)
216+
#define VM_HIGH_ARCH_4 BIT(VM_HIGH_ARCH_BIT_4)
215217
#endif /* CONFIG_ARCH_USES_HIGH_VMA_FLAGS */
216218

217219
#if defined(CONFIG_X86)
@@ -235,9 +237,11 @@ extern unsigned int kobjsize(const void *objp);
235237
# define VM_MAPPED_COPY VM_ARCH_1 /* T if mapped copy of data (nommu mmap) */
236238
#endif
237239

238-
#if defined(CONFIG_X86)
240+
#if defined(CONFIG_X86_INTEL_MPX)
239241
/* MPX specific bounds table or bounds directory */
240-
# define VM_MPX VM_ARCH_2
242+
# define VM_MPX VM_HIGH_ARCH_BIT_4
243+
#else
244+
# define VM_MPX VM_NONE
241245
#endif
242246

243247
#ifndef VM_GROWSUP

0 commit comments

Comments
 (0)