Skip to content

Commit 0b07092

Browse files
prati0100akpm00
authored andcommitted
kho: fix out-of-bounds access of vmalloc chunk
The list of pages in a vmalloc chunk is NULL-terminated. So when looping through the pages in a vmalloc chunk, both kho_restore_vmalloc() and kho_vmalloc_unpreserve_chunk() rightly make sure to stop when encountering a NULL page. But when the chunk is full, the loops do not stop and go past the bounds of chunk->phys, resulting in out-of-bounds memory access, and possibly the restoration or unpreservation of an invalid page. Fix this by making sure the processing of chunk stops at the end of the array. Link: https://lkml.kernel.org/r/20251103110159.8399-1-pratyush@kernel.org Fixes: a667300 ("kho: add support for preserving vmalloc allocations") Signed-off-by: Pratyush Yadav <pratyush@kernel.org> Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Cc: Alexander Graf <graf@amazon.com> Cc: Baoquan He <bhe@redhat.com> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent bba717b commit 0b07092

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

kernel/kexec_handover.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ static void kho_vmalloc_unpreserve_chunk(struct kho_vmalloc_chunk *chunk)
889889

890890
__kho_unpreserve(track, pfn, pfn + 1);
891891

892-
for (int i = 0; chunk->phys[i]; i++) {
892+
for (int i = 0; i < ARRAY_SIZE(chunk->phys) && chunk->phys[i]; i++) {
893893
pfn = PHYS_PFN(chunk->phys[i]);
894894
__kho_unpreserve(track, pfn, pfn + 1);
895895
}
@@ -1012,7 +1012,7 @@ void *kho_restore_vmalloc(const struct kho_vmalloc *preservation)
10121012
while (chunk) {
10131013
struct page *page;
10141014

1015-
for (int i = 0; chunk->phys[i]; i++) {
1015+
for (int i = 0; i < ARRAY_SIZE(chunk->phys) && chunk->phys[i]; i++) {
10161016
phys_addr_t phys = chunk->phys[i];
10171017

10181018
if (idx + contig_pages > total_pages)

0 commit comments

Comments
 (0)