The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] mm/hugetlb: Fix null pointer dereference of nodemask in hugetlb_cma_alloc_frozen_folio
@ 2026-07-02 21:57 Sourav Panda
  2026-07-02 23:24 ` Andrew Morton
  0 siblings, 1 reply; 6+ messages in thread
From: Sourav Panda @ 2026-07-02 21:57 UTC (permalink / raw)
  To: muchun.song, osalvador, akpm
  Cc: david, surenb, fvdl, gthelen, souravpanda, linux-mm, linux-kernel

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-07-04  4:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-02 21:57 [PATCH] mm/hugetlb: Fix null pointer dereference of nodemask in hugetlb_cma_alloc_frozen_folio Sourav Panda
2026-07-02 23:24 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox