linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Ye Chey <yechey@ai-sast.com>
Cc: akpm@linux-foundation.org, david@redhat.com,
	Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org,
	surenb@google.com, mhocko@suse.com, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: fix potential NULL pointer dereference in pagetable_alloc_noprof
Date: Wed, 21 May 2025 13:48:43 +0100	[thread overview]
Message-ID: <257c094c-522c-48c8-9bc2-70571dfb276f@lucifer.local> (raw)
In-Reply-To: <206c6dc2-792b-4c73-a922-eebd03864d2c@lucifer.local>

+cc mailing lists

Please ensure you always cc these when submitting patches by the way :)

On Wed, May 21, 2025 at 01:46:48PM +0100, Lorenzo Stoakes wrote:
> On Wed, May 21, 2025 at 08:40:08PM +0800, Ye Chey wrote:
> > The pagetable_alloc_noprof function does not check the return value of
> > alloc_pages_noprof, which could lead to a NULL pointer dereference when
> > memory allocation fails. Add a NULL check to prevent this issue.
> >
> > Signed-off-by: Ye Chey <yechey@ai-sast.com>
> > ---
> >  include/linux/mm.h | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/linux/mm.h b/include/linux/mm.h
> > index bf5520693..9052bb531 100644
> > --- a/include/linux/mm.h
> > +++ b/include/linux/mm.h
> > @@ -3000,7 +3000,8 @@ static inline bool pagetable_is_reserved(struct ptdesc *pt)
> >  static inline struct ptdesc *pagetable_alloc_noprof(gfp_t gfp, unsigned int order)
> >  {
> >  	struct page *page = alloc_pages_noprof(gfp | __GFP_COMP, order);
> > -
> > +	if (!page)
> > +		return NULL;
> >  	return page_ptdesc(page);
>
> Doesn't page_ptdesc() just cast the page to the appropriate type? And thus can
> handle it being NULL?
>
> >  }
> >  #define pagetable_alloc(...)	alloc_hooks(pagetable_alloc_noprof(__VA_ARGS__))
> > --
> > 2.44.0
> >


       reply	other threads:[~2025-05-21 12:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250521124008.36139-1-yechey@ai-sast.com>
     [not found] ` <206c6dc2-792b-4c73-a922-eebd03864d2c@lucifer.local>
2025-05-21 12:48   ` Lorenzo Stoakes [this message]
2025-05-22  6:58     ` Qi Zheng

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=257c094c-522c-48c8-9bc2-70571dfb276f@lucifer.local \
    --to=lorenzo.stoakes@oracle.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    --cc=yechey@ai-sast.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