From: Michal Hocko <mhocko@suse.com>
To: Joshua Hahn <joshua.hahnjy@gmail.com>
Cc: David Hildenbrand <david@kernel.org>,
David Rientjes <rientjes@google.com>,
Ben Gardon <bgardon@google.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, LKML <linux-kernel@vger.kernel.org>,
Chris Mason <mason@kernel.org>
Subject: Re: [PATCH 01/10] memcg-v1, oom: do not sleep in worker contexts
Date: Wed, 2 Dec 2026 22:28:34 +0100 [thread overview]
Message-ID: <axCNgqe_sdvlbQFk@tiehlicka> (raw)
In-Reply-To: <20261202191536.565275-1-joshua.hahnjy@gmail.com>
On Wed 02-12-26 12:21:55, Joshua Hahn wrote:
> On Wed, Dec 02, 2026 at 10:53:54AM +0100, Michal Hocko wrote:
> > From: Michal Hocko <mhocko@suse.com>
> >
> > SVA device faults at the limit of a v1 memcg with the OOM killer
> > disabled can leak a css reference, or cause a use-after-free of the
> > memcg.
> >
> > handle_mm_fault() enables the memcg OOM handling for FAULT_FLAG_USER, so
> > a failed charge can leave a css reference in current->memcg_in_oom. On
> > VM_FAULT_OOM the caller has to drop it in pagefault_out_of_memory(). But
> > iommu_sva_handle_mm() sets the flag for faults that it handles in a
> > kworker, and never makes that call. The pointer stays on the kworker,
> > and fork copies it to usermode helpers without a reference:
> >
> > kworker usermode helper
> > ======= ===============
> > iommu_sva_handle_mm()
> > memcg1_oom_prepare()
> > css_get()
> > current->memcg_in_oom = memcg
> > call_usermodehelper_exec_work()
> > dup_task_struct()
> > handle_mm_fault()
> > css_put()
> > iommu_sva_handle_mm()
> > handle_mm_fault()
> > css_put()
> >
> > Fix this by explicitly avoid oom_disabled path for workers. This would
> > simply fail the charge and bail out without triggering the oom killer
> > same as if this happened outside of #PF handler.
>
> Hi Michal, I hope you are doing well. Thank you for the fix!
>
> This was a fun fix to review because I wasn't entirely familiar with how
> v1 handles OOMs when the killer is disabled, so I got to learn about
> this mechanism.
Thanks for the review. Yes, this feature is quite tricky because it has
loose ends quite far away and a unusual worker context change while
sleeping inside a worker makes this hard to spot.
> The fix looks good to me, thanks!
> Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>
>
> And I also reproduced the issue and saw that I would get a KASAN
> slab-use-after-free before, but no such error with this patch applied.
> I don't have easy access to real IOMMU or SVA devices, so I wrote a
> module to exercise the path that you note in the commit. It just
> mimics iommu_sva_handle_mm().
> Tested-by: Joshua Hahn <joshua.hahnjy@gmail.com>
Yes, this is the most trivial way to trigger that. Thanks for trying.
> > Fixes: fc36479db74e ("iommu: Add a page fault handler")
> > Cc: stable
> > Reported-by: Chris Mason <mason@kernel.org>
> > Signed-off-by: Michal Hocko <mhocko@suse.com>
> > ---
> > mm/memcontrol-v1.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c
> > index b7f286888507..f2391eea4e0d 100644
> > --- a/mm/memcontrol-v1.c
> > +++ b/mm/memcontrol-v1.c
> > @@ -1100,7 +1100,8 @@ bool memcg1_oom_prepare(struct mem_cgroup *memcg, bool *locked)
> > * victim and then we have to bail out from the charge path.
> > */
> > if (READ_ONCE(memcg->oom_kill_disable)) {
> > - if (current->in_user_fault) {
> > + if (current->in_user_fault &&
> > + !(current->flags & (PF_WQ_WORKER|PF_IO_WORKER))) {
> > css_get(&memcg->css);
> > current->memcg_in_oom = memcg;
> > }
> > --
> > 2.56.1
> >
> >
--
Michal Hocko
SUSE Labs
next prev parent reply other threads:[~2026-12-02 21:28 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 9:53 [PATCH 0/10] assorted oom fixes Michal Hocko
2026-12-02 9:53 ` [PATCH 01/10] memcg-v1, oom: do not sleep in worker contexts Michal Hocko
2026-12-02 20:21 ` Joshua Hahn
2026-12-02 21:28 ` Michal Hocko [this message]
2026-12-02 9:53 ` [PATCH 02/10] mm/oom_kill: keep the allocating mm eligible Michal Hocko
2026-12-02 9:53 ` [PATCH 03/10] mm, oom: do not panic on constrained OOMs Michal Hocko
2026-12-02 9:53 ` [PATCH 04/10] mm/oom_kill: ratelimit memcg OOM reports with no victim Michal Hocko
2026-12-02 9:53 ` [PATCH 05/10] mm, oom: thaw tasks sharing the mm with the oom victim Michal Hocko
2026-12-02 16:30 ` sashiko-bot
2026-12-02 19:23 ` Michal Hocko
2026-12-02 9:53 ` [PATCH 06/10] mm, oom: check oom victims prior to numa placement Michal Hocko
2026-12-02 9:54 ` [PATCH 07/10] memcg, oom: wait for rcu_call callbacks before retrying reclaim Michal Hocko
2026-12-02 16:31 ` sashiko-bot
2026-12-02 19:38 ` Michal Hocko
2026-12-02 19:22 ` Harry Yoo
2026-12-02 19:33 ` Michal Hocko
2026-12-02 9:54 ` [PATCH 08/10] mm, " Michal Hocko
2026-12-02 16:31 ` sashiko-bot
2026-12-02 19:44 ` Michal Hocko
2026-12-02 9:54 ` [PATCH 09/10] mm, oom: add rcu_barrier before hiding victim from the oom killer Michal Hocko
2026-12-02 16:31 ` sashiko-bot
2026-12-02 19:53 ` Michal Hocko
2026-12-02 19:57 ` Lorenzo Stoakes (ARM)
2026-12-02 21:21 ` [PATCH v2] " Michal Hocko
2026-12-02 9:54 ` [PATCH 10/10] memcg: wake v1 OOM lock contenders on unlock Michal Hocko
2026-12-02 13:06 ` [PATCH 0/10] assorted oom fixes David Hildenbrand (Arm)
2026-12-02 19:01 ` Michal Hocko
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=axCNgqe_sdvlbQFk@tiehlicka \
--to=mhocko@suse.com \
--cc=akpm@linux-foundation.org \
--cc=bgardon@google.com \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=joshua.hahnjy@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mason@kernel.org \
--cc=rientjes@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