Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Jowett <[email protected]>
  • Loading branch information
Alan-Jowett committed Jan 8, 2025
1 parent 768692b commit 0eec122
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/asm_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,15 +475,11 @@ vector<raw_program> read_elf(std::istream& input_stream, const std::string& path
continue;
}
offset -= program_offset;

// Relocation is always on a double width instruction, so check that the offset is within the
// program and that offset + 1 is within the program.
if (((offset / sizeof(ebpf_inst)) + 1) >= prog.prog.size()) {
if (offset / sizeof(ebpf_inst) >= prog.prog.size()) {
throw UnmarshalError("Invalid relocation data");
}

ebpf_inst& reloc_inst = prog.prog[offset / sizeof(ebpf_inst)];
ebpf_inst& next_reloc_inst = prog.prog[offset / sizeof(ebpf_inst) + 1];

auto [symbol_name, symbol_section_index] = get_symbol_name_and_section_index(symbols, index);

Expand All @@ -497,6 +493,15 @@ vector<raw_program> read_elf(std::istream& input_stream, const std::string& path
continue;
}

// Verify that this is a map or global variable relocation.
verify_load_instruction(reloc_inst, symbol_name, offset);

// Load instructions are two instructions long, so we need to check the next instruction.
if (prog.prog.size() <= offset / sizeof(ebpf_inst) + 1) {
throw UnmarshalError("Invalid relocation data");
}
ebpf_inst& next_reloc_inst = prog.prog[offset / sizeof(ebpf_inst) + 1];

// Perform relocation for symbols located in the maps section.
if (map_section_indices.contains(symbol_section_index)) {
relocate_map(reloc_inst, symbol_name, map_record_size_or_map_offsets, info, offset, index,
Expand Down

0 comments on commit 0eec122

Please sign in to comment.