The patch titled Subject: mm-add-an-f_seal_future_write-seal-to-memfd-fix-2 has been added to the -mm tree. Its filename is mm-add-an-f_seal_future_write-seal-to-memfd-fix-2.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-add-an-f_seal_future_write-seal-to-memfd-fix-2.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-add-an-f_seal_future_write-seal-to-memfd-fix-2.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: "Joel Fernandes (Google)" <joel@xxxxxxxxxxxxxxxxx> Subject: mm-add-an-f_seal_future_write-seal-to-memfd-fix-2 v4 Link: http://lkml.kernel.org/r/20181122230906.GA198127@xxxxxxxxxx Signed-off-by: Joel Fernandes (Google) <joel@xxxxxxxxxxxxxxxxx> Suggested-by: Andy Lutomirski <luto@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- --- a/mm/shmem.c~mm-add-an-f_seal_future_write-seal-to-memfd-fix-2 +++ a/mm/shmem.c @@ -2123,20 +2123,22 @@ static int shmem_mmap(struct file *file, { struct shmem_inode_info *info = SHMEM_I(file_inode(file)); - /* - * New PROT_READ and MAP_SHARED mmaps are not allowed when "future - * write" seal active. - */ - if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_WRITE) && - (info->seals & F_SEAL_FUTURE_WRITE)) - return -EPERM; - /* - * Since the F_SEAL_FUTURE_WRITE seals allow for a MAP_SHARED read-only - * mapping, take care to not allow mprotect to revert protections. - */ - if (info->seals & F_SEAL_FUTURE_WRITE) + if (info->seals & F_SEAL_FUTURE_WRITE) { + /* + * New PROT_WRITE and MAP_SHARED mmaps are not allowed when + * "future write" seal active. + */ + if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_WRITE)) + return -EPERM; + + /* + * Since the F_SEAL_FUTURE_WRITE seals allow for a MAP_SHARED + * read-only mapping, take care to not allow mprotect to revert + * protections. + */ vma->vm_flags &= ~(VM_MAYWRITE); + } file_accessed(file); vma->vm_ops = &shmem_vm_ops; _ Patches currently in -mm which might be from joel@xxxxxxxxxxxxxxxxx are mm-treewide-remove-unused-address-argument-from-pte_alloc-functions-v2.patch mm-speed-up-mremap-by-20x-on-large-regions-v5.patch mm-speed-up-mremap-by-20x-on-large-regions-v5-fix.patch mm-select-have_move_pmd-in-x86-for-faster-mremap.patch mm-add-an-f_seal_future_write-seal-to-memfd.patch mm-add-an-f_seal_future_write-seal-to-memfd-fix.patch mm-add-an-f_seal_future_write-seal-to-memfd-fix-2.patch selftests-memfd-add-tests-for-f_seal_future_write-seal.patch selftests-memfd-add-tests-for-f_seal_future_write-seal-fix.patch