From: Sourav Panda <souravpanda@google.com>
To: muchun.song@linux.dev, osalvador@suse.de, akpm@linux-foundation.org
Cc: david@kernel.org, surenb@google.com, fvdl@google.com,
gthelen@google.com, souravpanda@google.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] mm/hugetlb: Fix null pointer dereference of nodemask in hugetlb_cma_alloc_frozen_folio
Date: Thu, 2 Jul 2026 21:57:13 +0000 [thread overview]
Message-ID: <20260702215713.627941-1-souravpanda@google.com> (raw)
alloc_buddy_hugetlb_folio_with_mpol() can pass a NULL nodemask to
hugetlb_cma_alloc_frozen_folio() as a fallback to allocate from all
nodes. In this case, hugetlb_cma_alloc_frozen_folio() blindly
dereferences it in for_each_node_mask(), leading to a null pointer
dereference.
Fix this by checking if nodemask is NULL and defaulting to
node_states[N_MEMORY] if it is.
Signed-off-by: Sourav Panda <souravpanda@google.com>
---
mm/hugetlb_cma.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/hugetlb_cma.c b/mm/hugetlb_cma.c
index 39344d6c78d8..563e11e607e5 100644
--- a/mm/hugetlb_cma.c
+++ b/mm/hugetlb_cma.c
@@ -34,6 +34,9 @@ struct folio *hugetlb_cma_alloc_frozen_folio(int order, gfp_t gfp_mask,
if (!hugetlb_cma_size)
return NULL;
+ if (!nodemask)
+ nodemask = &node_states[N_MEMORY];
+
if (hugetlb_cma[nid])
page = cma_alloc_frozen_compound(hugetlb_cma[nid], order);
--
2.55.0.rc0.799.gd6f94ed593-goog
next reply other threads:[~2026-07-02 21:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 21:57 Sourav Panda [this message]
2026-07-02 23:24 ` [PATCH] mm/hugetlb: Fix null pointer dereference of nodemask in hugetlb_cma_alloc_frozen_folio Andrew Morton
2026-07-03 20:04 ` Sourav Panda
2026-07-04 3:04 ` Muchun Song
2026-07-04 3:53 ` Sourav Panda
2026-07-04 4:06 ` Muchun Song
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=20260702215713.627941-1-souravpanda@google.com \
--to=souravpanda@google.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=fvdl@google.com \
--cc=gthelen@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=surenb@google.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.