From: Andrei Vagin <avagin@google.com>
To: Mike Rapoport <rppt@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Andrei Vagin <avagin@google.com>,
syzbot+cf5ad2009a9bae03cb23@syzkaller.appspotmail.com
Subject: [PATCH] userfaultfd: fix lock leak in mfill_get_vma()
Date: Mon, 16 Mar 2026 17:38:28 +0000 [thread overview]
Message-ID: <20260316173829.1126728-1-avagin@google.com> (raw)
In mfill_get_vma(), both the per-VMA lock (via uffd_mfill_lock()) and
the map_changing_lock are acquired. However, state->vma was only
assigned at the very end of the function. If any validation checks
failed after lock acquisition but before this assignment, the function
would jump to the out_unlock label and call mfill_put_vma(state).
Since mfill_put_vma() only performs cleanup if state->vma is non-NULL,
these error paths would leak both the per-VMA lock and the
map_changing_lock.
Fixes: akpm:userfaultfd-retry-copying-with-locks-dropped-in-mfill_atomic_pte_copy.patch
Reported-by: syzbot+cf5ad2009a9bae03cb23@syzkaller.appspotmail.com
Signed-off-by: Andrei Vagin <avagin@google.com>
---
mm/userfaultfd.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index 9ffc80d0a51b..04f9e21fecf1 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -224,6 +224,7 @@ static int mfill_get_vma(struct mfill_state *state)
* request the user to retry later
*/
down_read(&ctx->map_changing_lock);
+ state->vma = dst_vma;
err = -EAGAIN;
if (atomic_read(&ctx->mmap_changing))
goto out_unlock;
@@ -246,7 +247,7 @@ static int mfill_get_vma(struct mfill_state *state)
goto out_unlock;
if (is_vm_hugetlb_page(dst_vma))
- goto out;
+ return 0;
ops = vma_uffd_ops(dst_vma);
if (!ops)
@@ -256,8 +257,6 @@ static int mfill_get_vma(struct mfill_state *state)
!ops->get_folio_noalloc)
goto out_unlock;
-out:
- state->vma = dst_vma;
return 0;
out_unlock:
--
2.53.0.851.ga537e3e6e9-goog
reply other threads:[~2026-03-16 17:38 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260316173829.1126728-1-avagin@google.com \
--to=avagin@google.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rppt@kernel.org \
--cc=syzbot+cf5ad2009a9bae03cb23@syzkaller.appspotmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox