* [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; 2+ 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] 2+ messages in thread
* Re: [PATCH] ksm: Fix potential NULL pointer dereference
2025-09-25 3:13 [PATCH] ksm: Fix potential NULL pointer dereference Fushuai Wang
@ 2025-09-25 7:50 ` David Hildenbrand
0 siblings, 0 replies; 2+ messages in thread
From: David Hildenbrand @ 2025-09-25 7:50 UTC (permalink / raw)
To: Fushuai Wang, akpm, xu.xin16, chengming.zhou
Cc: linux-mm, linux-kernel, cuigaosheng1
On 25.09.25 05:13, Fushuai Wang wrote:
> 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.
We discussed this in [1] where Willy clarified that there is no
de-referencing happening [2].
So no, this is not required.
Consider "&kfolio->page" currently being a "(struct page *) kfolio",
which is just a pointer cast and no de-referencing.
[1]
https://lore.kernel.org/linux-mm/20241024032300.2501949-1-cuigaosheng1@huawei.com/
[2] https://lore.kernel.org/linux-mm/Zzdrnod2zcTeI-Nt@casper.infradead.org/
--
Cheers
David / dhildenb
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-25 7:50 UTC | newest]
Thread overview: 2+ 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®