Skip to contentSkip to conversation

FAILED: patch "[PATCH] mm/damon/sysfs: fix param_ctx leak on" failed to apply to 6.18-stable tree

PATCH New [email protected] 2 participants 2 messages Mar 30 – Mar 31

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 7fe000eb32904758a85e62f6ea9483f89d5dabfc
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026033007-talon-immature-91a3@gregkh' --subject-prefix 'PATCH 6.18.y' HEAD^..

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 7fe000eb32904758a85e62f6ea9483f89d5dabfc Mon Sep 17 00:00:00 2001
From: Josh Law <[email protected]>
Date: Sat, 21 Mar 2026 10:54:24 -0700
Subject: [PATCH] mm/damon/sysfs: fix param_ctx leak on
damon_sysfs_new_test_ctx() failure

Patch series "mm/damon/sysfs: fix memory leak and NULL dereference issues", v4.

DAMON_SYSFS can leak memory under allocation failure, and do NULL pointer dereference when a privileged user make wrong sequences of control. Fix those.

This patch (of 3):

When damon_sysfs_new_test_ctx() fails in damon_sysfs_commit_input(), param_ctx is leaked because the early return skips the cleanup at the out label. Destroy param_ctx before returning.

mm/damon/sysfs.c +3 -1
index 576d1ddd736b..b573b9d60784 100644
@@ -1524,8 +1524,10 @@ static int damon_sysfs_commit_input(void *data)
 	if (IS_ERR(param_ctx))
 		return PTR_ERR(param_ctx);
 	test_ctx = damon_sysfs_new_test_ctx(kdamond->damon_ctx);
-	if (!test_ctx)
+	if (!test_ctx) {
+		damon_destroy_ctx(param_ctx);
 		return -ENOMEM;
+	}
 	err = damon_commit_ctx(test_ctx, param_ctx);
 	if (err)
 		goto out;
maintainer
#1 lore raw

PATCH 1/1 mm/damon/sysfs: fix param_ctx leak on damon_sysfs_new_test_ctx() failure

From: Josh Law <[email protected]>

Patch series "mm/damon/sysfs: fix memory leak and NULL dereference issues", v4.

DAMON_SYSFS can leak memory under allocation failure, and do NULL pointer dereference when a privileged user make wrong sequences of control. Fix those.

This patch (of 3):

When damon_sysfs_new_test_ctx() fails in damon_sysfs_commit_input(), param_ctx is leaked because the early return skips the cleanup at the out label. Destroy param_ctx before returning.

Fixes f0c5118ebb0e ("mm/damon/sysfs: catch commit test ctx alloc failure")
Cc <[email protected]> [6.18+]
(cherry picked from commit 7fe000eb32904758a85e62f6ea9483f89d5dabfc)
---
 mm/damon/sysfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
mm/damon/sysfs.c +3 -1
index dec9f5d0d512..3d410f9213ed 100644
@@ -1476,8 +1476,10 @@ static int damon_sysfs_commit_input(void *data)
 	if (IS_ERR(param_ctx))
 		return PTR_ERR(param_ctx);
 	test_ctx = damon_new_ctx();
-	if (!test_ctx)
+	if (!test_ctx) {
+		damon_destroy_ctx(param_ctx);
 		return -ENOMEM;
+	}
 	err = damon_commit_ctx(test_ctx, param_ctx);
 	if (err)
 		goto out;
Signature · 1 line
2.47.3