Skip to content

Commit

Permalink
added elf_executable_text_filesz to header file
Browse files Browse the repository at this point in the history
  • Loading branch information
elfmaster committed Oct 31, 2022
1 parent 77a198a commit 9206050
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ all:
$(CC) -Wl,-z,separate-code test.c -o test_scop_pie
$(CC) -no-pie -Wl,-z,separate-code test.c -o test_scop_binary
$(CC) -O2 -g pltgot.c -o pltgot ../src/libelfmaster.a
$(CC) -O2 -g scop_check.c -o scop_check ../src/libelfmaster.a
$(CC) phoff.c -o phoff ../src/libelfmaster.a
./stripx test_stripped
./stripx test32_stripped
Expand Down
2 changes: 1 addition & 1 deletion include/libelfmaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ bool elf_write_address(elfobj_t *, uint64_t, uint64_t, typewidth_t width);
size_t __attribute__((deprecated)) elf_scop_text_filesz(elfobj_t *);
uint64_t elf_executable_text_offset(elfobj_t *);
uint64_t elf_executable_text_base(elfobj_t *);

uint64_t elf_executable_text_filesz(elfobj_t *);
/*
* 2nd arg is an output of the number of entries in .symtab
* returns true on success. Same thing for elf_dynsym_count
Expand Down
12 changes: 12 additions & 0 deletions src/libelfmaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,18 @@ elf_executable_text_filesz(struct elfobj *obj)
*/
struct elf_section section;

/*
* If the segment address segment.vaddr is within
* the range of an ELF section who is also claiming
* it has executable perms, then we can avoid finding
* a segment that was marked executable by an attacker
* and assume the linker made the right choice in marking
* the section as executable progbits.
*
* ON THE FLIP SIDE: If an attacker were to modify the
* perm flags of the section that our address resides in...
* well we might not find the right segment.
*/
if (elf_section_by_address(obj, segment.vaddr,
&section) == true) {
if (section.flags & SHF_EXECINSTR)
Expand Down

0 comments on commit 9206050

Please sign in to comment.