Re: [PATCH] mm/damon/sysfs-schemes: fix tried_regions setup failure cleanup
From: SJ Park
Date: Wed Jul 08 2026 - 10:27:35 EST
Hello Guangshuo,
On Wed, 8 Jul 2026 16:01:07 +0800 Guangshuo Li <lgs201920130244@xxxxxxxxx> wrote:
> damon_sysfs_scheme_add_dirs() sets up the tried_regions directory after
> the stats directory has already been created.
>
> If damon_sysfs_scheme_set_tried_regions() fails, scheme->tried_regions
> has not been assigned. The error path nevertheless jumps to
> put_tried_regions_out and dereferences scheme->tried_regions while
> trying to put its kobject.
>
> This can dereference uninitialized memory because struct
> damon_sysfs_scheme is allocated with kmalloc-style allocation and
> scheme->tried_regions is only assigned after tried_regions setup
> succeeds.
>
> On tried_regions setup failure, start cleanup from the last successfully
> created directory, stats, instead of trying to put tried_regions.
Thank you for this patch! However, it seems a same fix is already merged into
the mainline as commit 05ea83ee88ca ("mm/damon/sysfs-schemes: put stats for
scheme_add_dirs() internal error").
So, unfortunately we will not be able to merge this patch.
Thanks,
SJ
[...]