Is it possible to make the .data section of an ELF file executable?

I've tried to make the .data section executable by changing the flags of the .data section, but it simply doesn't work. Is it not possible by system design? I'm looking for a method other than dynamically modifying permissions with mprotect.


  • 2
    "It simply doesn't work" is a very bad error description. Which flags did you change? Which value did they have before and after the change? What did you do to check? What did you expect? What happened instead? – Guntram Blohm Nov 13 '14 at 15:21
  • changed the flags field of .data section header to 7(rwx) and then executed the binary and checked the memory map of the process by cat /proc/pid/maps. it said .data section is still rw-. – user10007 Nov 13 '14 at 15:31

The .data section is going together with the stack, therefore, you only need to compile your program with the option -zexecstack to get it executable. For example:

gcc -Wall -Wextra -zexecstack -fno-stack-protector -o example example.c

For executables or shared objects, the kernel/dynamic loader uses not the section table but the segment table (program headers). That's the one you need to patch (usually the second PT_LOAD entry describes the .data+.bss sections). See readelf -l.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.