mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-29 13:53:33 +00:00
mm/damon/sysfs-schemes: skip stats update if the scheme directory is removed
commit8468b48661
upstream. 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/20221114175552.1951-1-sj@kernel.org Fixes:0ac32b8aff
("mm/damon/sysfs: support DAMOS stats") Signed-off-by: SeongJae Park <sj@kernel.org> Cc: <stable@vger.kernel.org> [v5.18] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
3398bf9b0d
commit
dfb8a23d93
1 changed files with 4 additions and 0 deletions
|
@ -2342,6 +2342,10 @@ static int damon_sysfs_upd_schemes_stats(struct damon_sysfs_kdamond *kdamond)
|
||||||
damon_for_each_scheme(scheme, ctx) {
|
damon_for_each_scheme(scheme, ctx) {
|
||||||
struct damon_sysfs_stats *sysfs_stats;
|
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 = sysfs_schemes->schemes_arr[schemes_idx++]->stats;
|
||||||
sysfs_stats->nr_tried = scheme->stat.nr_tried;
|
sysfs_stats->nr_tried = scheme->stat.nr_tried;
|
||||||
sysfs_stats->sz_tried = scheme->stat.sz_tried;
|
sysfs_stats->sz_tried = scheme->stat.sz_tried;
|
||||||
|
|
Loading…
Reference in a new issue