[RFC PATCH 6.1.y 2/2] mm/damon/sysfs: put target pids for apply_inputs() failure
From: SJ Park
Date: Wed Oct 28 2026 - 01:11:30 EST
damon_sysfs_build_ctx() invokes damon_sysfs_apply_inputs() for setting
damon_ctx object with user inputs. If it is configured for virtual
address spaces monitoring, the setup also increases reference counts of
monitoring target pids. If the setup is failed, damon_sysfs_build_ctx()
deallocates the damon_ctx object without decreasing the reference counts
of the pids. If the failure happened after increasing reference counts
of pids, the pids can be leaked.
Fix the leaks by decreasing the pid reference counts before deallocating
the damon_ctx object.
The issue was discovered [1] by Sashiko.
[1] https://lore.kernel.org/20260730040740.140836-1-sj@xxxxxxxxxx
Fixes: 74bd8b7d2f8e ("mm/damon/sysfs: move targets setup code to a separated function")
Cc: <stable@xxxxxxxxxxxxxxx> # 5.19.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 4b28bb9ba0a24..b9b80d58e5bd6 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -2515,6 +2515,7 @@ static struct damon_ctx *damon_sysfs_build_ctx(
err = damon_sysfs_apply_inputs(ctx, sys_ctx);
if (err) {
+ damon_sysfs_destroy_targets(ctx);
damon_destroy_ctx(ctx);
return ERR_PTR(err);
}
--
2.47.3