linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Antonio Quartulli <antonio@mandelbit.com>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@redhat.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	Nico Pache <npache@redhat.com>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	Barry Song <baohua@kernel.org>, Zi Yan <ziy@nvidia.com>
Subject: Re: [RFC] mm/huge_memory: prevent potential NULL pointer dereference
Date: Wed, 16 Jul 2025 20:10:41 +0100	[thread overview]
Message-ID: <ffbcc306-0278-48b3-b051-095e5db5cecd@lucifer.local> (raw)
In-Reply-To: <a9076eac-dfd7-4a46-8e17-139f374e516c@mandelbit.com>

On Wed, Jul 16, 2025 at 09:05:14PM +0200, Antonio Quartulli wrote:
> Hi Lorenzo,
>
> On 16/07/2025 17:07, Lorenzo Stoakes wrote:
> > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> > > index 389620c65a5f..d649026db95a 100644
> > > --- a/mm/huge_memory.c
> > > +++ b/mm/huge_memory.c
> > > @@ -3802,7 +3802,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
> > >
> > >   			/* Some pages can be beyond EOF: drop them from cache */
> > >   			if (new_folio->index >= end) {
> >
> > It's kind of not _hugely_ clear but, if anon - which implies no mapping - we set
> > end == -1.
> >
> > At which point this condition cannot evaluate true (index is at page granularity
> > so even MAX_UINT64 would be page shifted and still not equal -1).
>
> I may be missing something, but why can't "index >= -1" be true?

These are unsigned long's, -1 in two's complement this means -1 translates
to the maximum possible unsigned long. Index cannot == the maximum number
as this is a _page_ index so a folio would need to reference a page larger
than could be represented in a 64-bit system for that to be so.

>
> In any case, with Zi's patch the NULL check comes before the rest so the
> problem does not exist anymore there.
>
> Regards,
>
> >
> > Under all other circumstances, mapping will be non-NULL.
> >
> > > -				if (shmem_mapping(mapping))
> > > +				if (mapping && shmem_mapping(mapping))
> > >   					nr_shmem_dropped += folio_nr_pages(new_folio);
> > >   				else if (folio_test_clear_dirty(new_folio))
> > >   					folio_account_cleaned(
> > > --
> > > 2.49.1
> > >
> > >
> >
> > Cheers, Lorenzo
>
> --
> Antonio Quartulli
>
> CEO and Co-Founder
> Mandelbit Srl
> https://www.mandelbit.com
>
>


  reply	other threads:[~2025-07-16 19:10 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-16 14:58 [RFC] mm/huge_memory: prevent potential NULL pointer dereference Antonio Quartulli
2025-07-16 15:07 ` Lorenzo Stoakes
2025-07-16 19:05   ` Antonio Quartulli
2025-07-16 19:10     ` Lorenzo Stoakes [this message]
2025-07-16 19:13       ` Antonio Quartulli
2025-07-16 15:10 ` Zi Yan
2025-07-16 15:18   ` David Hildenbrand
2025-07-16 15:24     ` Zi Yan
2025-07-16 15:31       ` David Hildenbrand
2025-07-16 16:18   ` Dan Carpenter

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=ffbcc306-0278-48b3-b051-095e5db5cecd@lucifer.local \
    --to=lorenzo.stoakes@oracle.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=antonio@mandelbit.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@redhat.com \
    --cc=dev.jain@arm.com \
    --cc=linux-mm@kvack.org \
    --cc=npache@redhat.com \
    --cc=ryan.roberts@arm.com \
    --cc=ziy@nvidia.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;
as well as URLs for NNTP newsgroup(s).