Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: a667300bd53f ("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>

authored by

Pratyush Yadav and committed by
Andrew Morton
0b07092d bba717bb

+2 -2
+2 -2
kernel/kexec_handover.c
··· 889 889 890 890 __kho_unpreserve(track, pfn, pfn + 1); 891 891 892 - for (int i = 0; chunk->phys[i]; i++) { 892 + for (int i = 0; i < ARRAY_SIZE(chunk->phys) && chunk->phys[i]; i++) { 893 893 pfn = PHYS_PFN(chunk->phys[i]); 894 894 __kho_unpreserve(track, pfn, pfn + 1); 895 895 } ··· 1012 1012 while (chunk) { 1013 1013 struct page *page; 1014 1014 1015 - for (int i = 0; chunk->phys[i]; i++) { 1015 + for (int i = 0; i < ARRAY_SIZE(chunk->phys) && chunk->phys[i]; i++) { 1016 1016 phys_addr_t phys = chunk->phys[i]; 1017 1017 1018 1018 if (idx + contig_pages > total_pages)