Skip to content

Commit 6557004

Browse files
techyguyperplexableakpm00
authored andcommitted
mm/damon/sysfs: check contexts->nr in repeat_call_fn
damon_sysfs_repeat_call_fn() calls damon_sysfs_upd_tuned_intervals(), damon_sysfs_upd_schemes_stats(), and damon_sysfs_upd_schemes_effective_quotas() without checking contexts->nr. If nr_contexts is set to 0 via sysfs while DAMON is running, these functions dereference contexts_arr[0] and cause a NULL pointer dereference. Add the missing check. For example, the issue can be reproduced using DAMON sysfs interface and DAMON user-space tool (damo) [1] like below. $ sudo damo start --refresh_interval 1s $ echo 0 | sudo tee \ /sys/kernel/mm/damon/admin/kdamonds/0/contexts/nr_contexts Link: https://patch.msgid.link/[email protected] Link: https://lkml.kernel.org/r/[email protected] Link: https://github.com/damonitor/damo [1] Fixes: d809a7c ("mm/damon/sysfs: implement refresh_ms file internal work") Signed-off-by: Josh Law <[email protected]> Reviewed-by: SeongJae Park <[email protected]> Signed-off-by: SeongJae Park <[email protected]> Cc: <[email protected]> [6.17+] Signed-off-by: Andrew Morton <[email protected]>
1 parent 1bfe9fb commit 6557004

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

mm/damon/sysfs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,9 +1620,12 @@ static int damon_sysfs_repeat_call_fn(void *data)
16201620

16211621
if (!mutex_trylock(&damon_sysfs_lock))
16221622
return 0;
1623+
if (sysfs_kdamond->contexts->nr != 1)
1624+
goto out;
16231625
damon_sysfs_upd_tuned_intervals(sysfs_kdamond);
16241626
damon_sysfs_upd_schemes_stats(sysfs_kdamond);
16251627
damon_sysfs_upd_schemes_effective_quotas(sysfs_kdamond);
1628+
out:
16261629
mutex_unlock(&damon_sysfs_lock);
16271630
return 0;
16281631
}

0 commit comments

Comments
 (0)