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 F1D1140926A; Tue, 21 Jul 2026 19:55:21 +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=1784663723; cv=none; b=X7dQihdPxPUcNIdaPNJCAHSM40z4mjJ1PyzXJbabXJizeyaGKpqOyRGSXqt4dhlwdPy7L3MwCDiQ0ptEemuQQ8s5kuEjbfNTWu1JCr5VRK54ehxUb3b6OvCWngXXxemUPp43Pl2xM7pb1uLxeprEMvc1i5EmpRit1WxMNMnUqd8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784663723; c=relaxed/simple; bh=dCCsCgL9RXUdZv82DJwfL0yiHX1S//jBpi3bZj/GS34=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pU9DYNGHaBx6MemgjDCTlh4RBJyg5Kvh1TW1uVvrmNZc6X91AmMuIN9GD5xooOszlXGnZlFC8lps+Mqub5SVpguMAsMYR1B7XAHb8eJ3cjqwLfLJONvs8BU1z+QQL9fL/G42RQLh1H1tdFQ6dfC+K3Jtld/y2ujhJ08SlstrOe8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=wbpkhz8a; 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="wbpkhz8a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63E4C1F00A3A; Tue, 21 Jul 2026 19:55:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784663721; bh=2r8PtqJsjaqyOC+TOza0k/+cqg69YS9yB+dr7q8gYvc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=wbpkhz8aP2Mss0ZM4dbPXn8kHD08LoafL9FCSYp13SQBfEbXVh5HZuTWIPedinPYB 8fuY87CjOrnnvb7mUcCSyhRu0PnKmvBXZ72qf8quqAqoISHv4qgTVWUHBeR4+gMJV+ I3+aMjeS94KzpSfg8nxclcKOgLc/+r/ZMmikyKko= 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 0931/1276] mm/damon/sysfs-schemes: put stats for scheme_add_dirs() internal error Date: Tue, 21 Jul 2026 17:22:54 +0200 Message-ID: <20260721152506.864437941@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 05ea83ee88ca70f8932906d9f2617ff996f45b50 upstream. damon_sysfs_scheme_add_dirs() setup the tried_regions directory after the stats directory setup is completed. When the tried_regions directory setup is failed, the setup function ensures the reference for the tried regions directory is released. Hence the error path should put references on setup succeeded directory objects, starting from the stats directory. However, the error path is putting the tried_regions directory instead of the stats directory. As a direct result, the stats directory object is leaked. Worse yet, if the tried_regions directory setup failed from the initial allocation, the scheme->tried_regions field remains uninitialized. The following kobject_put(&scheme->tried_regions->kobj) call in the error path will dereference the uninitialized memory. The setup failures should not be common. But once it happens, the consequence is quite bad. Fix this issue by correctly putting the stats directory instead of the tried_regions directory. The issue was discovered [1] by Sashiko. Link: https://lore.kernel.org/20260618005650.83868-3-sj@kernel.org Link: https://lore.kernel.org/20260617005223.96813-1-sj@kernel.org [1] Fixes: 5181b75f438d ("mm/damon/sysfs-schemes: implement schemes/tried_regions directory") Signed-off-by: SeongJae Park Cc: # 6.2.x Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/damon/sysfs-schemes.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1624,12 +1624,12 @@ static int damon_sysfs_scheme_add_dirs(s goto put_filters_watermarks_quotas_access_pattern_out; err = damon_sysfs_scheme_set_tried_regions(scheme); if (err) - goto put_tried_regions_out; + goto put_stats_out; return 0; -put_tried_regions_out: - kobject_put(&scheme->tried_regions->kobj); - scheme->tried_regions = NULL; +put_stats_out: + kobject_put(&scheme->stats->kobj); + scheme->stats = NULL; put_filters_watermarks_quotas_access_pattern_out: kobject_put(&scheme->filters->kobj); scheme->filters = NULL;