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 CDFBE46D09A; Tue, 21 Jul 2026 19:57:14 +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=1784663835; cv=none; b=diCYZ7iInGR15n8ZpZaETnjRW5jCKa0Ynp3wUnuufULO725cmw7GGuWJOaOJqBpeEN/RkxOLxhXaO1ibEyogrynlxAnm0m6QLE15+pKoYyPKTp3H1yT1QD0GGIOy/SaZ63jPI252jF6VB1C15Iz/yndTfeYDmDOb51pxlNVWA4U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784663835; c=relaxed/simple; bh=wI0BhyoqZNIj+EkPE5masa+0N1427qnfTUH5J5zNQjw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MN+WFUqYz8LLJ+SOs/EPuTl5dQ37BCk7fmR6YJjir6k7k5viV48an8Y4mUuK+rSQs4L8QuLePn6K+6ZJ/d3RhlqXmiK4Ziuz5LJsJee3q6k4KmESfz0/I9fMa7Rp5+lZwUTUbYvreEp6Do3HpI3vbDgrhxs6JPY9ZI0wZUcu/4k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JVjQNpRW; 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="JVjQNpRW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F2951F00A3A; Tue, 21 Jul 2026 19:57:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784663834; bh=kkNkcsCTIeppQKACWd20MsE2xb1N10rY6q07pNqkgrY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JVjQNpRW5hQh/qJ3R2kA1HsrAYXp6yUQhKvcQuL4tJqxWJfmG4htdH1XfwkaQKc+z SczrqdJsysFbyb0SFyQAGK8pUNdVWM0ZnKCGk9mhrsx09kWLzb26KYo8a2HY/cUp0k W9PwJe2S13Fy8+gWdH4SyCpP0z7sFpUrIFpTQ7Ew= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, SeongJae Park , Andrew Morton Subject: [PATCH 6.12 0930/1276] mm/damon/sysfs-schemes: fix dir put orders in access_pattern_add_dirs() Date: Tue, 21 Jul 2026 17:22:53 +0200 Message-ID: <20260721152506.842706114@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152446.065700225@linuxfoundation.org> References: <20260721152446.065700225@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: SeongJae Park commit d58fdbe37a829fd2e5803dd4e5a72992dd8c5368 upstream. Patch series "mm/damon/sysfs-schemes: fix wrong directories put orders in error paths". Error paths of damon_sysfs_access_pattern_add_dirs() and damon_sysfs_scheme_add_dirs() functions put references to directories in wrong orders. As a result, uninitialized memory dereference and/or memory leak can happen. Fix those. This patch (of 2): In access_pattern_add_dirs(), error handling path puts references starting from setup failed directories. If the failure happpened from the initial allication in the setup functions, uninitialized memory dereference happen. The allocation failures will not commonly happen, but the consequence is quite bad. Fix the wrong reference put orders. The issue was discovered [1] by Sashiko. Link: https://lore.kernel.org/20260618005650.83868-2-sj@kernel.org Link: https://lore.kernel.org/20260617060005.86852-1-sj@kernel.org [1] Fixes: 7e84b1f8212a ("mm/damon/sysfs: support DAMON-based Operation Schemes") Signed-off-by: SeongJae Park Cc: # 5.18.x Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/damon/sysfs-schemes.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1393,22 +1393,19 @@ static int damon_sysfs_access_pattern_ad err = damon_sysfs_access_pattern_add_range_dir(access_pattern, &access_pattern->sz, "sz"); if (err) - goto put_sz_out; + return err; err = damon_sysfs_access_pattern_add_range_dir(access_pattern, &access_pattern->nr_accesses, "nr_accesses"); if (err) - goto put_nr_accesses_sz_out; + goto put_sz_out; err = damon_sysfs_access_pattern_add_range_dir(access_pattern, &access_pattern->age, "age"); if (err) - goto put_age_nr_accesses_sz_out; + goto put_nr_accesses_sz_out; return 0; -put_age_nr_accesses_sz_out: - kobject_put(&access_pattern->age->kobj); - access_pattern->age = NULL; put_nr_accesses_sz_out: kobject_put(&access_pattern->nr_accesses->kobj); access_pattern->nr_accesses = NULL;