6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: SJ Park 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: # 5.18.x Signed-off-by: SJ Park Signed-off-by: Sasha Levin --- mm/damon/sysfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index ad9fa8a86c9ef..b3ce45d66ac65 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1538,6 +1538,7 @@ static int damon_sysfs_turn_damon_on(struct damon_sysfs_kdamond *kdamond) } err = damon_start(&ctx, 1, false); if (err) { + damon_sysfs_destroy_targets(ctx); damon_destroy_ctx(ctx); return err; } -- 2.53.0