]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm/damon/lru_sort: handle ctx allocation failure
authorSeongJae Park <sj@kernel.org>
Fri, 29 May 2026 00:01:03 +0000 (17:01 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 3 Jun 2026 23:25:51 +0000 (16:25 -0700)
DAMON_LRU_SORT allocates the damon_ctx object for its kdamond in its init
function.  damon_lru_sort_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.

Link: https://lore.kernel.org/20260529000104.7006-3-sj@kernel.org
Fixes: c4a8e662c839 ("mm/damon/lru_sort: use damon_initialized()")
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: <stable@vger.kernel.org> # 6.18.x
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/damon/lru_sort.c

index 8494040b1ee48feeaca4b16b627d6e28b1a39d91..8cfe7bd3dc1d33ba348d47545cffec80bcfe400a 100644 (file)
@@ -437,6 +437,10 @@ static int damon_lru_sort_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_lru_sort_turn(enabled);
 }