]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm/damon/sysfs-schemes: put stats for scheme_add_dirs() internal error
authorSeongJae Park <sj@kernel.org>
Thu, 18 Jun 2026 00:56:48 +0000 (17:56 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 2 Jul 2026 02:02:53 +0000 (19:02 -0700)
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
Fixes: 5181b75f438d ("mm/damon/sysfs-schemes: implement schemes/tried_regions directory")
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: <stable@vger.kernel.org> # 6.2.x
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/damon/sysfs-schemes.c

index 7c00aa78b2f5056104d1379f7ee734b8ded8e62f..0134111c3c1ff6eaeced50f6f6a48bebf168a141 100644 (file)
@@ -2513,12 +2513,12 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme)
                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->ops_filters->kobj);
        scheme->ops_filters = NULL;