memblock: reject non-page-aligned reserve_mem regions
PATCH v2 1/1 memblock: reject non-page-aligned reserve_mem regions
When map->start or map->size is not page aligned, reserved_mem_preserve() does not preserve the last one or two pages of the region from map->start to map->start + map->size.
After kexec the new kernel reserves only the preserved pages, so those pages are released to the buddy allocator. But reserve_mem_find_by_name() still returns the whole region including them, so they can be allocated while the subsystem is still using them.
So reject a reserve_mem= size or alignment that is not a multiple of PAGE_SIZE to keep both map->start and map->size page aligned.
---
Changes from v1 [1]
- reject non-page-aligned size and align instead of fix page count when preserving reserve_mem regions
[1] https://lore.kernel.org/all/[email protected]/
--- Documentation/admin-guide/kernel-parameters.txt | 3 +++ mm/memblock.c | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +3 -0
@@ -6648,6 +6648,9 @@ Kernel parameters reserve_mem=12M:4096:oops ramoops.mem_name=oops + Both the size and the alignment must be multiples of + the page size. + reservetop= [X86-32,EARLY] Format: nn[KMG] Reserves a hole at the top of the kernel virtual
mm/memblock.c +7 -2
@@ -2816,12 +2816,17 @@ static int __init reserve_mem(char *p)if (*p !=':' ) goto err_param; +if (!IS_ALIGNED (size,PAGE_SIZE ) || !IS_ALIGNED (align,PAGE_SIZE )) { +pr_err ("reserve_mem: size and align must be multiples of the page size\n" ); +return -EINVAL ; + } +/* * memblock_phys_alloc() doesn't like a zero size align, * but it is OK for this command to have it. */ -if (align <SMP_CACHE_BYTES ) - align =SMP_CACHE_BYTES ; +if (!align) + align =PAGE_SIZE ; name = p +1 ; len =strlen (name);
base-commit: dbffc67777cd752ef3f77818109e1d2ef13e2949
Signature · 1 line
2.43.0
Mike Rapoport
maintainer(adding tracing and pstore folks)
Quoted 68 lines · Sang-Heon Jeon
When
map->startormap->sizeis not page aligned,reserved_mem_preserve()does not preserve the last one or two pages of the region frommap->starttomap->start+map->size.After kexec the new kernel reserves only the preserved pages, so those pages are released to the buddy allocator. But
reserve_mem_find_by_name()still returns the whole region including them, so they can be allocated while the subsystem is still using them.So reject a reserve_mem= size or alignment that is not a multiple of
PAGE_SIZEto keep bothmap->startandmap->sizepage aligned.Fixes 8375b76517cb ("kho: replace kho_preserve_phys() with kho_preserve_pages()")Signed-off-by Sang-Heon Jeon <[email protected]>---
Changes from v1 [1]
- reject non-page-aligned size and align instead of fix page count when preservingreserve_memregions[1] https://lore.kernel.org/all/[email protected]/
--- Documentation/admin-guide/kernel-parameters.txt | 3 +++ mm/memblock.c | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-)Documentation/admin-guide/kernel-parameters.txt +3
-0@@ -6648,6 +6648,9 @@ Kernel parameters reserve_mem=12M:4096:oops ramoops.mem_name=oops + Both the size and the alignment must be multiples of + the page size. + reservetop= [X86-32,EARLY] Format: nn[KMG] Reserves a hole at the top of the kernel virtualmm/memblock.c +7
-2@@ -2816,12 +2816,17 @@ static int __init reserve_mem(char *p)if (*p !=':' ) goto err_param; +if (!IS_ALIGNED (size,PAGE_SIZE ) || !IS_ALIGNED (align,PAGE_SIZE )) { +pr_err ("reserve_mem: size and align must be multiples of the page size\n" ); +return -EINVAL ; + } +/* * memblock_phys_alloc() doesn't like a zero size align, * but it is OK for this command to have it. */ -if (align <SMP_CACHE_BYTES ) - align =SMP_CACHE_BYTES ; +if (!align) + align =PAGE_SIZE ; name = p +1 ; len =strlen (name);base-commit:
dbffc67777cd752ef3f77818109e1d2ef13e2949Signature · 1 line
2.43.0
Signature · 2 lines
Sincerely yours, Mike.
Quoted 1 line · Sang-Heon Jeon
memblock: reject non-page-aligned
reserve_memregions
Applied to for-next branch of memblock.git tree, thanks!
[1/1] memblock: reject non-page-aligned reserve_mem regions
commit: 5728d3523f12826a2b180c1c5738f74e33197e14
tree: https://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock
branch: for-next
--
Sincerely yours,
Mike.