mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 6.1.y 0/2] mm/damon/sysfs: fix pid leaks from wrong error handlings
@ 2026-10-28 14:17 SJ Park
  2026-10-28 14:17 ` [PATCH 6.1.y 1/2] mm/damon/sysfs: put target pids for damon_start() failure SJ Park
  2026-10-28 14:17 ` [PATCH 6.1.y 2/2] mm/damon/sysfs: put target pids for apply_inputs() failure SJ Park
  0 siblings, 2 replies; 3+ messages in thread
From: SJ Park @ 2026-10-28 14:17 UTC (permalink / raw)
  To: stable; +Cc: SJ Park, Andrew Morton, damon, linux-kernel, linux-mm

DAMON sysfs interface can leak pids due to wrong error handlings.  The
issue in the mainline has been fixed with code refactoring.  The
refactoring is done with commits including 7114bc5e01cf ("mm/damon/core:
add cleanup_target() ops callback").   Porting all the refactoring
changes to old stable kernels will be challenging.  Hence submitting
this non-mainline hotfix series.

Changes from RFC
- RFC: https://lore.kernel.org/20261028051104.154232-1-sj@kernel.org
- Drop RFC tag.

SJ Park (2):
  mm/damon/sysfs: put target pids for damon_start() failure
  mm/damon/sysfs: put target pids for apply_inputs() failure

 mm/damon/sysfs.c | 2 ++
 1 file changed, 2 insertions(+)


base-commit: 2d552c13645b4174829d2e131c6f6483a5111b6f
-- 
2.47.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 6.1.y 1/2] mm/damon/sysfs: put target pids for damon_start() failure
  2026-10-28 14:17 [PATCH 6.1.y 0/2] mm/damon/sysfs: fix pid leaks from wrong error handlings SJ Park
@ 2026-10-28 14:17 ` SJ Park
  2026-10-28 14:17 ` [PATCH 6.1.y 2/2] mm/damon/sysfs: put target pids for apply_inputs() failure SJ Park
  1 sibling, 0 replies; 3+ messages in thread
From: SJ Park @ 2026-10-28 14:17 UTC (permalink / raw)
  To: stable; +Cc: SJ Park, Andrew Morton, damon, linux-kernel, linux-mm

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@vger.kernel.org> # 5.18.x
Signed-off-by: SJ Park <sj@kernel.org>
---
 mm/damon/sysfs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index 9a918f8e4c6bf..4b28bb9ba0a24 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -2547,6 +2547,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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 6.1.y 2/2] mm/damon/sysfs: put target pids for apply_inputs() failure
  2026-10-28 14:17 [PATCH 6.1.y 0/2] mm/damon/sysfs: fix pid leaks from wrong error handlings SJ Park
  2026-10-28 14:17 ` [PATCH 6.1.y 1/2] mm/damon/sysfs: put target pids for damon_start() failure SJ Park
@ 2026-10-28 14:17 ` SJ Park
  1 sibling, 0 replies; 3+ messages in thread
From: SJ Park @ 2026-10-28 14:17 UTC (permalink / raw)
  To: stable; +Cc: SJ Park, Andrew Morton, damon, linux-kernel, linux-mm

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@kernel.org

Fixes: 74bd8b7d2f8e ("mm/damon/sysfs: move targets setup code to a separated function")
Cc: <stable@vger.kernel.org> # 5.19.x
Signed-off-by: SJ Park <sj@kernel.org>
---
 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-28 14:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-28 14:17 [PATCH 6.1.y 0/2] mm/damon/sysfs: fix pid leaks from wrong error handlings SJ Park
2026-10-28 14:17 ` [PATCH 6.1.y 1/2] mm/damon/sysfs: put target pids for damon_start() failure SJ Park
2026-10-28 14:17 ` [PATCH 6.1.y 2/2] mm/damon/sysfs: put target pids for apply_inputs() failure SJ Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®