From: syzbot <syzbot+e24a2e34fad0efbac047@syzkaller.appspotmail.com>
To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Forwarded: [PATCH] mm/userfaultfd: validate dst_addr after re-acquiring VMA lock in mfill_copy_folio_retry
Date: Sun, 15 Mar 2026 22:11:18 -0700 [thread overview]
Message-ID: <69b790f6.a00a0220.3b25d1.0021.GAE@google.com> (raw)
In-Reply-To: <69b703e6.050a0220.248e02.0101.GAE@google.com>
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] mm/userfaultfd: validate dst_addr after re-acquiring VMA lock in mfill_copy_folio_retry
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
mfill_copy_folio_retry() drops the VMA lock to perform
copy_from_user() without holding it, then reacquires it
via mfill_get_vma(). However, mfill_get_vma() only validates
that dst_start is within the VMA bounds, not dst_addr (the
current page being processed).
A concurrent UFFDIO_UNREGISTER can split the VMA during the
window where the lock is dropped, shrinking vma->vm_end. When
mfill_get_vma() reacquires the lock, it finds the VMA using
dst_start which may still be valid, but dst_addr may now fall
outside the split VMA's bounds.
This causes folio_add_new_anon_rmap() to trigger its sanity
check:
address < vma->vm_start || address + (nr << 12) > vma->vm_end
WARNING: mm/rmap.c:1682 folio_add_new_anon_rmap+0x5fe/0x14b0
Fix this by validating dst_addr against the reacquired VMA
bounds after mfill_get_vma() returns in mfill_copy_folio_retry().
Reported-by: syzbot+e24a2e34fad0efbac047@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=e24a2e34fad0efbac047
Signed-off-by: Deepanshu Kartikey <Kartikey406@gmail.com>
---
mm/userfaultfd.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index 9ffc80d0a51b..dbf16c9bcf6f 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -467,6 +467,16 @@ static int mfill_copy_folio_retry(struct mfill_state *state, struct folio *folio
if (err)
return err;
+ /*
+ * VMA may have been split while the lock was dropped for
+ * copy_from_user(). mfill_get_vma() only validates dst_start
+ * but not dst_addr (current page). Re-validate dst_addr against
+ * the reacquired VMA bounds before installing the PTE.
+ */
+ if (state->dst_addr < state->vma->vm_start ||
+ state->dst_addr >= state->vma->vm_end)
+ return -EFAULT;
+
err = mfill_get_pmd(state);
if (err)
return err;
--
2.43.0
next prev parent reply other threads:[~2026-03-16 5:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-15 19:09 [syzbot] [mm?] WARNING in folio_add_new_anon_rmap syzbot
2026-03-16 2:02 ` Forwarded: [PATCH] mm/userfaultfd: re-validate vma in mfill_atomic() loop under CONFIG_PER_VMA_LOCK syzbot
2026-03-16 5:11 ` syzbot [this message]
2026-03-16 6:19 ` [syzbot] [mm?] WARNING in folio_add_new_anon_rmap Harry Yoo
2026-03-16 6:58 ` syzbot
2026-03-16 11:01 ` Mike Rapoport
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=69b790f6.a00a0220.3b25d1.0021.GAE@google.com \
--to=syzbot+e24a2e34fad0efbac047@syzkaller.appspotmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=syzkaller-bugs@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.