On 2026-10-28T16:23:17+11:00, Jerome Forissier <[email protected]> wrote: > x86: Handle unordered runtime relocations > > Runtime relocation entries are not guaranteed to be sorted by target > address. This was observed with GNU ld 2.42 when linking qemu-x86 using > --emit-relocs and -pie: after an unrelated image-layout change, .rel.dyn > contained 450 address decreases. The old code skipped relocation of > mem_malloc_brk in sbrk(), causing allocation to fail and log_init() to > abort boot. > > The ordering check was added as a cheap corruption guard because .bss > overlays __rel_dyn_start and may overwrite relocation entries before > relocation. Replace it with lower and upper image-bound checks. Together > with the existing type and target checks, these reject most corrupted > entries without requiring sorted input. A corrupted entry whose location > and target both happen to be in range may still be applied; the ordering > check likewise could not reject corruption that preserved increasing > addresses. > > Apply the same correction to the 32-bit and 64-bit paths. > > Fixes: b50b1633c022 ("x86: Add support for 64-bit relocation") > Fixes: 62f7970a5a06 ("x86: Add error checking to x86 relocation code") > Signed-off-by: Jerome Forissier <[email protected]> > > arch/x86/lib/relocate.c | 24 +++++++++++------------- > 1 file changed, 11 insertions(+), 13 deletions(-)
Reviewed-by: Simon Glass <[email protected]>
