[PATCH] netfs: Fix netfs_page_mkwrite() to check folio->mapping is valid
Matthew Wilcox
willy at infradead.org
Mon Jun 24 08:30:37 PDT 2024
On Mon, Jun 24, 2024 at 12:23:01PM +0100, David Howells wrote:
> @@ -508,6 +509,10 @@ vm_fault_t netfs_page_mkwrite(struct vm_fault *vmf, struct netfs_group *netfs_gr
>
> if (folio_lock_killable(folio) < 0)
> goto out;
> + if (folio->mapping != mapping) {
> + ret = VM_FAULT_NOPAGE | VM_FAULT_LOCKED;
> + goto out;
> + }
Have you tested this? I'd expect it to throw some VM assertions.
ret = vmf->vma->vm_ops->page_mkwrite(vmf);
/* Restore original flags so that caller is not surprised */
vmf->flags = old_flags;
if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE)))
return ret;
...
if (unlikely(!tmp || (tmp &
(VM_FAULT_ERROR | VM_FAULT_NOPAGE)))) {
folio_put(folio);
return tmp;
}
So you locked the folio, then called folio_put() without unlocking it.
Usually the VM complains noisily if you free a locked folio.
More information about the linux-afs
mailing list