From: Dev Jain <dev.jain@arm.com>
To: Sasha Levin <sashal@kernel.org>,
akpm@linux-foundation.org, peterx@redhat.com
Cc: aarcange@redhat.com, surenb@google.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] mm/userfaultfd: fix missing PTE unmap for non-migration entries
Date: Mon, 30 Jun 2025 20:39:07 +0530 [thread overview]
Message-ID: <ff136c84-4406-4849-aaa3-46578ea444cb@arm.com> (raw)
In-Reply-To: <20250630031958.1225651-1-sashal@kernel.org>
On 30/06/25 8:49 am, Sasha Levin wrote:
> When handling non-swap entries in move_pages_pte(), the error handling
> for entries that are NOT migration entries fails to unmap the page table
> entries before jumping to the error handling label.
>
> This results in a kmap/kunmap imbalance which on CONFIG_HIGHPTE systems
> triggers a WARNING in kunmap_local_indexed() because the kmap stack is
> corrupted.
>
> Example call trace on ARM32 (CONFIG_HIGHPTE enabled):
> WARNING: CPU: 1 PID: 633 at mm/highmem.c:622 kunmap_local_indexed+0x178/0x17c
> Call trace:
> kunmap_local_indexed from move_pages+0x964/0x19f4
> move_pages from userfaultfd_ioctl+0x129c/0x2144
> userfaultfd_ioctl from sys_ioctl+0x558/0xd24
>
> The issue was introduced with the UFFDIO_MOVE feature but became more
> frequent with the addition of guard pages (commit 7c53dfbdb024 ("mm: add
> PTE_MARKER_GUARD PTE marker")) which made the non-migration entry code
> path more commonly executed during userfaultfd operations.
>
> Fix this by ensuring PTEs are properly unmapped in all non-swap entry
> paths before jumping to the error handling label, not just for migration
> entries.
>
> Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")
> Cc: stable@vger.kernel.org
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> mm/userfaultfd.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
> index 8253978ee0fb1..7c298e9cbc18f 100644
> --- a/mm/userfaultfd.c
> +++ b/mm/userfaultfd.c
> @@ -1384,14 +1384,15 @@ static int move_pages_pte(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd,
>
> entry = pte_to_swp_entry(orig_src_pte);
> if (non_swap_entry(entry)) {
> + pte_unmap(src_pte);
> + pte_unmap(dst_pte);
> + src_pte = dst_pte = NULL;
> if (is_migration_entry(entry)) {
> - pte_unmap(src_pte);
> - pte_unmap(dst_pte);
> - src_pte = dst_pte = NULL;
> migration_entry_wait(mm, src_pmd, src_addr);
> err = -EAGAIN;
> - } else
> + } else {
> err = -EFAULT;
> + }
> goto out;
Won't the out label take care of the unmapping? I think CONFIG_HIGHPTE
is involved in the explanation.
> }
>
next prev parent reply other threads:[~2025-06-30 15:09 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-30 3:19 Sasha Levin
2025-06-30 15:09 ` Dev Jain [this message]
2025-07-01 0:57 ` Andrew Morton
2025-07-08 15:10 ` David Hildenbrand
2025-07-08 15:32 ` Suren Baghdasaryan
2025-07-08 15:33 ` Sasha Levin
2025-07-08 15:39 ` Suren Baghdasaryan
2025-07-08 15:57 ` Sasha Levin
2025-07-08 16:34 ` Suren Baghdasaryan
2025-07-31 12:43 ` Sasha Levin
2025-07-08 15:42 ` David Hildenbrand
2025-07-31 12:37 ` Sasha Levin
2025-07-31 12:56 ` David Hildenbrand
2025-07-31 14:00 ` Suren Baghdasaryan
2025-07-31 14:07 ` Sasha Levin
2025-08-01 13:26 ` Sasha Levin
2025-08-01 14:06 ` David Hildenbrand
2025-08-01 14:13 ` David Hildenbrand
2025-08-01 14:24 ` Sasha Levin
2025-08-01 14:29 ` Sasha Levin
2025-08-07 19:51 ` Sasha Levin
2025-08-08 8:02 ` David Hildenbrand
2025-08-08 15:55 ` Sasha Levin
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=ff136c84-4406-4849-aaa3-46578ea444cb@arm.com \
--to=dev.jain@arm.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=peterx@redhat.com \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
--cc=surenb@google.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