All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Liam Ni <zhiguangni01@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	dave.hansen@linux.intel.com, luto@kernel.org,
	peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com,
	bp@alien8.de, x86@kernel.org, hpa@zytor.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH] mm/sparse:avoid null pointer access in memory_present()
Date: Sat, 17 Jun 2023 10:00:51 +0300	[thread overview]
Message-ID: <20230617070051.GU52412@kernel.org> (raw)
In-Reply-To: <CACZJ9cXM9VkJ5=euHphwM5TtX3aZqZ_QynOq10FtrqCxZfZsQA@mail.gmail.com>

On Sat, Jun 17, 2023 at 02:17:58PM +0800, Liam Ni wrote:
> On Sat, 17 Jun 2023 at 13:44, Andrew Morton <akpm@linux-foundation.org> wrote:
> >
> > On Sat, 17 Jun 2023 14:40:36 +1000 Liam Ni <zhiguangni01@gmail.com> wrote:
> >
> > > __nr_to_section() may return a null pointer,
> > > before accessing the member variable section_mem_map,
> > > we should first determine whether it is a null pointer.
> > >
> > > ...
> > >
> > > --- a/mm/sparse.c
> > > +++ b/mm/sparse.c
> > > @@ -258,7 +258,7 @@ static void __init memory_present(int nid, unsigned long start, unsigned long en
> > >               set_section_nid(section, nid);
> > >
> > >               ms = __nr_to_section(section);
> > > -             if (!ms->section_mem_map) {
> > > +             if (ms && !ms->section_mem_map) {
> > >                       ms->section_mem_map = sparse_encode_early_nid(nid) |
> > >                                                       SECTION_IS_ONLINE;
> > >                       __section_mark_present(ms, section);
> >
> > I'm suspecting that if __nr_to_section() returns NULL here, we should
> > just panic.  But a null-deref gives the same information, so why change
> > things?
> 
> Do you mean if ms is a null pointer,ms->section_mem_map will cause
> system panic,so we needn't change?
 
Yes, if __nr_to_section ever returns NULL the system will crash anyway.

-- 
Sincerely yours,
Mike.


  reply	other threads:[~2023-06-17  7:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-17  4:40 [PATCH] mm/sparse:avoid null pointer access in memory_present() Liam Ni
2023-06-17  5:44 ` Andrew Morton
2023-06-17  6:17   ` Liam Ni
2023-06-17  7:00     ` Mike Rapoport [this message]
2023-06-17  8:59       ` Liam Ni
2023-06-18  7:16         ` Mike Rapoport

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=20230617070051.GU52412@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=zhiguangni01@gmail.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.