linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Liam Ni <zhiguangni01@gmail.com>
To: 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,
	akpm@linux-foundation.org, rppt@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, zhiguangni01@gmail.com
Subject: [PATCH] mm/sparse:avoid null pointer access in memory_present()
Date: Sat, 17 Jun 2023 14:40:36 +1000	[thread overview]
Message-ID: <20230617044036.3985524-1-zhiguangni01@gmail.com> (raw)

__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.

Signed-off-by: Liam Ni <zhiguangni01@gmail.com>
---
 mm/sparse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/sparse.c b/mm/sparse.c
index 4e6e3a9d49dc..37fa3818bc25 100644
--- 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);
-- 
2.25.1



             reply	other threads:[~2023-06-17  4:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-17  4:40 Liam Ni [this message]
2023-06-17  5:44 ` Andrew Morton
2023-06-17  6:17   ` Liam Ni
2023-06-17  7:00     ` Mike Rapoport
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=20230617044036.3985524-1-zhiguangni01@gmail.com \
    --to=zhiguangni01@gmail.com \
    --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=rppt@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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