Skip to content

Commit 0721a61

Browse files
sjp38akpm00
authored andcommitted
mm/damon/sysfs-schemes: handle schemes sysfs dir removal before commit_schemes_quota_goals
'commit_schemes_quota_goals' command handler, damos_sysfs_set_quota_scores() assumes the number of schemes sysfs directory will be same to the number of schemes of the DAMON context. The assumption is wrong since users can remove schemes sysfs directories while DAMON is running. In the case, illegal memory accesses can happen. Fix it by checking the case. Link: https://lkml.kernel.org/r/20240213023633.124928-1-sj@kernel.org Fixes: d91beaa ("mm/damon/sysfs-schemes: implement a command for scheme quota goals only commit") Signed-off-by: SeongJae Park <sj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 118642d commit 0721a61

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

mm/damon/sysfs-schemes.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,10 @@ void damos_sysfs_set_quota_scores(struct damon_sysfs_schemes *sysfs_schemes,
19051905
damon_for_each_scheme(scheme, ctx) {
19061906
struct damon_sysfs_scheme *sysfs_scheme;
19071907

1908+
/* user could have removed the scheme sysfs dir */
1909+
if (i >= sysfs_schemes->nr)
1910+
break;
1911+
19081912
sysfs_scheme = sysfs_schemes->schemes_arr[i];
19091913
damos_sysfs_set_quota_score(sysfs_scheme->quotas->goals,
19101914
&scheme->quota);

0 commit comments

Comments
 (0)