Commit 0199390a authored by SeongJae Park's avatar SeongJae Park Committed by Andrew Morton
Browse files

mm/damon/sysfs: dealloc repeat_call_control if damon_call() fails

damon_call() for repeat_call_control of DAMON_SYSFS could fail if somehow
the kdamond is stopped before the damon_call().  It could happen, for
example, when te damon context was made for monitroing of a virtual
address processes, and the process is terminated immediately, before the
damon_call() invocation.  In the case, the dyanmically allocated
repeat_call_control is not deallocated and leaked.

Fix the leak by deallocating the repeat_call_control under the
damon_call() failure.

This issue is discovered by sashiko [1].

Link: https://lkml.kernel.org/r/20260327003224.55752-1-sj@kernel.org
Link: https://lore.kernel.org/20260320020630.962-1-sj@kernel.org

 [1]
Fixes: 04a06b13 ("mm/damon/sysfs: use dynamically allocated repeat mode damon_call_control")
Signed-off-by: default avatarSeongJae Park <sj@kernel.org>
Cc: <stable@vger.kernel.org>	[6.17+]
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent cece9dc6
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1670,7 +1670,8 @@ static int damon_sysfs_turn_damon_on(struct damon_sysfs_kdamond *kdamond)
	repeat_call_control->data = kdamond;
	repeat_call_control->repeat = true;
	repeat_call_control->dealloc_on_cancel = true;
	damon_call(ctx, repeat_call_control);
	if (damon_call(ctx, repeat_call_control))
		kfree(repeat_call_control);
	return err;
}