summaryrefslogtreecommitdiff
path: root/mm
diff options
context:
space:
mode:
authorSeongJae Park <sj@kernel.org>2022-11-14 17:55:52 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-12-02 17:43:10 +0100
commitdfb8a23d93a6f6c7b3c51f4fb5acdb25e176cd45 (patch)
tree32f68a1c120e478831dbe888b3f26e4168784bf4 /mm
parent3398bf9b0d12912bfe912b86dcea86527fd85ed8 (diff)
downloadlinux-dfb8a23d93a6f6c7b3c51f4fb5acdb25e176cd45.tar.gz
linux-dfb8a23d93a6f6c7b3c51f4fb5acdb25e176cd45.tar.bz2
linux-dfb8a23d93a6f6c7b3c51f4fb5acdb25e176cd45.zip
mm/damon/sysfs-schemes: skip stats update if the scheme directory is removed
commit 8468b486612c808c9e337708d66a435498f1735c 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: 0ac32b8affb5 ("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>
Diffstat (limited to 'mm')
-rw-r--r--mm/damon/sysfs.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index bdef9682d0a0..b4b9614eecbe 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -2342,6 +2342,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;