From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44317563FBF; Wed, 9 Sep 2026 14:15:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788963358; cv=none; b=u1dfoTZ9xMQBij+H6KwC9kyEUqajSVAmoAf8UpkkQUzBqtUHPjCyFWI/5W4aO3TEOu+axNoDtMavylfTv4BxvLG5cP66V3/hlNKUabhnaSMQLqTzo1oFVPg1X7jRTfq40a4vPwL3etnl+wHvZlVNfj91E0EzxIJeXU2xyeaLhnE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788963358; c=relaxed/simple; bh=GwvaexlLVlMmbcRT2qHEg92mqVl5N7q6lwv0Y6WNy94=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T2nExrtdj7MSKzl0vvE0unViJ1O/CCC4JdwSYkBgBquyJd8eoJq4zw2rWZ6AZj0+TD+45Cl/M2VuIETMSz31zsEm9yGZA51Fz9V1rG8hJiD0Xt9iKTWudE4K2pccC4AaUBG6nbbBr9rLOsukKJw/ry5L5H1jJ6qNS9Ql0XMOCf0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=FtqdnzE6; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="FtqdnzE6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 605A21F00A3A; Wed, 9 Sep 2026 14:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788963356; bh=bWMKPkDvdQND+RmNWNDerTP1TKHY98qPmjTyPjOuxgg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FtqdnzE6fYOCH36j2zhonBzbwC735Y03qm15wrmtK7Z02p4WZNT4r9K8psPyj4q2u nVMUTs3f0sBL/NixMXocVgfuXNyDoAzHZmaBmDZlo/Oo4F2CVB2tzluhCA0U227ZzO ryS2Olt3Abm3LtJkPOyfpFRdebl4AvGJJa0wpWZc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, SJ Park , Zenghui Yu , Andrew Morton Subject: [PATCH 6.18 052/583] samples/damon/wsse: handle damon_start() failure Date: Wed, 9 Sep 2026 15:35:37 +0200 Message-ID: <20260909134239.776271422@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260909134237.773280130@linuxfoundation.org> References: <20260909134237.773280130@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: SJ Park commit e4742be45ea45bf554399ce89a09f71e525d7981 upstream. Patch series "samples/damon: handle damon_{start,stop}() failures". All DAMON sample modules are not correctly handling failures from damon_start(). Among those, mtier also has an additional problem for handling of damon_stop() failures. wsse and prcl also have a problem in their damon_call() failure handling. As a result, memory leaks, next DAMON operation disruptions, and use-after-free can happen. Fix those. Note that only the damon_start() failure caused issues can reliably be reproduced. Reproducing those issues require the admin permission, though. This patch (of 6): damon_sample_wsse_start() callers assume it will clean up resources when it fails. And the function does the cleanup for context buildup failures. However, it is not doing the cleanup for damon_start() failure. As a result, when damon_start() fails, it leaks the memory for DAMON context. Free the context in case of the failure to fix the issues. Note that the issue can reliably be reproduced because the module calls damon_start() in the exclusive mode. For example, $ sudo damo start $ echo $$ | sudo tee /sys/module/damon_sample_wsse/parameters/target_pid $ echo Y | sudo tee /sys/module/damon_sample_wsse/parameters/enabled $ sudo cat /proc/allocinfo | grep damon_new_ctx Because the first command is running another DAMON instance, the third command fails the damon_start() call because the new DAMON instance cannot exclusively run. And without this fix, by repeating the third and the fourth commands above, we can show the memory consumption is only increasing due to the leaks. It requires the sudo permission though. The issue was discovered [1] by Sashiko. Link: https://lore.kernel.org/20260628215447.96166-2-sj@kernel.org Link: https://lore.kernel.org/20260609145814.70163-1-sj@kernel.org [1] Fixes: b757c6cfc696 ("samples/damon/wsse: start and stop DAMON as the user requests") Signed-off-by: SJ Park Reviewed-by: Zenghui Yu Cc: # 6.14.x Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- samples/damon/wsse.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/samples/damon/wsse.c b/samples/damon/wsse.c index 799ad4443943..bbd9392ab5b3 100644 --- a/samples/damon/wsse.c +++ b/samples/damon/wsse.c @@ -87,8 +87,10 @@ static int damon_sample_wsse_start(void) target->pid = target_pidp; err = damon_start(&ctx, 1, true); - if (err) + if (err) { + damon_destroy_ctx(ctx); return err; + } repeat_call_control.data = ctx; return damon_call(ctx, &repeat_call_control); } -- 2.55.0