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 unpreservation of higher-order vmalloc preservations

kho_vmalloc_unpreserve_chunk() calls __kho_unpreserve() with end_pfn as
pfn + 1. This happens to work for 0-order pages, but leaks higher order
pages.

For example, say order 2 pages back the allocation. During preservation,
they get preserved in the order 2 bitmaps, but
kho_vmalloc_unpreserve_chunk() would try to unpreserve them from the order
0 bitmaps, which should not have these bits set anyway, leaving the order
2 bitmaps untouched. This results in the pages being carried over to the
next kernel. Nothing will free those pages in the next boot, leaking
them.

Fix this by taking the order into account when calculating the end PFN for
__kho_unpreserve().

Link: https://lkml.kernel.org/r/20251103180235.71409-2-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
7ecd2e43 0b07092d

+4 -3
+4 -3
kernel/kexec_handover.c
··· 882 882 return NULL; 883 883 } 884 884 885 - static void kho_vmalloc_unpreserve_chunk(struct kho_vmalloc_chunk *chunk) 885 + static void kho_vmalloc_unpreserve_chunk(struct kho_vmalloc_chunk *chunk, 886 + unsigned short order) 886 887 { 887 888 struct kho_mem_track *track = &kho_out.ser.track; 888 889 unsigned long pfn = PHYS_PFN(virt_to_phys(chunk)); ··· 892 891 893 892 for (int i = 0; i < ARRAY_SIZE(chunk->phys) && chunk->phys[i]; i++) { 894 893 pfn = PHYS_PFN(chunk->phys[i]); 895 - __kho_unpreserve(track, pfn, pfn + 1); 894 + __kho_unpreserve(track, pfn, pfn + (1 << order)); 896 895 } 897 896 } 898 897 ··· 903 902 while (chunk) { 904 903 struct kho_vmalloc_chunk *tmp = chunk; 905 904 906 - kho_vmalloc_unpreserve_chunk(chunk); 905 + kho_vmalloc_unpreserve_chunk(chunk, kho_vmalloc->order); 907 906 908 907 chunk = KHOSER_LOAD_PTR(chunk->hdr.next); 909 908 free_page((unsigned long)tmp);