mm,fork,security: introduce MADV_WIPEONFORK
Subsystems (13)
cover mm,fork,security: introduce MADV_WIPEONFORK
[resend because half the recipients got dropped due to IPv6 firewall issues]
Introduce MADV_WIPEONFORK semantics, which result in a VMA being empty in the child process after fork. This differs from MADV_DONTFORK in one important way.
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.
This is similar to the OpenBSD minherit syscall with MAP_INHERIT_ZERO:
https://man.openbsd.org/minherit.2
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/2 x86,mpx: make mpx depend on x86-64 to free up VMA flag
From: Rik van Riel <[email protected]>
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.
--- arch/x86/Kconfig | 4 +++- include/linux/mm.h | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-)
arch/x86/Kconfig +3 -1
@@ -1756,7 +1756,9 @@ config X86_SMAP config X86_INTEL_MPX prompt "Intel MPX (Memory Protection Extensions)" def_bool n - depends on CPU_SUP_INTEL + # Note: only available in 64-bit mode due to VMA flags shortage + depends on CPU_SUP_INTEL && X86_64 + select ARCH_USES_HIGH_VMA_FLAGS ---help--- MPX provides hardware features that can be used in conjunction with compiler-instrumented code to check
include/linux/mm.h +6 -2
@@ -208,10 +208,12 @@ extern unsigned int kobjsize(const void *objp);#define VM_HIGH_ARCH_BIT_1 33/* bit only usable on 64-bit architectures */ #define VM_HIGH_ARCH_BIT_2 34/* bit only usable on 64-bit architectures */ #define VM_HIGH_ARCH_BIT_3 35/* bit only usable on 64-bit architectures */ +#define VM_HIGH_ARCH_BIT_4 36/* bit only usable on 64-bit architectures */ #define VM_HIGH_ARCH_0 BIT(VM_HIGH_ARCH_BIT_0)#define VM_HIGH_ARCH_1 BIT(VM_HIGH_ARCH_BIT_1)#define VM_HIGH_ARCH_2 BIT(VM_HIGH_ARCH_BIT_2)#define VM_HIGH_ARCH_3 BIT(VM_HIGH_ARCH_BIT_3) +#define VM_HIGH_ARCH_4 BIT(VM_HIGH_ARCH_BIT_4)#endif /* CONFIG_ARCH_USES_HIGH_VMA_FLAGS */ #if defined(CONFIG_X86 )
@@ -235,9 +237,11 @@ extern unsigned int kobjsize(const void *objp);# define VM_MAPPED_COPY VM_ARCH_1/* T if mapped copy of data (nommu mmap) */ #endif -#if defined(CONFIG_X86 ) +#if defined(CONFIG_X86_INTEL_MPX )/* MPX specific bounds table or bounds directory */ -# define VM_MPX VM_ARCH_2 +# define VM_MPX VM_HIGH_ARCH_BIT_4 +#else +# define VM_MPX VM_NONE#endif #ifndef VM_GROWSUP
Signature · 1 line
2.9.4
PATCH 2/2 mm,fork: introduce MADV_WIPEONFORK
In reply to [email protected]From: Rik van Riel <[email protected]>
Introduce MADV_WIPEONFORK semantics, which result in a VMA being empty in the child process after fork. This differs from MADV_DONTFORK in one important way.
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.
This is similar to the OpenBSD minherit syscall with MAP_INHERIT_ZERO:
https://man.openbsd.org/minherit.2
--- arch/alpha/include/uapi/asm/mman.h | 3 +++ arch/mips/include/uapi/asm/mman.h | 3 +++ arch/parisc/include/uapi/asm/mman.h | 3 +++ arch/xtensa/include/uapi/asm/mman.h | 3 +++ fs/proc/task_mmu.c | 1 + include/linux/mm.h | 2 +- include/uapi/asm-generic/mman-common.h | 3 +++ kernel/fork.c | 8 ++++++-- mm/madvise.c | 8 ++++++++ mm/memory.c | 10 ++++++++++ 10 files changed, 41 insertions(+), 3 deletions(-)
arch/alpha/include/uapi/asm/mman.h +3 -0
@@ -64,6 +64,9 @@overrides the coredump filter bits */ #define MADV_DODUMP 17/* Clear the MADV_NODUMP flag */ +#define MADV_WIPEONFORK 18/* Zero memory on fork, child only */ +#define MADV_KEEPONFORK 19/* Undo MADV_WIPEONFORK */ +/* compatibility flags */ #define MAP_FILE 0
arch/mips/include/uapi/asm/mman.h +3 -0
@@ -91,6 +91,9 @@overrides the coredump filter bits */ #define MADV_DODUMP 17/* Clear the MADV_NODUMP flag */ +#define MADV_WIPEONFORK 18/* Zero memory on fork, child only */ +#define MADV_KEEPONFORK 19/* Undo MADV_WIPEONFORK */ +/* compatibility flags */ #define MAP_FILE 0
arch/parisc/include/uapi/asm/mman.h +3 -0
@@ -60,6 +60,9 @@overrides the coredump filter bits */ #define MADV_DODUMP 70/* Clear the MADV_NODUMP flag */ +#define MADV_WIPEONFORK 71/* Zero memory on fork, child only */ +#define MADV_KEEPONFORK 72/* Undo MADV_WIPEONFORK */ +/* compatibility flags */ #define MAP_FILE 0#define MAP_VARIABLE 0
arch/xtensa/include/uapi/asm/mman.h +3 -0
@@ -103,6 +103,9 @@overrides the coredump filter bits */ #define MADV_DODUMP 17/* Clear the MADV_NODUMP flag */ +#define MADV_WIPEONFORK 18/* Zero memory on fork, child only */ +#define MADV_KEEPONFORK 19/* Undo MADV_WIPEONFORK */ +/* compatibility flags */ #define MAP_FILE 0
fs/proc/task_mmu.c +1 -0
@@ -651,6 +651,7 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma) [ilog2(VM_NORESERVE)] = "nr", [ilog2(VM_HUGETLB)] = "ht", [ilog2(VM_ARCH_1)] = "ar", + [ilog2(VM_WIPEONFORK)] = "wf", [ilog2 (VM_DONTDUMP )] ="dd" , #ifdef CONFIG_MEM_SOFT_DIRTY [ilog2(VM_SOFTDIRTY)] = "sd",
include/linux/mm.h +1 -1
@@ -189,7 +189,7 @@ extern unsigned int kobjsize(const void *objp);#define VM_NORESERVE 0x00200000/* should the VM suppress accounting */ #define VM_HUGETLB 0x00400000/* Huge TLB Page VM */ #define VM_ARCH_1 0x01000000/* Architecture-specific flag */ -#define VM_ARCH_2 0x02000000 +#define VM_WIPEONFORK 0x02000000/* Wipe VMA contents in child. */ #define VM_DONTDUMP 0x04000000/* Do not include in the core dump */ #ifdef CONFIG_MEM_SOFT_DIRTY
include/uapi/asm-generic/mman-common.h +3 -0
@@ -58,6 +58,9 @@overrides the coredump filter bits */ #define MADV_DODUMP 17/* Clear the MADV_DONTDUMP flag */ +#define MADV_WIPEONFORK 18/* Zero memory on fork, child only */ +#define MADV_KEEPONFORK 19/* Undo MADV_WIPEONFORK */ +/* compatibility flags */ #define MAP_FILE 0
kernel/fork.c +6 -2
@@ -628,7 +628,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, prev =NULL ;for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) { -struct file *file; +struct file *file =NULL ;if (mpnt->vm_flags &VM_DONTCOPY ) {vm_stat_account (mm, mpnt->vm_flags, -vma_pages (mpnt));
@@ -658,7 +658,11 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, goto fail_nomem_anon_vma_fork; tmp->vm_flags &= ~(VM_LOCKED |VM_LOCKONFAULT ); tmp->vm_next = tmp->vm_prev =NULL ; - file = tmp->vm_file; + +/* With VM_WIPEONFORK, the child gets an empty VMA. */ +if (!(tmp->vm_flags &VM_WIPEONFORK )) + file = tmp->vm_file; +if (file) {struct inode *inode =file_inode (file);struct address_space *mapping = file->f_mapping;
mm/madvise.c +8 -0
@@ -80,6 +80,12 @@ static long madvise_behavior(struct vm_area_struct *vma, } new_flags &= ~VM_DONTCOPY ;break ; +case MADV_WIPEONFORK : + new_flags |=VM_WIPEONFORK ; +break ; +case MADV_KEEPONFORK : + new_flags &= ~VM_WIPEONFORK ; +break ;case MADV_DONTDUMP : new_flags |=VM_DONTDUMP ;break ;
@@ -689,6 +695,8 @@ madvise_behavior_valid(int behavior)#endif case MADV_DONTDUMP :case MADV_DODUMP : +case MADV_WIPEONFORK : +case MADV_KEEPONFORK :#ifdef CONFIG_MEMORY_FAILURE case MADV_SOFT_OFFLINE :case MADV_HWPOISON :
mm/memory.c +10 -0
@@ -1134,6 +1134,16 @@ int copy_page_range(struct mm_struct *dst_mm, struct mm_struct *src_mm, !vma->anon_vma)return 0 ; +/* +* With VM_WIPEONFORK, the child inherits the VMA from the +* parent, but not its contents. +* +* A child accessing VM_WIPEONFORK memory will see all zeroes; +* a child accessing VM_DONTCOPY memory receives a segfault. +*/ +if (vma->vm_flags &VM_WIPEONFORK ) +return 0 ; +if (is_vm_hugetlb_page (vma))return copy_hugetlb_page_range (dst_mm, src_mm, vma);
Signature · 1 line
2.9.4
Re: [PATCH 1/2] x86,mpx: make mpx depend on x86-64 to free up VMA flag
In reply to [email protected]Quoted 3 lines · On 08/04/2017 12:07 PM, [email protected] wrote:
MPX only seems to be available on 64 bit CPUs, starting with Skylake and Goldmont. Move
VM_MPXinto the 64 bit only portion ofvma->vm_flags, in order to free up a VMA flag.
Makes me a little sad. But, seems worth it.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/2] mm,fork: introduce MADV_WIPEONFORK
In reply to [email protected]Quoted 49 lines · On 08/04/2017 12:07 PM, [email protected] wrote:
From: Rik van Riel <[email protected]>
Introduce
MADV_WIPEONFORKsemantics, which result in a VMA being empty in the child process after fork. This differs fromMADV_DONTFORKin one important way.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_DONTFORKalso seems to be used to allow very large programs to fork in systems with strict memory overcommit restrictions, changing the semantics ofMADV_DONTFORKmight 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_atforkhook to not get called.It would be better to have the kernel take care of this automatically.
This is similar to the OpenBSD minherit syscall with
MAP_INHERIT_ZERO:https://man.openbsd.org/minherit.2
Reported-by Florian Weimer <[email protected]>Reported-by Colm MacCA!rtaigh <[email protected]>Signed-off-by Rik van Riel <[email protected]>
Quoted 13 lines
--- arch/alpha/include/uapi/asm/mman.h | 3 +++ arch/mips/include/uapi/asm/mman.h | 3 +++ arch/parisc/include/uapi/asm/mman.h | 3 +++ arch/xtensa/include/uapi/asm/mman.h | 3 +++ fs/proc/task_mmu.c | 1 + include/linux/mm.h | 2 +- include/uapi/asm-generic/mman-common.h | 3 +++ kernel/fork.c | 8 ++++++-- mm/madvise.c | 8 ++++++++ mm/memory.c | 10 ++++++++++ 10 files changed, 41 insertions(+), 3 deletions(-)
This didn't seem 'quite right' to me for shared mappings and/or file backed mappings. I wasn't exactly sure what it 'should' do in such cases. So, I tried it with a mapping created as follows:
addr = mmap(ADDR, page_size,
PROT_READ | PROT_WRITE, MAP_ANONYMOUS|MAP_SHARED, -1, 0);
When setting MADV_WIPEONFORK on the vma/mapping, I got the following at task exit time:
[ 694.558290] ------------[ cut here ]------------ [ 694.558978] kernel BUG at mm/filemap.c:212! [ 694.559476] invalid opcode: 0000 [#1] SMP [ 694.560023] Modules linked in: ip6t_REJECT nf_reject_ipv6 ip6t_rpfilter xt_conntrack ebtable_broute bridge stp llc ebtable_nat ip6table_nat nf_conntrack_ipv6 nf_defrag_ipv6 nf_nat_ipv6 ip6table_raw ip6table_mangle ip6table_security iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack iptable_raw iptable_mangle 9p iptable_security ebtable_filter ebtables ip6table_filter ip6_tables snd_hda_codec_generic snd_hda_intel snd_hda_codec snd_hwdep snd_hda_core snd_seq ppdev snd_seq_device joydev crct10dif_pclmul crc32_pclmul crc32c_intel snd_pcm ghash_clmulni_intel 9pnet_virtio virtio_balloon snd_timer 9pnet parport_pc snd parport i2c_piix4 soundcore nfsd auth_rpcgss nfs_acl lockd grace sunrpc virtio_net virtio_blk virtio_console 8139too qxl drm_kms_helper ttm drm serio_raw 8139cp [ 694.571554] mii virtio_pci ata_generic virtio_ring virtio pata_acpi [ 694.572608] CPU: 3 PID: 1200 Comm: test_wipe2 Not tainted 4.13.0-rc3+ #8 [ 694.573778] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.9.1-1.fc24 04/01/2014 [ 694.574917] task: ffff880137178040 task.stack: ffffc900019d4000 [ 694.575650] RIP: 0010:__delete_from_page_cache+0x344/0x410 [ 694.576409] RSP: 0018:ffffc900019d7a88 EFLAGS: 00010082 [ 694.577238] RAX: 0000000000000021 RBX: ffffea00047d0e00 RCX: 0000000000000006 [ 694.578537] RDX: 0000000000000000 RSI: 0000000000000096 RDI: ffff88023fd0db90 [ 694.579774] RBP: ffffc900019d7ad8 R08: 00000000000882b6 R09: 000000000000028a [ 694.580754] R10: ffffc900019d7da8 R11: ffffffff8211184d R12: ffffea00047d0e00 [ 694.582040] R13: 0000000000000000 R14: 0000000000000202 R15: ffff8801384439e8 [ 694.583236] FS: 0000000000000000(0000) GS:ffff88023fd00000(0000) knlGS:0000000000000000 [ 694.584607] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 694.585409] CR2: 00007ff77a8da618 CR3: 0000000001e09000 CR4: 00000000001406e0 [ 694.586547] Call Trace: [ 694.586996] delete_from_page_cache+0x54/0x110 [ 694.587481] truncate_inode_page+0xab/0x120 [ 694.588110] shmem_undo_range+0x498/0xa50 [ 694.588813] ? save_stack_trace+0x1b/0x20 [ 694.589529] ? set_track+0x70/0x140 [ 694.590150] ? init_object+0x69/0xa0 [ 694.590722] ? __inode_wait_for_writeback+0x73/0xe0 [ 694.591525] shmem_truncate_range+0x16/0x40 [ 694.592268] shmem_evict_inode+0xb1/0x190 [ 694.592735] evict+0xbb/0x1c0 [ 694.593147] iput+0x1c0/0x210 [ 694.593497] dentry_unlink_inode+0xb4/0x150 [ 694.593982] __dentry_kill+0xc1/0x150 [ 694.594400] dput+0x1c8/0x1e0 [ 694.594745] __fput+0x172/0x1e0 [ 694.595103] ____fput+0xe/0x10 [ 694.595463] task_work_run+0x80/0xa0 [ 694.595886] do_exit+0x2d6/0xb50 [ 694.596323] ? __do_page_fault+0x288/0x4a0 [ 694.596818] do_group_exit+0x47/0xb0 [ 694.597249] SyS_exit_group+0x14/0x20 [ 694.597682] entry_SYSCALL_64_fastpath+0x1a/0xa5 [ 694.598198] RIP: 0033:0x7ff77a5e78c8 [ 694.598612] RSP: 002b:00007ffc5aece318 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7 [ 694.599804] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007ff77a5e78c8 [ 694.600609] RDX: 0000000000000000 RSI: 000000000000003c RDI: 0000000000000000 [ 694.601424] RBP: 00007ff77a8da618 R08: 00000000000000e7 R09: ffffffffffffff98 [ 694.602224] R10: 0000000000000003 R11: 0000000000000246 R12: 0000000000000001 [ 694.603151] R13: 00007ff77a8dbc60 R14: 0000000000000000 R15: 0000000000000000 [ 694.603984] Code: 60 f3 c5 81 e8 2e 7e 03 00 0f 0b 48 c7 c6 60 f3 c5 81 4c 89 e7 e8 1d 7e 03 00 0f 0b 48 c7 c6 00 f4 c5 81 4c 89 e7 e8 0c 7e 03 00 <0f> 0b 48 c7 c6 38 f3 c5 81 4c 89 e7 e8 fb 7d 03 00 0f 0b 48 c7 [ 694.606500] RIP: __delete_from_page_cache+0x344/0x410 RSP: ffffc900019d7a88 [ 694.607426] ---[ end trace 55e6b04ae95d8ce3 ]---
BTW, this was on 4.13.0-rc3 + your patches. Simple test program is below.
Signature · 55 lines
Mike Kravetz
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/mman.h>
#include <errno.h>
#define MADV_WIPEONFORK 18
#define ADDR (void *)(0x0UL)
int main(int argc, char ** argv)
{
unsigned long page_size;
int ret;
void *addr;
char foo;
page_size = sysconf(_SC_PAGE_SIZE);
addr = mmap(ADDR, page_size,
PROT_READ | PROT_WRITE,
MAP_ANONYMOUS|MAP_SHARED, -1, 0);
if (addr == MAP_FAILED) {
perror("mmap");
exit (1);
}
printf("Parent writing 'a' to page\n");
*((char *)addr) = 'a';
ret = madvise(addr, page_size, MADV_WIPEONFORK);
if (ret) {
perror("madvise");
exit (1);
}
if (fork()) {
/* In parent */
sleep(1);
} else {
/* In child */
foo = *((char *)addr);
printf("child read '%c' from page\n", foo);
}
return ret;
}
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>Quoted 8 lines · On Fri, Aug 04, 2017 at 03:07:28PM -0400, [email protected] wrote:
[resend because half the recipients got dropped due to IPv6 firewall issues]
Introduce
MADV_WIPEONFORKsemantics, which result in a VMA being empty in the child process after fork. This differs fromMADV_DONTFORKin one important way.If a child process accesses memory that was
MADV_WIPEONFORK, it will get zeroes. The address ranges are still valid, they are just empty.
I feel like we are repeating mistake we made with MADV_DONTNEED.
MADV_WIPEONFORK would require a specific action from kernel, ignoring the /advise/ would likely lead to application misbehaviour.
Is it something we really want to see from madvise()?
Signature · 7 lines
Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/2] mm,fork: introduce MADV_WIPEONFORK
In reply to Mike KravetzQuoted 12 lines · Mike Kravetz
Quoted 11 lines · On 08/04/2017 12:07 PM, [email protected] wrote:
From: Rik van Riel <[email protected]>
Introduce
MADV_WIPEONFORKsemantics, which result in a VMA being empty in the child process after fork. This differs fromMADV_DONTFORK
in one important way.If a child process accesses memory that was
MADV_WIPEONFORK, it will get zeroes. The address ranges are still valid, they are just empty.
Quoted 7 lines
This didn't seem 'quite right' to me for shared mappings and/or file backed mappings.A A I wasn't exactly sure what it 'should' do in such cases.A A So, I tried it with a mapping created as follows:
addr = mmap(ADDR,
page_size,
A A A A A A A A A A A A A A A A A A A A A A A APROT_READ|PROT_WRITE, A A A A A A A A A A A A A A A A A A A A A A A A MAP_ANONYMOUS|MAP_SHARED, -1, 0);
Your test program is pretty much the same I used, except I used MAP_PRIVATE instead of MAP_SHARED.
Let me see how the code paths differ for both cases...
Quoted 87 lines
When setting
MADV_WIPEONFORKon the vma/mapping, I got the following at task exit time:[A A 694.558290] ------------[ cut here ]------------
[A A 694.558978] kernel BUG atmm/filemap.c:212!
[A A 694.559476] invalid opcode: 0000 [#1] SMP
[A A 694.560023] Modules linked in:ip6t_REJECTnf_reject_ipv6ip6t_rpfilterxt_conntrackebtable_broutebridge stp llcebtable_natip6table_natnf_conntrack_ipv6nf_defrag_ipv6nf_nat_ipv6ip6table_rawip6table_mangleip6table_securityiptable_natnf_conntrack_ipv4nf_defrag_ipv4nf_nat_ipv4nf_natnf_conntrackiptable_rawiptable_mangle9piptable_securityebtable_filterebtablesip6table_filterip6_tablessnd_hda_codec_genericsnd_hda_intelsnd_hda_codecsnd_hwdepsnd_hda_coresnd_seqppdevsnd_seq_devicejoydevcrct10dif_pclmulcrc32_pclmulcrc32c_intelsnd_pcmghash_clmulni_intel9pnet_virtiovirtio_balloonsnd_timer9pnetparport_pcsnd parporti2c_piix4soundcore nfsdauth_rpcgssnfs_acllockd grace sunrpcvirtio_netvirtio_blkvirtio_console8139too qxldrm_kms_helperttm drmserio_raw8139cp
[A A 694.571554]A A miivirtio_pciata_genericvirtio_ringvirtiopata_acpi
[A A 694.572608] CPU: 3 PID: 1200 Comm:test_wipe2Not tainted 4.13.0- rc3+ #8
[A A 694.573778] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.9.1-1.fc24 04/01/2014
[A A 694.574917] task:ffff880137178040task.stack:ffffc900019d4000[A A 694.575650] RIP: 0010:__delete_from_page_cache+0x344/0x410 [A A 694.576409] RSP: 0018:ffffc900019d7a88 EFLAGS: 00010082 [A A 694.577238] RAX: 0000000000000021 RBX:ffffea00047d0e00RCX:
0000000000000006
[A A 694.578537] RDX: 0000000000000000 RSI: 0000000000000096 RDI:ffff88023fd0db90
[A A 694.579774] RBP:ffffc900019d7ad8R08:00000000000882b6R09:000000000000028a
[A A 694.580754] R10:ffffc900019d7da8R11:ffffffff8211184dR12:ffffea00047d0e00
[A A 694.582040] R13: 0000000000000000 R14: 0000000000000202 R15:ffff8801384439e8
[A A 694.583236] FS:A A 0000000000000000(0000) GS:ffff88023fd00000(0000) knlGS:0000000000000000
[A A 694.584607] CS:A A 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [A A 694.585409] CR2:00007ff77a8da618CR3:0000000001e09000CR4:00000000001406e0
[A A 694.586547] Call Trace:
[A A 694.586996]A Adelete_from_page_cache+0x54/0x110
[A A 694.587481]A Atruncate_inode_page+0xab/0x120
[A A 694.588110]A Ashmem_undo_range+0x498/0xa50
[A A 694.588813]A A ?save_stack_trace+0x1b/0x20
[A A 694.589529]A A ?set_track+0x70/0x140
[A A 694.590150]A A ?init_object+0x69/0xa0
[A A 694.590722]A A ?__inode_wait_for_writeback+0x73/0xe0[A A 694.591525]A Ashmem_truncate_range+0x16/0x40
[A A 694.592268]A Ashmem_evict_inode+0xb1/0x190
[A A 694.592735]A Aevict+0xbb/0x1c0
[A A 694.593147]A Aiput+0x1c0/0x210
[A A 694.593497]A Adentry_unlink_inode+0xb4/0x150
[A A 694.593982]A A__dentry_kill+0xc1/0x150
[A A 694.594400]A Adput+0x1c8/0x1e0
[A A 694.594745]A A__fput+0x172/0x1e0
[A A 694.595103]A A____fput+0xe/0x10
[A A 694.595463]A Atask_work_run+0x80/0xa0
[A A 694.595886]A Ado_exit+0x2d6/0xb50
[A A 694.596323]A A ?__do_page_fault+0x288/0x4a0
[A A 694.596818]A Ado_group_exit+0x47/0xb0
[A A 694.597249]A ASyS_exit_group+0x14/0x20
[A A 694.597682]A Aentry_SYSCALL_64_fastpath+0x1a/0xa5
[A A 694.598198] RIP: 0033:0x7ff77a5e78c8
[A A 694.598612] RSP: 002b:00007ffc5aece318 EFLAGS: 00000246ORIG_RAX:00000000000000e7
[A A 694.599804] RAX: ffffffffffffffda RBX: 0000000000000000 RCX:00007ff77a5e78c8
[A A 694.600609] RDX: 0000000000000000 RSI:000000000000003cRDI:
0000000000000000
[A A 694.601424] RBP:00007ff77a8da618R08:00000000000000e7R09:ffffffffffffff98
[A A 694.602224] R10: 0000000000000003 R11: 0000000000000246 R12:
0000000000000001
[A A 694.603151] R13:00007ff77a8dbc60R14: 0000000000000000 R15:
0000000000000000
[A A 694.603984] Code: 60 f3 c5 81 e8 2e 7e 03 00 0f 0b 48 c7 c6 60 f3 c5 81 4c 89 e7 e8 1d 7e 03 00 0f 0b 48 c7 c6 00 f4 c5 81 4c 89 e7 e8 0c 7e 03 00 <0f> 0b 48 c7 c6 38 f3 c5 81 4c 89 e7 e8 fb 7d 03 00 0f 0b 48 c7A
[A A 694.606500] RIP:__delete_from_page_cache+0x344/0x410RSP:ffffc900019d7a88
[A A 694.607426] ---[ end trace55e6b04ae95d8ce3]---
Quoted 3 lines
BTW, this was on 4.13.0-rc3 + your patches.A A Simple test program is below.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 13 lines · Kirill A. Shutemov
Quoted 11 lines · On Fri, Aug 04, 2017 at 03:07:28PM -0400, [email protected] wrote:
[resend because half the recipients got dropped due to IPv6 firewall issues]
Introduce
MADV_WIPEONFORKsemantics, which result in a VMA being empty in the child process after fork. This differs fromMADV_DONTFORK
in one important way.If a child process accesses memory that was
MADV_WIPEONFORK, it will get zeroes. The address ranges are still valid, they are just empty.
Quoted 6 lines
I feel like we are repeating mistake we made with
MADV_DONTNEED.
MADV_WIPEONFORKwould require a specific action from kernel, ignoring the /advise/ would likely lead to application misbehaviour.Is it something we really want to see from
madvise()?
We already have various mandatory madvise behaviors in Linux, including MADV_REMOVE, MADV_DONTFORK, and MADV_DONTDUMP.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
kbuild test robot
build botRe: [PATCH 2/2] mm,fork: introduce MADV_WIPEONFORK
In reply to [email protected]url: https://github.com/0day-ci/linux/commits/riel-redhat-com/mm-fork-security-introduce-MADV_WIPEONFORK/20170806-035914 config: m68k-sun3_defconfig (attached as .config) compiler: m68k-linux-gcc…
Hi Rik,
[auto build test ERROR on linus/master]
[also build test ERROR on v4.13-rc5]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/riel-redhat-com/mm-fork-security-introduce-MADV_WIPEONFORK/20170806-035914
config: m68k-sun3_defconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 4.9.0
reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=m68k
All errors (new ones prefixed by >>):
In file included from mm/debug.c:12:0:
>> include/trace/events/mmflags.h:131:31: error: 'VM_ARCH_2' undeclared here (not in a function)
#define __VM_ARCH_SPECIFIC_2 {VM_ARCH_2, "arch_2" }
^
include/trace/events/mmflags.h:165:2: note: in expansion of macro '__VM_ARCH_SPECIFIC_2'
__VM_ARCH_SPECIFIC_2 , \
^
mm/debug.c:39:2: note: in expansion of macro '__def_vmaflag_names'
__def_vmaflag_names,
^vim +/VM_ARCH_2 +131 include/trace/events/mmflags.h
bcf669179 Kirill A. Shutemov 2016-03-17 127
bcf669179 Kirill A. Shutemov 2016-03-17 128 #if defined(CONFIG_X86)
bcf669179 Kirill A. Shutemov 2016-03-17 129 #define __VM_ARCH_SPECIFIC_2 {VM_MPX, "mpx" }
bcf669179 Kirill A. Shutemov 2016-03-17 130 #else
bcf669179 Kirill A. Shutemov 2016-03-17 @131 #define __VM_ARCH_SPECIFIC_2 {VM_ARCH_2, "arch_2" }
420adbe9f Vlastimil Babka 2016-03-15 132 #endif
420adbe9f Vlastimil Babka 2016-03-15 133 :::::: The code at line 131 was first introduced by commit
:::::: bcf6691797f425b301f629bb783b7ff2d0bcfa5a mm, tracing: refresh __def_vmaflag_names
:::::: TO: Kirill A. Shutemov <[email protected]> :::::: CC: Linus Torvalds <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation