kern/dl: Check for the SHF_INFO_LINK flag in grub_dl_relocate_symbols()

The grub_dl_relocate_symbols() iterates through the sections in
an ELF looking for relocation sections. According to the spec [1]
the SHF_INFO_LINK flag should be set if the sh_info field is meant
to be a section index.

[1] https://refspecs.linuxbase.org/elf/gabi4+/ch4.sheader.html

Reported-by: B Horn <b@horn.uk>
Signed-off-by: B Horn <b@horn.uk>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
B Horn authored and Daniel Kiper committed 2025-02-13 15:45:55 +01:00
1 parent d72208423d
commit 98ad84328d
1 file changed
+3
+3
View File
@@ -623,6 +623,9 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
grub_dl_segment_t seg; grub_dl_segment_t seg;
grub_err_t err; grub_err_t err;
if (!(s->sh_flags & SHF_INFO_LINK))
continue;
/* Find the target segment. */ /* Find the target segment. */
for (seg = mod->segment; seg; seg = seg->next) for (seg = mod->segment; seg; seg = seg->next)
if (seg->section == s->sh_info) if (seg->section == s->sh_info)