Skip to content

Commit

Permalink
mm/damon/sysfs-schemes: skip stats update if the scheme directory is …
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
sjp38 authored and akpm00 committed Nov 23, 2022
1 parent 4a955be commit 8468b48
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mm/damon/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2339,6 +2339,10 @@ static int damon_sysfs_upd_schemes_stats(struct damon_sysfs_kdamond *kdamond)
damon_for_each_scheme(scheme, ctx) {
struct damon_sysfs_stats *sysfs_stats;

/* user could have removed the scheme sysfs dir */
if (schemes_idx >= sysfs_schemes->nr)
break;

sysfs_stats = sysfs_schemes->schemes_arr[schemes_idx++]->stats;
sysfs_stats->nr_tried = scheme->stat.nr_tried;
sysfs_stats->sz_tried = scheme->stat.sz_tried;
Expand Down

0 comments on commit 8468b48

Please sign in to comment.