Re: [PATCH 3/6] mm/vma: only permit MAP_PRIVATE /dev/zero to be mapped anonymous
From: Gregory Price
Date: Mon Sep 07 2026 - 12:18:12 EST
On Wed, Sep 02, 2026 at 07:00:20PM +0100, Lorenzo Stoakes (ARM) wrote:
> In order to use mmap_prepare() with MAP_PRIVATE mappings of /dev/zero
> without the success_hook hack we explicitly permitted mmap_prepare handlers
> to set NULL vm_ops.
>
> However this is dangerous and we really only want to allow this for
> MAP_PRIVATE-mapped /dev/zero.
>
"this is dangerous" -> can you expand on this?
I had been experimenting with mmap'ing kmem dax devices as a way to test
generating a driver-defined efault mempolicy on an anonymous region, and
this exact pattern came up for me during mmap_prepare trying to get rid
of the "fileness" of the VMA.
Basically looked exactly like the /dev/zero vma.
I understand this is a hack, i'm just trying to better understand why
"this is dangerous" and it shouldn't be a supported pattern.
for clarity:
fd = open("/dev/dax0.0",...);
buf = mmap(fd, ...);
/*
* mmap(_prepare) callback marks the vma anonymous so it takes anon
* fault routes and sets an mbind mempolicy installed on the vma to
* prefer the node the dax device is registered to.
*/
buf[0] = 0xDEADBEEF; /* faults an anon page from the node */