Skip to content

Commit 8468b48

Browse files
sjp38akpm00
authored andcommitted
mm/damon/sysfs-schemes: skip stats update if the scheme directory is removed
A DAMON sysfs interface user can start DAMON with a scheme, remove the sysfs directory for the scheme, and then ask update of the scheme's stats. Because the schemes stats update logic isn't aware of the situation, it results in an invalid memory access. Fix the bug by checking if the scheme sysfs directory exists. Link: https://lkml.kernel.org/r/[email protected] Fixes: 0ac32b8 ("mm/damon/sysfs: support DAMOS stats") Signed-off-by: SeongJae Park <[email protected]> Cc: <[email protected]> [v5.18] Signed-off-by: Andrew Morton <[email protected]>
1 parent 4a955be commit 8468b48

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

mm/damon/sysfs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,6 +2339,10 @@ static int damon_sysfs_upd_schemes_stats(struct damon_sysfs_kdamond *kdamond)
23392339
damon_for_each_scheme(scheme, ctx) {
23402340
struct damon_sysfs_stats *sysfs_stats;
23412341

2342+
/* user could have removed the scheme sysfs dir */
2343+
if (schemes_idx >= sysfs_schemes->nr)
2344+
break;
2345+
23422346
sysfs_stats = sysfs_schemes->schemes_arr[schemes_idx++]->stats;
23432347
sysfs_stats->nr_tried = scheme->stat.nr_tried;
23442348
sysfs_stats->sz_tried = scheme->stat.sz_tried;

0 commit comments

Comments
 (0)