From: Andrew Morton <akpm@linux-foundation.org>
To: Sourav Panda <souravpanda@google.com>
Cc: muchun.song@linux.dev, osalvador@suse.de, david@kernel.org,
surenb@google.com, fvdl@google.com, gthelen@google.com,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/hugetlb: Fix null pointer dereference of nodemask in hugetlb_cma_alloc_frozen_folio
Date: Thu, 2 Jul 2026 16:24:15 -0700 [thread overview]
Message-ID: <20260702162415.142571f4d8c43aa4b95b9f7c@linux-foundation.org> (raw)
In-Reply-To: <20260702215713.627941-1-souravpanda@google.com>
On Thu, 2 Jul 2026 21:57:13 +0000 Sourav Panda <souravpanda@google.com> wrote:
> 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.
>
oh.
> Fix this by checking if nodemask is NULL and defaulting to
> node_states[N_MEMORY] if it is.
>
> --- 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);
It is possible to hit this with any known testcase?
If not, why not. I smell the smell of dead code somewhere?
Sashiko said things:
https://sashiko.dev/#/patchset/20260702215713.627941-1-souravpanda@google.com
Ackerly's "mm: hugetlb: move mpol interpretation out of
alloc_buddy_hugetlb_folio_with_mpol()" made big changes to
alloc_buddy_hugetlb_folio_with_mpol():
https://lore.kernel.org/20260702-hugetlb-open-up-v4-2-d53cefcccf34@google.com.
If this bug is real then it would be better to stage your fix ahead of
Ackerly's series. Possibly with a cc:stable. Then I can redo
Ackerly's patch on top and we'll need to check that this bug isn't
reintroduced.
next prev parent reply other threads:[~2026-07-03 0:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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=20260702162415.142571f4d8c43aa4b95b9f7c@linux-foundation.org \
--to=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=souravpanda@google.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox