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 KASAN support for restored vmalloc regions

Restored vmalloc regions are currently not properly marked for KASAN,
causing KASAN to treat accesses to these regions as out-of-bounds.

Fix this by properly unpoisoning the restored vmalloc area using
kasan_unpoison_vmalloc(). This requires setting the VM_UNINITIALIZED flag
during the initial area allocation and clearing it after the pages have
been mapped and unpoisoned, using the clear_vm_uninitialized_flag()
helper.

Link: https://lkml.kernel.org/r/20260225223857.1714801-3-pasha.tatashin@soleen.com
Fixes: a667300bd53f ("kho: add support for preserving vmalloc allocations")
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Reported-by: Pratyush Yadav <pratyush@kernel.org>
Reviewed-by: Pratyush Yadav (Google) <pratyush@kernel.org>
Tested-by: Pratyush Yadav (Google) <pratyush@kernel.org>
Cc: Alexander Graf <graf@amazon.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: "Uladzislau Rezki (Sony)" <urezki@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Pasha Tatashin and committed by
Andrew Morton
019fc368 ec106365

+11 -1
+11 -1
kernel/liveupdate/kexec_handover.c
··· 14 14 #include <linux/cma.h> 15 15 #include <linux/kmemleak.h> 16 16 #include <linux/count_zeros.h> 17 + #include <linux/kasan.h> 17 18 #include <linux/kexec.h> 18 19 #include <linux/kexec_handover.h> 19 20 #include <linux/kho_radix_tree.h> ··· 1078 1077 void *kho_restore_vmalloc(const struct kho_vmalloc *preservation) 1079 1078 { 1080 1079 struct kho_vmalloc_chunk *chunk = KHOSER_LOAD_PTR(preservation->first); 1080 + kasan_vmalloc_flags_t kasan_flags = KASAN_VMALLOC_PROT_NORMAL; 1081 1081 unsigned int align, order, shift, vm_flags; 1082 1082 unsigned long total_pages, contig_pages; 1083 1083 unsigned long addr, size; ··· 1130 1128 goto err_free_pages_array; 1131 1129 1132 1130 area = __get_vm_area_node(total_pages * PAGE_SIZE, align, shift, 1133 - vm_flags, VMALLOC_START, VMALLOC_END, 1131 + vm_flags | VM_UNINITIALIZED, 1132 + VMALLOC_START, VMALLOC_END, 1134 1133 NUMA_NO_NODE, GFP_KERNEL, 1135 1134 __builtin_return_address(0)); 1136 1135 if (!area) ··· 1145 1142 1146 1143 area->nr_pages = total_pages; 1147 1144 area->pages = pages; 1145 + 1146 + if (vm_flags & VM_ALLOC) 1147 + kasan_flags |= KASAN_VMALLOC_VM_ALLOC; 1148 + 1149 + area->addr = kasan_unpoison_vmalloc(area->addr, total_pages * PAGE_SIZE, 1150 + kasan_flags); 1151 + clear_vm_uninitialized_flag(area); 1148 1152 1149 1153 return area->addr; 1150 1154