Search code examples
linuxmemorypermissionselfreadelf

linux ELF section and header access permission


In my understanding, ELF header is for program execution view. section is for linker's view.

but linux command 'readelf' shows that there are memory access permission flag for each section (AWX) and each header (RWE).

the book say's more than one of section is merged into single header. what happens if when linker merges more than one section into single header and each section has different access permission flags??

and what is the relationship between access permission in /proc/[pid]/maps such as

root@declspec-desktop:/tmp# cat /proc/1951/maps
004a5000-005f8000 r-xp 00000000 08:01 511     /lib/tls/i686/cmov/libc-2.11.1.so
005f8000-005fa000 r--p 00153000 08:01 511     /lib/tls/i686/cmov/libc-2.11.1.so
005fa000-005fb000 rw-p 00155000 08:01 511     /lib/tls/i686/cmov/libc-2.11.1.so

and access permission in section and header??

how does these permissions (in /proc/[pid]/maps) determined?


Solution

  • As per my understanding for your example above, permissions in /proc//maps are the permissions associated with different sections. For example, in the above snippet, entry with permissions - 'r-xp' gives the address of .text segment (location where code is present.) For this reason, if you check, it does not contain 'w' permission as we are not supposed to write new code in an executing binary. So, in your above example -

    004a5000-005f8000 r-xp 00000000 08:01 511     /lib/tls/i686/cmov/libc-2.11.1.so - TEXT AREA which contains executable code
    
    005f8000-005fa000 r--p 00153000 08:01 511     /lib/tls/i686/cmov/libc-2.11.1.so - Area that contains read only variables or constants (.rodata data)
    
    005fa000-005fb000 rw-p 00155000 08:01 511     /lib/tls/i686/cmov/libc-2.11.1.so - Area where we have variables used by program i.e. (.data)
    

    Sorry, i could not follow your other question. Can you please elaborate? Also, which book are you talking about?