Re: Sealed memfd & no-fault mmap

From: Lin, Ming
Date: Sat May 29 2021 - 03:35:16 EST


On 5/28/2021 6:03 PM, Linus Torvalds wrote:
On Fri, May 28, 2021 at 7:07 AM Lin, Ming <minggr@xxxxxxxxx> wrote:

Does something like following draft patch on the right track?

No, I don't think this can work:

+ _dst_pte = pte_mkspecial(pfn_pte(my_zero_pfn(dst_addr),
+ vma->vm_page_prot));

You can't just blindly insert the zero pfn - for a shared write
mapping, that would actually allow writes to the zeropage. That would
be horrible.

I should check the vma is not writable.

diff --git a/mm/shmem.c b/mm/shmem.c
index 856d2d8d4cdf..fa23e38bc692 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1820,7 +1820,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
spinlock_t *ptl;
int ret;
- if (!IS_NOFAULT(inode))
+ if (!IS_NOFAULT(inode) || (vma->vm_flags & VM_WRITE))
return -EINVAL;
_dst_pte = pte_mkspecial(pfn_pte(my_zero_pfn(dst_addr)