Skip to content

Commit 34df6c4

Browse files
ranxiaokaiakpm00
authored andcommitted
kho: fix missing early_memunmap() call in kho_populate()
Patch series "two fixes in kho_populate()", v3. This patch (of 2): kho_populate() returns without calling early_memunmap() on success path, this will cause early ioremap virtual address space leak. Link: https://lkml.kernel.org/r/20260212111146.210086-1-ranxiaokai627@163.com Link: https://lkml.kernel.org/r/20260212111146.210086-2-ranxiaokai627@163.com Fixes: b50634c ("kho: cleanup error handling in kho_populate()") Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn> Reviewed-by: Pratyush Yadav <pratyush@kernel.org> Cc: Alexander Graf <graf@amazon.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 55f8b45 commit 34df6c4

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

kernel/liveupdate/kexec_handover.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,36 +1463,37 @@ void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len,
14631463
struct kho_scratch *scratch = NULL;
14641464
phys_addr_t mem_map_phys;
14651465
void *fdt = NULL;
1466+
bool populated = false;
14661467
int err;
14671468

14681469
/* Validate the input FDT */
14691470
fdt = early_memremap(fdt_phys, fdt_len);
14701471
if (!fdt) {
14711472
pr_warn("setup: failed to memremap FDT (0x%llx)\n", fdt_phys);
1472-
goto err_report;
1473+
goto report;
14731474
}
14741475
err = fdt_check_header(fdt);
14751476
if (err) {
14761477
pr_warn("setup: handover FDT (0x%llx) is invalid: %d\n",
14771478
fdt_phys, err);
1478-
goto err_unmap_fdt;
1479+
goto unmap_fdt;
14791480
}
14801481
err = fdt_node_check_compatible(fdt, 0, KHO_FDT_COMPATIBLE);
14811482
if (err) {
14821483
pr_warn("setup: handover FDT (0x%llx) is incompatible with '%s': %d\n",
14831484
fdt_phys, KHO_FDT_COMPATIBLE, err);
1484-
goto err_unmap_fdt;
1485+
goto unmap_fdt;
14851486
}
14861487

14871488
mem_map_phys = kho_get_mem_map_phys(fdt);
14881489
if (!mem_map_phys)
1489-
goto err_unmap_fdt;
1490+
goto unmap_fdt;
14901491

14911492
scratch = early_memremap(scratch_phys, scratch_len);
14921493
if (!scratch) {
14931494
pr_warn("setup: failed to memremap scratch (phys=0x%llx, len=%lld)\n",
14941495
scratch_phys, scratch_len);
1495-
goto err_unmap_fdt;
1496+
goto unmap_fdt;
14961497
}
14971498

14981499
/*
@@ -1509,7 +1510,7 @@ void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len,
15091510
if (WARN_ON(err)) {
15101511
pr_warn("failed to mark the scratch region 0x%pa+0x%pa: %pe",
15111512
&area->addr, &size, ERR_PTR(err));
1512-
goto err_unmap_scratch;
1513+
goto unmap_scratch;
15131514
}
15141515
pr_debug("Marked 0x%pa+0x%pa as scratch", &area->addr, &size);
15151516
}
@@ -1529,16 +1530,17 @@ void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len,
15291530
kho_in.scratch_phys = scratch_phys;
15301531
kho_in.mem_map_phys = mem_map_phys;
15311532
kho_scratch_cnt = scratch_cnt;
1532-
pr_info("found kexec handover data.\n");
15331533

1534-
return;
1534+
populated = true;
1535+
pr_info("found kexec handover data.\n");
15351536

1536-
err_unmap_scratch:
1537+
unmap_scratch:
15371538
early_memunmap(scratch, scratch_len);
1538-
err_unmap_fdt:
1539+
unmap_fdt:
15391540
early_memunmap(fdt, fdt_len);
1540-
err_report:
1541-
pr_warn("disabling KHO revival\n");
1541+
report:
1542+
if (!populated)
1543+
pr_warn("disabling KHO revival\n");
15421544
}
15431545

15441546
/* Helper functions for kexec_file_load */

0 commit comments

Comments
 (0)