* [PATCH v2] mm: memcg: initialize *locked in memcg1_oom_prepare() stub
@ 2026-07-16 13:42 Breno Leitao
2026-07-17 0:39 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Breno Leitao @ 2026-07-16 13:42 UTC (permalink / raw)
To: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
Muchun Song, Andrew Morton
Cc: Michal Hocko, cgroups, linux-mm, linux-kernel, kernel-team,
stable, Joshua Hahn, SeongJae Park, Breno Leitao
mem_cgroup_oom() passes an uninitialized "locked" to memcg1_oom_prepare()
and reads it back in memcg1_oom_finish():
bool locked, ret;
...
if (!memcg1_oom_prepare(memcg, &locked))
return false;
ret = mem_cgroup_out_of_memory(memcg, mask, order);
memcg1_oom_finish(memcg, locked);
This relies on memcg1_oom_prepare() setting *locked whenever it returns
true. The CONFIG_MEMCG_V1=y version does, but the stub used when
CONFIG_MEMCG_V1=n returns true without touching *locked, so
memcg1_oom_finish() consumes an uninitialized value. On a memcg OOM this
is reported by UBSAN:
UBSAN: invalid-load in mm/memcontrol.c:1932:27
load of value 0 is not a valid value for type 'bool' (aka '_Bool')
Initialize *locked to false in the stub; with cgroup v1 compiled out
there is no OOM lock to take.
Fixes: e93d4166b40a ("mm: memcg: put cgroup v1-specific code under a config option")
Cc: stable@vger.kernel.org
Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: SeongJae Park <sj@kernel.org>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Signed-off-by: Breno Leitao <leitao@debian.org>
---
Changes in v2:
- added the reviews and acks.
- Link to v1: https://lore.kernel.org/r/20260626-memcg-oom-uninit-locked-v1-1-a00175936b39@debian.org
---
mm/memcontrol-v1.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/mm/memcontrol-v1.h b/mm/memcontrol-v1.h
index d3ed5b93290fb..0f703f239c80f 100644
--- a/mm/memcontrol-v1.h
+++ b/mm/memcontrol-v1.h
@@ -101,7 +101,11 @@ static inline void memcg1_remove_from_trees(struct mem_cgroup *memcg) {}
static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg) {}
static inline void memcg1_css_offline(struct mem_cgroup *memcg) {}
-static inline bool memcg1_oom_prepare(struct mem_cgroup *memcg, bool *locked) { return true; }
+static inline bool memcg1_oom_prepare(struct mem_cgroup *memcg, bool *locked)
+{
+ *locked = false;
+ return true;
+}
static inline void memcg1_oom_finish(struct mem_cgroup *memcg, bool locked) {}
static inline void memcg1_oom_recover(struct mem_cgroup *memcg) {}
---
base-commit: b8809969e1d7a591e0f49dd464a5d04b3cf02ab1
change-id: 20260626-memcg-oom-uninit-locked-5ec79dff4396
Best regards,
--
Breno Leitao <leitao@debian.org>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] mm: memcg: initialize *locked in memcg1_oom_prepare() stub
2026-07-16 13:42 [PATCH v2] mm: memcg: initialize *locked in memcg1_oom_prepare() stub Breno Leitao
@ 2026-07-17 0:39 ` Andrew Morton
2026-07-17 10:52 ` Johannes Weiner
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2026-07-17 0:39 UTC (permalink / raw)
To: Breno Leitao
Cc: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
Muchun Song, Michal Hocko, cgroups, linux-mm, linux-kernel,
kernel-team, stable, Joshua Hahn, SeongJae Park
On Thu, 16 Jul 2026 06:42:18 -0700 Breno Leitao <leitao@debian.org> wrote:
> mem_cgroup_oom() passes an uninitialized "locked" to memcg1_oom_prepare()
> and reads it back in memcg1_oom_finish():
>
> bool locked, ret;
> ...
> if (!memcg1_oom_prepare(memcg, &locked))
> return false;
> ret = mem_cgroup_out_of_memory(memcg, mask, order);
> memcg1_oom_finish(memcg, locked);
>
> This relies on memcg1_oom_prepare() setting *locked whenever it returns
> true. The CONFIG_MEMCG_V1=y version does, but the stub used when
> CONFIG_MEMCG_V1=n returns true without touching *locked, so
> memcg1_oom_finish() consumes an uninitialized value. On a memcg OOM this
> is reported by UBSAN:
>
> UBSAN: invalid-load in mm/memcontrol.c:1932:27
> load of value 0 is not a valid value for type 'bool' (aka '_Bool')
>
> Initialize *locked to false in the stub; with cgroup v1 compiled out
> there is no OOM lock to take.
Thanks.
Sashiko, as is its wont, reminds us that we all suck:
https://sashiko.dev/#/patchset/20260716-memcg-oom-uninit-locked-v2-1-63631d878eb4@debian.org
Does this potential memcg issue look legit?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] mm: memcg: initialize *locked in memcg1_oom_prepare() stub
2026-07-17 0:39 ` Andrew Morton
@ 2026-07-17 10:52 ` Johannes Weiner
0 siblings, 0 replies; 3+ messages in thread
From: Johannes Weiner @ 2026-07-17 10:52 UTC (permalink / raw)
To: Andrew Morton
Cc: Breno Leitao, Michal Hocko, Roman Gushchin, Shakeel Butt,
Muchun Song, Michal Hocko, cgroups, linux-mm, linux-kernel,
kernel-team, stable, Joshua Hahn, SeongJae Park
On Thu, Jul 16, 2026 at 05:39:49PM -0700, Andrew Morton wrote:
> On Thu, 16 Jul 2026 06:42:18 -0700 Breno Leitao <leitao@debian.org> wrote:
>
> > mem_cgroup_oom() passes an uninitialized "locked" to memcg1_oom_prepare()
> > and reads it back in memcg1_oom_finish():
> >
> > bool locked, ret;
> > ...
> > if (!memcg1_oom_prepare(memcg, &locked))
> > return false;
> > ret = mem_cgroup_out_of_memory(memcg, mask, order);
> > memcg1_oom_finish(memcg, locked);
> >
> > This relies on memcg1_oom_prepare() setting *locked whenever it returns
> > true. The CONFIG_MEMCG_V1=y version does, but the stub used when
> > CONFIG_MEMCG_V1=n returns true without touching *locked, so
> > memcg1_oom_finish() consumes an uninitialized value. On a memcg OOM this
> > is reported by UBSAN:
> >
> > UBSAN: invalid-load in mm/memcontrol.c:1932:27
> > load of value 0 is not a valid value for type 'bool' (aka '_Bool')
> >
> > Initialize *locked to false in the stub; with cgroup v1 compiled out
> > there is no OOM lock to take.
>
> Thanks.
>
> Sashiko, as is its wont, reminds us that we all suck:
> https://sashiko.dev/#/patchset/20260716-memcg-oom-uninit-locked-v2-1-63631d878eb4@debian.org
>
> Does this potential memcg issue look legit?
Yes, it looks legit to me. The task is meant to be put to sleep after
this until current->memcg_in_oom is cleared. But sleep-and-clear
happens on userspace resume and there can be multiple allocs before.
Is it worth fixing? It's a deprecated feature inside a deprecated
feature (6df4ad704707 ("memcg: initiate deprecation of oom_control"),
August 2024). Maybe we just ought to delete all this...
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-17 10:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-16 13:42 [PATCH v2] mm: memcg: initialize *locked in memcg1_oom_prepare() stub Breno Leitao
2026-07-17 0:39 ` Andrew Morton
2026-07-17 10:52 ` Johannes Weiner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox