The patch titled Subject: mm: prevent derefencing NULL ptr in pfn_section_valid() has been added to the -mm mm-hotfixes-unstable branch. Its filename is mm-prevent-derefencing-null-ptr-in-pfn_section_valid.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-prevent-derefencing-null-ptr-in-pfn_section_valid.patch This patch will later appear in the mm-hotfixes-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Waiman Long <longman@xxxxxxxxxx> Subject: mm: prevent derefencing NULL ptr in pfn_section_valid() Date: Tue, 25 Jun 2024 20:16:39 -0400 Commit 5ec8e8ea8b77 ("mm/sparsemem: fix race in accessing memory_section->usage") changed pfn_section_valid() to add a READ_ONCE() call around "ms->usage" to fix a race with section_deactivate() where ms->usage can be cleared. The READ_ONCE() call, by itself, is not enough to prevent NULL pointer dereference. We need to check its value before dereferencing it. Link: https://lkml.kernel.org/r/20240626001639.1350646-1-longman@xxxxxxxxxx Fixes: 5ec8e8ea8b77 ("mm/sparsemem: fix race in accessing memory_section->usage") Signed-off-by: Waiman Long <longman@xxxxxxxxxx> Cc: Charan Teja Kalla <quic_charante@xxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/mmzone.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/include/linux/mmzone.h~mm-prevent-derefencing-null-ptr-in-pfn_section_valid +++ a/include/linux/mmzone.h @@ -1979,8 +1979,9 @@ static inline int subsection_map_index(u static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn) { int idx = subsection_map_index(pfn); + struct mem_section_usage *usage = READ_ONCE(ms->usage); - return test_bit(idx, READ_ONCE(ms->usage)->subsection_map); + return usage ? test_bit(idx, usage->subsection_map) : 0; } #else static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn) _ Patches currently in -mm which might be from longman@xxxxxxxxxx are mm-prevent-derefencing-null-ptr-in-pfn_section_valid.patch