[PATCH 0/4] mm/damon/sysfs: fix resource leak and NULL pointer dereferences
From: Josh Law
Date: Thu Mar 19 2026 - 12:22:49 EST
This series fixes a memory leak and three NULL pointer dereferences in
the DAMON sysfs interface, all in mm/damon/sysfs.c.
Patch 1 fixes a damon_ctx leak in damon_sysfs_commit_input() when
damon_sysfs_new_test_ctx() fails after param_ctx was already built.
Patches 2-4 fix missing contexts->nr checks before dereferencing
contexts_arr[0]. A user can trigger these by setting nr_contexts to 0
via sysfs and then issuing commands that assume a context exists:
- Patch 2: CLEAR_SCHEMES_TRIED_REGIONS handler in damon_sysfs_handle_cmd()
- Patch 3: damon_sysfs_update_schemes_tried_regions(), reached via
UPDATE_SCHEMES_TRIED_BYTES and UPDATE_SCHEMES_TRIED_REGIONS
- Patch 4: damon_sysfs_repeat_call_fn(), reachable when nr_contexts is
set to 0 while DAMON is running
Josh Law (4):
mm/damon/sysfs: fix param_ctx leak on damon_sysfs_new_test_ctx()
failure
mm/damon/sysfs: check contexts->nr before clear_schemes_tried_regions
mm/damon/sysfs: check contexts->nr in update_schemes_tried_regions
mm/damon/sysfs: check contexts->nr in repeat_call_fn
mm/damon/sysfs.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
--
2.34.1