From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,vschneid@redhat.com,vincent.guittot@linaro.org,
vbabka@kernel.org,surenb@google.com,stable@vger.kernel.org,
shakeel.butt@linux.dev,rppt@kernel.org,rostedt@goodmis.org,
puranjay@kernel.org,pfalcato@suse.de,peterz@infradead.org,mingo@redhat.com,
mhocko@suse.com,mgorman@suse.de,mason@kernel.org,liam@infradead.org,
kprateek.nayak@amd.com,kees@kernel.org,juri.lelli@redhat.com,
jannh@google.com,dietmar.eggemann@arm.com,david@kernel.org,
bsegall@google.com,ast@kernel.org,ljs@kernel.org,akpm@linux-foundation.org
Subject: [merged mm-hotfixes-stable] mm-vma-drop-mm-asynchronously-in-vma_start_read.patch removed from -mm tree
Date: Tue, 01 Dec 2026 19:47:54 -0800 [thread overview]
Message-ID: <20261202034754.924091F000C1@smtp.kernel.org> (raw)
In-Reply-To: <20261124-vma-read-lock-mmdrop-async-v1-1-257f99f551de@kernel.org>
The quilt patch titled
Subject: mm/vma: drop mm asynchronously in vma_start_read()
has been removed from the -mm tree. Its filename was
mm-vma-drop-mm-asynchronously-in-vma_start_read.patch
This patch was dropped because it was merged into the mm-hotfixes-stable branch
of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Subject: mm/vma: drop mm asynchronously in vma_start_read()
Date: Tue, 24 Nov 2026 12:26:19 +0000
Commit bee9ef4a40a2 ("bpf: switch task_vma iterator from mmap_lock to
per-VMA locks") open-codes a lock_next_vma() implementation that does
roughly the same thing in bpf_iter_task_vma_find_next(), only without
fallback to an mmap_lock.
This is because bpf_iter_task_vma_find_next() can be called from
non-sleepable contexts.
However, lock_vma_under_rcu() gave no guarantee as to which contexts it is
safe to be called from, and indeed it turns out this assumption is unsafe.
Since commit 9bbffee67ffd ("mm: fix a UAF when vma->mm is freed after
vma->vm_refcnt got dropped"), this call chain is possible on x86:
lock_vma_under_rcu()
-> vma_start_read()
-> mmdrop()
-> __mmdrop()
-> mm_free_pgd()
-> pgd_free()
-> pgd_dtor()
-> spin_lock(&pgd_lock)
Thus, a plain spin_lock() can occur when lock_vma_under_rcu() is
called. Since bpf_iter_task_vma_find_next() can be called in softirq
context, this can deadlock, for example:
pgd_alloc()
-> spin_lock(&pgd_lock)
<softirq>
bpf_iter_task_vma_next()
-> lock_vma_under_rcu()
...
-> spin_lock(&pgd_lock) [ DEADLOCK ]
Alexei Starovoitov also pointed out that a BPF program attached to
trace_contention_end() can similarly cause a deadlock:
pgd_alloc()
spin_lock(&pgd_lock)
queued_spin_lock_slowpath()
trace_contention_end() <- pgd_lock is held
tp_btf/contention_end prog
bpf_iter_task_vma_next()
lock_vma_under_rcu()
vma_start_read()
mmdrop(other_mm) <- last put takes pgd_lock again
Resolve the issue by having vma_start_read() use mmdrop_async() instead of
mmdrop() so the work is deferred to a work queue.
Make mmdrop_async() an internal mm function, defined in mm/internal.h, to
avoid abuse elsewhere (kernel/fork.c includes this header, so still retains
access).
Commit 0b16f8bed19c ("mm: change vma_start_read() to drop RCU lock on
failure") accounted for the fact that the RCU lock had to be dropped for
this operation, which is no longer applicable.
For the sake of a backported fix, retain this behaviour, however drop the
RCU lock last and remove the now irrelevant comment.
[akpm@linux-foundation.org: tweak comment, per Lorenzo]
Link: https://lore.kernel.org/awXHR007d8MlhJUC@gremlin
[akpm@linux-foundation.org: comment fixup, per Suren]
Link: https://lore.kernel.org/CAJuCfpEmFEX5iqLw_c94a97rVrC+xBWpKnO4rVpeDgkUfAPq7Q@mail.gmail.com
Link: https://patch.msgid.link/20261124-vma-read-lock-mmdrop-async-v1-1-257f99f551de@kernel.org
Link: https://lore.kernel.org/all/DN267JUKDRNS.2VMV07CQ58R4X@gmail.com/
Fixes: bee9ef4a40a2 ("bpf: switch task_vma iterator from mmap_lock to per-VMA locks")
Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reported-by: Chris Mason <mason@kernel.org>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Acked-by: Pedro Falcato <pfalcato@suse.de>
Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Reviewed-by: Liam R. Howlett (Google) <liam@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Benjamin Segall <bsegall@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Kees Cook <kees@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Jann Horn <jannh@google.com>
Cc: Puranjay Mohan <puranjay@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: <stable@vger.kernel.org>
kernel/fork.c | 16 ----------------
mm/internal.h | 3 +++
mm/mmap_lock.c | 25 ++++++++++++++++++++-----
3 files changed, 23 insertions(+), 21 deletions(-)
--- a/kernel/fork.c~mm-vma-drop-mm-asynchronously-in-vma_start_read
+++ a/kernel/fork.c
@@ -744,22 +744,6 @@ void __mmdrop(struct mm_struct *mm)
}
EXPORT_SYMBOL_GPL(__mmdrop);
-static void mmdrop_async_fn(struct work_struct *work)
-{
- struct mm_struct *mm;
-
- mm = container_of(work, struct mm_struct, async_put_work);
- __mmdrop(mm);
-}
-
-static void mmdrop_async(struct mm_struct *mm)
-{
- if (unlikely(atomic_dec_and_test(&mm->mm_count))) {
- INIT_WORK(&mm->async_put_work, mmdrop_async_fn);
- schedule_work(&mm->async_put_work);
- }
-}
-
static inline void free_signal_struct(struct signal_struct *sig)
{
taskstats_tgid_free(sig);
--- a/mm/internal.h~mm-vma-drop-mm-asynchronously-in-vma_start_read
+++ a/mm/internal.h
@@ -1692,4 +1692,7 @@ static inline bool can_spin_trylock(void
/* char-mem.c */
bool file_is_dev_zero(const struct file *file);
+/* mmap_lock.c */
+void mmdrop_async(struct mm_struct *mm);
+
#endif /* __MM_INTERNAL_H */
--- a/mm/mmap_lock.c~mm-vma-drop-mm-asynchronously-in-vma_start_read
+++ a/mm/mmap_lock.c
@@ -300,17 +300,16 @@ err:
err_unstable:
/*
* If vma got attached to another mm from under us, that mm is not
- * stable and can be freed in the narrow window after vma->vm_refcnt
+ * stable and can be reused in the narrow window after vma->vm_refcnt
* is dropped and before rcuwait_wake_up(mm) is called. Grab it before
* releasing vma->vm_refcnt.
*/
- other_mm = vma->vm_mm; /* use a copy as vma can be freed after we drop vm_refcnt */
+ other_mm = vma->vm_mm; /* use a copy as vma can be reused after we drop vm_refcnt */
- /* __mmdrop() is a heavy operation, do it after dropping RCU lock. */
- rcu_read_unlock();
mmgrab(other_mm);
vma_refcount_put(vma);
- mmdrop(other_mm);
+ mmdrop_async(other_mm);
+ rcu_read_unlock();
return NULL;
}
@@ -560,6 +559,22 @@ void __mm_reset_vma_seqcounts(struct mm_
}
EXPORT_SYMBOL(__mm_reset_vma_seqcounts);
+static void mmdrop_async_fn(struct work_struct *work)
+{
+ struct mm_struct *mm;
+
+ mm = container_of(work, struct mm_struct, async_put_work);
+ __mmdrop(mm);
+}
+
+void mmdrop_async(struct mm_struct *mm)
+{
+ if (unlikely(atomic_dec_and_test(&mm->mm_count))) {
+ INIT_WORK(&mm->async_put_work, mmdrop_async_fn);
+ schedule_work(&mm->async_put_work);
+ }
+}
+
#ifdef CONFIG_LOCK_MM_AND_FIND_VMA
#include <linux/extable.h>
_
Patches currently in -mm which might be from ljs@kernel.org are
mm-vma-predicate-vma_assert_stabilised-on-config_debug_vm.patch
mm-only-assert-mmap-locks-if-config_debug_vm-or-lockdep-is-set.patch
mm-only-assert-vma-locks-if-config_debug_vm-is-set.patch
mm-convert-warn_on_onces-to-vm_warn_on_once-in-vma-lock-code.patch
mm-madvise-zap-markers-from-guard-regions.patch
mm-mmap-free-gathered-pages-before-mmf_oom_skip.patch
percpu-fix-contig-hints-that-are-too-low.patch
percpu-search-the-whole-reserved-chunk.patch
xen-privcmd-convert-mmap-hook-to-mmap_prepare.patch
kvm-ppc-book3s-convert-spapr-tce-mmap-hook-to-mmap_prepare.patch
mshv_vtl-convert-mmap-hooks-to-mmap_prepare.patch
x86-sgx-convert-vepc-mmap-hook-to-mmap_prepare.patch
udf-convert-mmap-hook-to-mmap_prepare.patch
selinuxfs-convert-mmap-hooks-to-mmap_prepare.patch
xen-convert-xenstore-interface-mmap-hooks-to-mmap_prepare.patch
soc-aspeed-convert-lpc-and-p2a-control-mmap-hooks-to-mmap_prepare.patch
soc-qcom-rmtfs_mem-convert-mmap-hook-to-mmap_prepare.patch
tee-convert-shm-mmap-hook-to-mmap_prepare.patch
misc-bcm-vk-convert-mmap-hook-to-mmap_prepare.patch
ptp-vmclock-convert-mmap-hook-to-mmap_prepare.patch
vhost-vdpa-convert-mmap-hook-to-mmap_prepare.patch
mm-vma-error-out-on-invalid-bounds-in-unmapped_area_topdown.patch
mm-vma-lock-vmas-before-taking-mm_all_locks_mutex.patch
mm-filemap-convert-fault-and-readahead-logic-to-use-vma_flags_t.patch
mm-madvise-convert-madvise_vma_behavior-to-use-vma_flags_t.patch
mm-convert-miscellaneous-vma-flag-tests-to-use-vma_flags_t.patch
fs-proc-task_mmu-convert-vma-flag-tests-to-use-vma_flags_t.patch
fs-coredump-convert-vma_dump_size-to-use-vma_flags_t.patch
uprobes-convert-vma-flag-tests-to-use-vma_flags_t.patch
perf-convert-vma-flag-tests-to-use-vma_flags_t.patch
selinux-convert-vma-flag-tests-to-use-vma_flags_t.patch
apparmor-convert-vma-flag-tests-to-use-vma_flags_t.patch
ima-convert-vma-flag-tests-to-use-vma_flags_t.patch
ipe-convert-vma-flag-tests-to-use-vma_flags_t.patch
coda-never-point-a-files-f_mapping-at-a-containers-mapping.patch
fs-proc-task_mmu-write-protect-only-with-ptrace-attach.patch
prev parent reply other threads:[~2026-12-02 3:47 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 12:26 [PATCH] mm/vma: drop mm asynchronously in vma_start_read() Lorenzo Stoakes (ARM)
2026-11-24 13:04 ` Pedro Falcato
2026-11-24 15:46 ` Suren Baghdasaryan
2026-11-24 15:51 ` Suren Baghdasaryan
2026-11-24 15:58 ` Lorenzo Stoakes (ARM)
2026-11-24 16:05 ` Puranjay Mohan
2026-11-24 16:34 ` Suren Baghdasaryan
2026-11-24 17:23 ` Lorenzo Stoakes (ARM)
2026-11-24 17:33 ` Andrew Morton
2026-11-24 17:49 ` Suren Baghdasaryan
2026-11-24 18:35 ` Vlastimil Babka (SUSE)
2026-11-24 18:51 ` Lorenzo Stoakes (ARM)
2026-11-24 15:56 ` Lorenzo Stoakes (ARM)
2026-11-24 17:13 ` + mm-vma-drop-mm-asynchronously-in-vma_start_read.patch added to mm-hotfixes-unstable branch Andrew Morton
2026-11-24 18:37 ` [PATCH] mm/vma: drop mm asynchronously in vma_start_read() Vlastimil Babka (SUSE)
2026-12-02 3:47 ` Andrew Morton [this message]
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=20261202034754.924091F000C1@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=ast@kernel.org \
--cc=bsegall@google.com \
--cc=david@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=jannh@google.com \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=kprateek.nayak@amd.com \
--cc=liam@infradead.org \
--cc=ljs@kernel.org \
--cc=mason@kernel.org \
--cc=mgorman@suse.de \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=mm-commits@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=pfalcato@suse.de \
--cc=puranjay@kernel.org \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=shakeel.butt@linux.dev \
--cc=stable@vger.kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.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