Skip to content

Commit ea7165a

Browse files
committed
Reject overflowing ELF section ranges
1 parent 275c2d4 commit ea7165a

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

rpcs3/Loader/ELF.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,9 @@ class elf_object
373373
// Try to find it in phdr data instead of allocating new section
374374
p_index++;
375375

376-
if (hdr.p_offset <= shdr.sh_offset && shdr.sh_offset + shdr.sh_size <= hdr.p_offset + hdr.p_filesz)
376+
if (hdr.p_offset <= shdr.sh_offset &&
377+
shdr.sh_size <= hdr.p_filesz &&
378+
shdr.sh_offset - hdr.p_offset <= hdr.p_filesz - shdr.sh_size)
377379
{
378380
const auto& prog = ::at32(progs, p_index);
379381
shdrs.back().bin_view = {prog.bin.data() + shdr.sh_offset - hdr.p_offset, shdr.sh_size};
@@ -469,7 +471,9 @@ class elf_object
469471
p_index++;
470472

471473
// Rely on previous sh_offset value!
472-
if (hdr.p_offset <= shdr.sh_offset && shdr.sh_offset + shdr.sh_size - 1 <= hdr.p_offset + hdr.p_filesz - 1)
474+
if (hdr.p_offset <= shdr.sh_offset &&
475+
shdr.sh_size <= hdr.p_filesz &&
476+
shdr.sh_offset - hdr.p_offset <= hdr.p_filesz - shdr.sh_size)
473477
{
474478
out.sh_offset = ::narrow<sz_t>(data_base + static_cast<usz>(shdr.sh_offset - hdr.p_offset));
475479
result = true;

0 commit comments

Comments
 (0)