diff options
| author | Waiman Long <longman@redhat.com> | 2024-06-26 03:16:39 +0300 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2024-07-18 14:21:10 +0300 |
| commit | 797323d1cf92d09b7a017cfec576d9babf99cde7 (patch) | |
| tree | feba3440f6d2c5008f8cc678a6f4a0d5359b79eb /include | |
| parent | fc19e231688cc244f38c46d8fdcff2ba80f43fbf (diff) | |
| download | linux-797323d1cf92d09b7a017cfec576d9babf99cde7.tar.xz | |
mm: prevent derefencing NULL ptr in pfn_section_valid()
[ Upstream commit 82f0b6f041fad768c28b4ad05a683065412c226e ]
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@redhat.com
Fixes: 5ec8e8ea8b77 ("mm/sparsemem: fix race in accessing memory_section->usage")
Signed-off-by: Waiman Long <longman@redhat.com>
Cc: Charan Teja Kalla <quic_charante@quicinc.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/linux/mmzone.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index e46fbca00309..05092c37a430 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1968,8 +1968,9 @@ static inline int subsection_map_index(unsigned long pfn) 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) |
