linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/userfaultfd: Reset ptes when close() for wr-protected ones
@ 2024-04-22 13:33 Peter Xu
  2024-04-22 15:09 ` David Hildenbrand
  2024-04-22 19:47 ` Andrew Morton
  0 siblings, 2 replies; 4+ messages in thread
From: Peter Xu @ 2024-04-22 13:33 UTC (permalink / raw)
  To: linux-kernel, linux-mm
  Cc: peterx, Nadav Amit, Andrew Morton, David Hildenbrand,
	syzbot+d8426b591c36b21c750e

Userfaultfd unregister includes a step to remove wr-protect bits from all
the relevant pgtable entries, but that only covered an explicit
UFFDIO_UNREGISTER ioctl, not a close() on the userfaultfd itself.  Cover
that too.

Link: https://lore.kernel.org/all/000000000000ca4df20616a0fe16@google.com/
Analyzed-by: David Hildenbrand <david@redhat.com>
Reported-by: syzbot+d8426b591c36b21c750e@syzkaller.appspotmail.com
Signed-off-by: Peter Xu <peterx@redhat.com>
---
 fs/userfaultfd.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index 3e6ddda6f159..d2c3879745e5 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -898,6 +898,10 @@ static int userfaultfd_release(struct inode *inode, struct file *file)
 			prev = vma;
 			continue;
 		}
+		/* Reset ptes for the whole vma range if wr-protected */
+		if (userfaultfd_wp(vma))
+			uffd_wp_range(vma, vma->vm_start,
+				      vma->vm_end - vma->vm_start, false);
 		new_flags = vma->vm_flags & ~__VM_UFFD_FLAGS;
 		vma = vma_modify_flags_uffd(&vmi, prev, vma, vma->vm_start,
 					    vma->vm_end, new_flags,
-- 
2.44.0



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-22 21:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-22 13:33 [PATCH] mm/userfaultfd: Reset ptes when close() for wr-protected ones Peter Xu
2024-04-22 15:09 ` David Hildenbrand
2024-04-22 19:47 ` Andrew Morton
2024-04-22 21:08   ` Peter Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox