Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read/elf: check for relocations that apply to relocations #680

Merged
merged 1 commit into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/read/elf/relocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,25 @@ impl RelocationSections {
continue;
}

let sh_info = section.sh_info(endian) as usize;
if sh_info == 0 {
let sh_info = SectionIndex(section.sh_info(endian) as usize);
if sh_info.0 == 0 {
// Skip dynamic relocations.
continue;
}
if sh_info >= relocations.len() {
if sh_info.0 >= relocations.len() {
return Err(Error("Invalid ELF sh_info for relocation section"));
}

// We don't support relocations that apply to other relocation sections
// because it interferes with the chaining of relocation sections below.
let sh_info_type = sections.section(sh_info)?.sh_type(endian);
if sh_info_type == elf::SHT_REL || sh_info_type == elf::SHT_RELA {
return Err(Error("Unsupported ELF sh_info for relocation section"));
}

// Handle multiple relocation sections by chaining them.
let next = relocations[sh_info];
relocations[sh_info] = index;
let next = relocations[sh_info.0];
relocations[sh_info.0] = index;
relocations[index] = next;
}
}
Expand Down
Loading