[PATCH 6.12.y 1/2] mm/damon/sysfs: put target pids for damon_start() failure
From: SJ Park
Date: Wed Oct 28 2026 - 10:12:10 EST
damon_sysfs_turn_damon_on() allocates and sets up damon_ctx to start.
If it is for virtual address space monitoring, the setup increases the
reference counts of the target pids. After the setup, the function
invokes damon_start(). If damon_start() fails, it deallocates the
damon_ctx object without decreasing the reference counts of target pids.
As a result, pids can be leaked.
Fix the leak by putting pids using damon_sysfs_destroy_targets() before
deallocating the damon_ctx object.
Fixes: a61ea561c871 ("mm/damon/sysfs: link DAMON for virtual address spaces monitoring")
Cc: <stable@xxxxxxxxxxxxxxx> # 5.18.x
Signed-off-by: SJ Park <sj@xxxxxxxxxx>
---
mm/damon/sysfs.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index 5aa23c6545cb8..107a28557afe2 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -1519,6 +1519,7 @@ static int damon_sysfs_turn_damon_on(struct damon_sysfs_kdamond *kdamond)
return PTR_ERR(ctx);
err = damon_start(&ctx, 1, false);
if (err) {
+ damon_sysfs_destroy_targets(ctx);
damon_destroy_ctx(ctx);
return err;
}
--
2.47.3