Skip to content

Commit 1f03bcb

Browse files
Waiman-Longvijay-suman
authored andcommitted
mm: prevent derefencing NULL ptr in pfn_section_valid()
[ Upstream commit 82f0b6f ] 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]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit bc17f2377818dca643a74499c3f5333500c90503) FOF: 0924 Signed-off-by: Vijayendra Suman <[email protected]>
1 parent dbdd7f3 commit 1f03bcb

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
@@ -1494,8 +1494,9 @@ static inline int subsection_map_index(unsigned long pfn)
14941494
static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn)
14951495
{
14961496
int idx = subsection_map_index(pfn);
1497+
struct mem_section_usage *usage = READ_ONCE(ms->usage);
14971498

1498-
return test_bit(idx, READ_ONCE(ms->usage)->subsection_map);
1499+
return usage ? test_bit(idx, usage->subsection_map) : 0;
14991500
}
15001501
#else
15011502
static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn)

0 commit comments

Comments
 (0)