* [PATCH] mm/damon/core: handle region split failure in apply_min_nr_regions()
@ 2026-07-18 16:37 SJ Park
2026-07-18 17:21 ` SJ Park
0 siblings, 1 reply; 2+ messages in thread
From: SJ Park @ 2026-07-18 16:37 UTC (permalink / raw)
To: Andrew Morton; +Cc: SJ Park, stable, damon, linux-kernel, linux-mm
damon_apply_min_nr_regions() repeatedly split each region until its size
becomes small enough to meet the user-defined low limit of the number of
regions. The loop assumes the split operation (damon_split_region_at())
will always succeed and create the new region. But the operation could
silently fail for memory allocation failures, for example. If such
failure happens and the region was the last region, the linked
list-based next region fetching returns invalid pointer. As a result,
invalid memory dereference and corruption could happen. Fix by breaking
the loop in the corner case.
The allocation failure is unlikely since it is arguably too small to
fail. But, it could still theoretically happen, and the consequence is
very bad.
This issue was discovered [1] by Sashiko.
[1] https://lore.kernel.org/20260717011834.120715-1-sj@kernel.org
Fixes: b1029f29eb1d ("mm/damon/core: split regions for min_nr_regions")
Cc: <stable@vger.kernel.org> # 7.1.x
Signed-off-by: SJ Park <sj@kernel.org>
---
Changes from RFC v1
- RFC v1: https://lore.kernel.org/20260718004301.88883-1-sj@kernel.org
- Drop RFC tag.
- Rebase to latest mm-new.
mm/damon/core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 20d267c615faf..3d829e0ad63b5 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1913,6 +1913,9 @@ static unsigned long damon_apply_min_nr_regions(struct damon_ctx *ctx)
damon_for_each_region_safe(r, next, t) {
while (damon_sz_region(r) > max_region_sz) {
damon_split_region_at(t, r, max_region_sz);
+ /* split might failed */
+ if (r == damon_last_region(t))
+ break;
r = damon_next_region(r);
}
}
base-commit: 5817557f6220462f0ca298b73e4b3f4bb91ccd1f
--
2.47.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mm/damon/core: handle region split failure in apply_min_nr_regions()
2026-07-18 16:37 [PATCH] mm/damon/core: handle region split failure in apply_min_nr_regions() SJ Park
@ 2026-07-18 17:21 ` SJ Park
0 siblings, 0 replies; 2+ messages in thread
From: SJ Park @ 2026-07-18 17:21 UTC (permalink / raw)
To: SJ Park; +Cc: Andrew Morton, stable, damon, linux-kernel, linux-mm
On Sat, 18 Jul 2026 09:37:06 -0700 SJ Park <sj@kernel.org> wrote:
> damon_apply_min_nr_regions() repeatedly split each region until its size
> becomes small enough to meet the user-defined low limit of the number of
> regions. The loop assumes the split operation (damon_split_region_at())
> will always succeed and create the new region. But the operation could
> silently fail for memory allocation failures, for example. If such
> failure happens and the region was the last region, the linked
> list-based next region fetching returns invalid pointer. As a result,
> invalid memory dereference and corruption could happen. Fix by breaking
> the loop in the corner case.
Sashiko found a room to improve in this patch. I will post a new revision with
the improvement. Please don't add this to mm-new.
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-18 17:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-18 16:37 [PATCH] mm/damon/core: handle region split failure in apply_min_nr_regions() SJ Park
2026-07-18 17:21 ` SJ Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox