Skip to content

elf | tool treats whole segment as executable even if sections inside it are read-only #196

Open
@Kristal-g

Description

@Kristal-g

Great tool!

I was surprised at first when I tried to use gadgets that it found, but they were in memory that is not executable or is already freed.
The cause for this is this commit here.

I get that it might be generally more correct to search by segment and not by sections, but it could be useful to have the ability to control that feature, or maybe alert about non-executable sections inside an executable segment.

The use-case for me is searching gadgets in the linux kernel, that has a RWX segment with ".init" sections that get freed after the kernel's initialization:

Section Headers:                                                 
  [Nr] Name              Type             Address           Offset                                                                       
       Size              EntSize          Flags  Link  Info  Align                                                                       
  [ 0]                   NULL             0000000000000000  00000000 
       0000000000000000  0000000000000000           0     0     0
...
 [23] .init.data        PROGBITS         ffffffff83746000  02b46000
       00000000001eb8c0  0000000000000000  WA       0     0     8192
...
Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000200000 0xffffffff81000000 0x0000000001000000
                 0x00000000020e17a8 0x00000000020e17a8  R E    0x200000
  LOAD           0x0000000002400000 0xffffffff83200000 0x0000000003200000
                 0x0000000000449000 0x0000000000449000  RW     0x200000
  LOAD           0x0000000002a00000 0x0000000000000000 0x0000000003649000
                 0x0000000000036000 0x0000000000036000  RW     0x200000
  LOAD           0x0000000002a7f000 0xffffffff8367f000 0x000000000367f000
                 0x0000000001b81000 0x0000000001b81000  RWE    0x200000
  NOTE           0x0000000001d5d5fc 0xffffffff82b5d5fc 0x0000000002b5d5fc
                 0x00000000000001d8 0x00000000000001d8         0x4

 Section to Segment mapping:
  Segment Sections...
   00     .text .rodata .pci_fixup .tracedata __ksymtab __ksymtab_gpl __kcrctab __kcrctab_gpl __ksymtab_strings __init_rodata __param __modver __ex_table .notes .BTF .BTF_ids 
   01     .data __bug_table .vvar 
   02     .data..percpu 
   03     .init.text .altinstr_aux .init.data .x86_cpu_dev.init .parainstructions .retpoline_sites .return_sites .call_sites .altinstructions .altinstr_replacement .apicdrivers .exit.text .smp_locks .data_nosave .bss .brk .init.scratch 
   04     .notes 

I would create a pull request myself, but we should first agree if we want to fix it, and how :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions