DAMON_RECLAIM allocates the damon_ctx object for its kdamond in its init function. damon_reclaim_enabled_store() wrongly assumes the allocation will always succeed once tried. If the damon_ctx allocation was failed, therefore, code execution reaches to damon_commit_ctx() while 'ctx' is NULL. As a result, it dereferences the NULL 'ctx' pointer. Avoid the NULL dereference by returning -ENOMEM if 'ctx' is NULL. Fixes: 3f7a914ab9a5 ("mm/damon/reclaim: use damon_initialized()") Cc: # 6.18.x Signed-off-by: SeongJae Park --- mm/damon/reclaim.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index ed446d00ef1cf..ce4499cf4b8b0 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -399,6 +399,10 @@ static int damon_reclaim_enabled_store(const char *val, if (!damon_initialized()) return 0; + /* damon_modules_new_paddr_ctx_target() in the init function failed. */ + if (!ctx) + return -ENOMEM; + return damon_reclaim_turn(enabled); } -- 2.47.3