* [PATCH] ksm: Fix potential NULL pointer dereference
@ 2025-09-25 3:13 Fushuai Wang
2025-09-25 7:50 ` David Hildenbrand
0 siblings, 1 reply; 3+ messages in thread
From: Fushuai Wang @ 2025-09-25 3:13 UTC (permalink / raw)
To: akpm, david, xu.xin16, chengming.zhou
Cc: linux-mm, linux-kernel, cuigaosheng1, Fushuai Wang
The stable_tree_search() function may return an error pointer
(NULL or ERR_PTR(...)). The current code does not check for
these cases before dereferencing the returned value.
Gaosheng once added the necessary check in commit 98c3ca0015b8
("ksm: convert cmp_and_merge_page() to use a folio"), but it seems
the check was lost during the process of being merged into the
mainline.
Fixes: 98c3ca0015b8 ("ksm: convert cmp_and_merge_page() to use a folio")
Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
---
mm/ksm.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mm/ksm.c b/mm/ksm.c
index 160787bb121c..7aa9b2829a7b 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -2272,7 +2272,8 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite
/* Start by searching for the folio in the stable tree */
kfolio = stable_tree_search(page);
- if (&kfolio->page == page && rmap_item->head == stable_node) {
+ if (!IS_ERR_OR_NULL(kfolio) && &kfolio->page == page &&
+ rmap_item->head == stable_node) {
folio_put(kfolio);
return;
}
--
2.36.1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH -next] mm/ksm: Add missing IS_ERR_OR_NULL check for stable_tree_search()
@ 2024-11-15 15:41 Matthew Wilcox
2025-09-25 8:02 ` [PATCH] ksm: Fix potential NULL pointer dereference Fushuai Wang
0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox @ 2024-11-15 15:41 UTC (permalink / raw)
To: David Hildenbrand; +Cc: Gaosheng Cui, akpm, wangweiyang2, linux-mm
On Fri, Nov 15, 2024 at 11:44:10AM +0100, David Hildenbrand wrote:
> On 24.10.24 05:23, Gaosheng Cui wrote:
> > The stable_tree_search() maybe return -EBUSY if the stable node's page
> > is being migrated or nullptr, we need to check kfolio with
> > IS_ERR_OR_NULL() before dereference it.
Argh. I doidn't notice this when it came through. Andrew already
folded it in, but it's utter garbage. We don't dereference folio.
NAK.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-25 8:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-25 3:13 [PATCH] ksm: Fix potential NULL pointer dereference Fushuai Wang
2025-09-25 7:50 ` David Hildenbrand
-- strict thread matches above, loose matches on Subject: below --
2024-11-15 15:41 [PATCH -next] mm/ksm: Add missing IS_ERR_OR_NULL check for stable_tree_search() Matthew Wilcox
2025-09-25 8:02 ` [PATCH] ksm: Fix potential NULL pointer dereference Fushuai Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox