* [RFC PATCH 0/2] mm/damon/{reclaim,lru_sort}: handle ctx allocation failures
@ 2026-05-28 6:11 SeongJae Park
2026-05-28 6:11 ` [RFC PATCH 1/2] mm/damon/reclaim: handle ctx allocation failure SeongJae Park
2026-05-28 6:11 ` [RFC PATCH 2/2] mm/damonn/lru_sort: " SeongJae Park
0 siblings, 2 replies; 3+ messages in thread
From: SeongJae Park @ 2026-05-28 6:11 UTC (permalink / raw)
Cc: SeongJae Park, # 6 . 18 . x, Andrew Morton, damon, linux-kernel,
linux-mm
DAMON_RECLAIM and DAMON_LRU_SORT could dereference NULL pointers if
their damon_ctx object allocations fail. The bug is expected to happen
not frequently,, because the allocation is arguably too small to fail on
common setup. But theoretically it is possible and the consequence is
bad. Fix those.
The issue was discovered [1] by Sashiko.
[1] https://lore.kernel.org/20260419014800.877-1-sj@kernel.org
SeongJae Park (2):
mm/damon/reclaim: handle ctx allocation failure
mm/damonn/lru_sort: handle ctx allocation failure
mm/damon/lru_sort.c | 4 ++++
mm/damon/reclaim.c | 4 ++++
2 files changed, 8 insertions(+)
base-commit: 3c18aac8c775b020a2c50e91051f106dc621ad3e
--
2.47.3
^ permalink raw reply [flat|nested] 3+ messages in thread* [RFC PATCH 1/2] mm/damon/reclaim: handle ctx allocation failure
2026-05-28 6:11 [RFC PATCH 0/2] mm/damon/{reclaim,lru_sort}: handle ctx allocation failures SeongJae Park
@ 2026-05-28 6:11 ` SeongJae Park
2026-05-28 6:11 ` [RFC PATCH 2/2] mm/damonn/lru_sort: " SeongJae Park
1 sibling, 0 replies; 3+ messages in thread
From: SeongJae Park @ 2026-05-28 6:11 UTC (permalink / raw)
Cc: SeongJae Park, # 6 . 18 . x, Andrew Morton, damon, linux-kernel,
linux-mm
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: <stable@vger.kernel.org> # 6.18.x
Signed-off-by: SeongJae Park <sj@kernel.org>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* [RFC PATCH 2/2] mm/damonn/lru_sort: handle ctx allocation failure
2026-05-28 6:11 [RFC PATCH 0/2] mm/damon/{reclaim,lru_sort}: handle ctx allocation failures SeongJae Park
2026-05-28 6:11 ` [RFC PATCH 1/2] mm/damon/reclaim: handle ctx allocation failure SeongJae Park
@ 2026-05-28 6:11 ` SeongJae Park
1 sibling, 0 replies; 3+ messages in thread
From: SeongJae Park @ 2026-05-28 6:11 UTC (permalink / raw)
Cc: SeongJae Park, # 6 . 18 . x, Andrew Morton, damon, linux-kernel,
linux-mm
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.
Fixes: c4a8e662c839 ("mm/damon/lru_sort: use damon_initialized()")
Cc: <stable@vger.kernel.org> # 6.18.x
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/lru_sort.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c
index eca88ed941b32..8298c6001fd09 100644
--- a/mm/damon/lru_sort.c
+++ b/mm/damon/lru_sort.c
@@ -476,6 +476,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);
}
--
2.47.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-28 6:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-28 6:11 [RFC PATCH 0/2] mm/damon/{reclaim,lru_sort}: handle ctx allocation failures SeongJae Park
2026-05-28 6:11 ` [RFC PATCH 1/2] mm/damon/reclaim: handle ctx allocation failure SeongJae Park
2026-05-28 6:11 ` [RFC PATCH 2/2] mm/damonn/lru_sort: " SeongJae Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox