Re: [PATCH] device-dax: fail all private mapping attempts

From: Hugh Dickins
Date: Mon Dec 05 2016 - 20:02:15 EST


On Wed, 16 Nov 2016, Dan Williams wrote:

> The device-dax implementation originally tried to be tricky and allow
> private read-only mappings, but in the process allowed writable
> MAP_PRIVATE + MAP_NORESERVE mappings. For simplicity and predictability
> just fail all private mapping attempts since device-dax memory is
> statically allocated and will never support overcommit.
>
> Cc: <stable@xxxxxxxxxxxxxxx>
> Cc: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
> Fixes: dee410792419 ("/dev/dax, core: file operations and dax-mmap")
> Reported-by: Pawel Lebioda <pawel.lebioda@xxxxxxxxx>
> Signed-off-by: Dan Williams <dan.j.williams@xxxxxxxxx>
> ---
> drivers/dax/dax.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dax/dax.c b/drivers/dax/dax.c
> index 0e499bfca41c..3d94ff20fdca 100644
> --- a/drivers/dax/dax.c
> +++ b/drivers/dax/dax.c
> @@ -270,8 +270,8 @@ static int check_vma(struct dax_dev *dax_dev, struct vm_area_struct *vma,
> if (!dax_dev->alive)
> return -ENXIO;
>
> - /* prevent private / writable mappings from being established */
> - if ((vma->vm_flags & (VM_NORESERVE|VM_SHARED|VM_WRITE)) == VM_WRITE) {
> + /* prevent private mappings from being established */
> + if ((vma->vm_flags & VM_SHARED) != VM_SHARED) {

I think that is more restrictive than you intended: haven't tried,
but I believe it rejects a PROT_READ, MAP_SHARED, O_RDONLY fd mmap,
leaving no way to mmap /dev/dax without write permission to it.

See line 1393 of mm/mmap.c: the test you want is probably
if (!(vma->vm_flags & VM_MAYSHARE))

Hugh

> dev_info(dev, "%s: %s: fail, attempted private mapping\n",
> current->comm, func);
> return -EINVAL;
>
> --