From: Gaosheng Cui <cuigaosheng1@huawei.com>
To: <akpm@linux-foundation.org>, <willy@infradead.org>,
<david@redhat.com>, <wangweiyang2@huawei.com>
Cc: <linux-mm@kvack.org>
Subject: [PATCH -next] mm/ksm: Add missing IS_ERR_OR_NULL check for stable_tree_search()
Date: Thu, 24 Oct 2024 11:23:00 +0800 [thread overview]
Message-ID: <20241024032300.2501949-1-cuigaosheng1@huawei.com> (raw)
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.
To mitigate this, add IS_ERR_OR_NULL check for stable_tree_search().
Fixes: 15605244fdce ("ksm: convert cmp_and_merge_page() to use a folio")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
---
mm/ksm.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/mm/ksm.c b/mm/ksm.c
index 4d482d011745..7ac59cde626c 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -1787,7 +1787,7 @@ static __always_inline struct folio *chain(struct ksm_stable_node **s_n_d,
* with identical content to the page that we are scanning right now.
*
* This function returns the stable tree node of identical content if found,
- * NULL otherwise.
+ * -EBUSY if the stable node's page is being migrated, NULL otherwise.
*/
static struct folio *stable_tree_search(struct page *page)
{
@@ -2261,7 +2261,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.25.1
next reply other threads:[~2024-10-24 3:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-24 3:23 Gaosheng Cui [this message]
2024-11-15 10:44 ` David Hildenbrand
2024-11-15 15:41 ` Matthew Wilcox
2024-11-15 15:52 ` David Hildenbrand
2025-09-25 8:02 ` [PATCH] ksm: Fix potential NULL pointer dereference Fushuai Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241024032300.2501949-1-cuigaosheng1@huawei.com \
--to=cuigaosheng1@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=linux-mm@kvack.org \
--cc=wangweiyang2@huawei.com \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox