Skip to content

Commit 82f0b6f

Browse files
Waiman-Longakpm00
authored andcommitted
mm: prevent derefencing NULL ptr in pfn_section_valid()
Commit 5ec8e8e ("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/[email protected] Fixes: 5ec8e8e ("mm/sparsemem: fix race in accessing memory_section->usage") Signed-off-by: Waiman Long <[email protected]> Cc: Charan Teja Kalla <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent fa2690a commit 82f0b6f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

include/linux/mmzone.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1979,8 +1979,9 @@ static inline int subsection_map_index(unsigned long pfn)
19791979
static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn)
19801980
{
19811981
int idx = subsection_map_index(pfn);
1982+
struct mem_section_usage *usage = READ_ONCE(ms->usage);
19821983

1983-
return test_bit(idx, READ_ONCE(ms->usage)->subsection_map);
1984+
return usage ? test_bit(idx, usage->subsection_map) : 0;
19841985
}
19851986
#else
19861987
static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn)

0 commit comments

Comments
 (0)