diff options
| author | Shakeel Butt <shakeel.butt@linux.dev> | 2026-11-10 16:09:13 -0800 |
|---|---|---|
| committer | Andrew Morton <akpm@linux-foundation.org> | 2026-11-22 22:24:11 -0800 |
| commit | 9436a736a148e3499cc1932b866d840803fbf764 (patch) | |
| tree | 70a4fab58a4a1962ebbfa11dd1c421ce228e41f8 /tools/perf/scripts/python/bin | |
| parent | f6f10d976c8ad7c96c33eb90ef071e15f79010b6 (diff) | |
mm: mglru: splice all generations when reparenting a memcg
Noah reported list_del corruption on single-node hosts running 7.2.11,
which already has commit bf4ade7dbd76 ("memcg: keep folio's objcg same as
its node"). The bad pointer is an MGLRU list head in a freed
mem_cgroup_per_node:
slab mem_cgroup_per_node start ff31bfa36a3c9e00 pointer offset 528 size 1920
list_del corruption. next->prev should be ffacf881ccc70e08, but was ff31bfa36a3ca010. (next=ff31bfa36a3ca010)
When a memcg goes offline, __lru_gen_reparent_memcg() moves its MGLRU
lists to the parent. It moves only the generations (gens) from min_seq to
max_seq, and it puts each list at the same index in the parent.
A folio's gen in folio->flags can be ahead of the list it is on. In the
parent, the same index can stand for an older gen, so the folio's gen can
end up older than its list. Once the parent's min_seq passes that gen,
sort_folio() puts the folio on the list for max_seq + 1, where it stays
until the next aging.
If the parent goes offline before that aging, the folio is not moved to
the grandparent. It stays on the parent's list after the parent is freed,
and the next list_del() on it touches freed memory. This needs two
cgroups on one branch to go offline one after the other, such as a
container and then its pod.
The parent always has MAX_NR_GENS gens at this point, so every index is
valid in it. Move all MAX_NR_GENS lists, not only the gens from min_seq
to max_seq.
A reproducer that drives these steps through the lru_gen debugfs file gets
a KASAN use-after-free on the freed mem_cgroup_per_node without this
patch, and no report with it.
Link: https://patch.msgid.link/20261111000913.22943-1-shakeel.butt@linux.dev
Fixes: f304652609ea ("mm: vmscan: prepare for reparenting MGLRU folios")
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reported-by: Noah Feldt <noah@feldt.systems>
Closes: https://lore.kernel.org/all/20261110132853.71228-1-noah@feldt.systems/
Reviewed-by: Kairui Song <kasong@tencent.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Tested-by: Noah Feldt <noah@feldt.systems>
Link: https://lore.kernel.org/20261115124954.7146-1-noah@feldt.systems
Reviewed-by: Barry Song <baohua@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Qi Zheng <qi.zheng@linux.dev>
Cc: Kairui Song <ryncsn@gmail.com>
Cc: <stable@vger.kernel.org>
mm/vmscan.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
Diffstat (limited to 'tools/perf/scripts/python/bin')
0 files changed, 0 insertions, 0 deletions
