title: Linux default behavior of executable .data section changed between 5.4 and 5.9?
body: <h1>Story</h1>
  <h3>Case 1</h3>
  <p>I accidentally wrote my Assembly code in the <code>.data</code> section. I compiled it and executed it. The program ran normally under Linux <code>5.4.0-53-generic</code> even though I didn't specify a flag like <code>execstack</code>.</p>
  <h3>Case 2:</h3>
  <p>After that, I executed the program under Linux <code>5.9.0-050900rc5-generic</code>. The program got <code>SIGSEGV</code>. I inspected the virtual memory permission by reading <code>/proc/$pid/maps</code>. It turned out that the section is not executable.</p>
  <p>I think there is a configuration on Linux that manages that permission. But I don't know where to find.</p>
  <h1>Code</h1>
  <h2>[Linux 5.4.0-53-generic]</h2>
  <h3>Run (normal)</h3>
  <pre><code>ammarfaizi2@integral:/tmp$ uname -r
  5.4.0-53-generic
  ammarfaizi2@integral:/tmp$ cat test.asm
  [section .data]
  global _start
  _start:
    mov eax, 60
    xor edi, edi
    syscall
  ammarfaizi2@integral:/tmp$ nasm --version
  NASM version 2.14.02
  ammarfaizi2@integral:/tmp$ nasm -felf64 test.asm -o test.o
  ammarfaizi2@integral:/tmp$ ld test.o -o test
  ammarfaizi2@integral:/tmp$ ./test
  ammarfaizi2@integral:/tmp$ echo $?
  0
  ammarfaizi2@integral:/tmp$ md5sum test
  7ffff5fd44e6ff0a278e881732fba525  test
  ammarfaizi2@integral:/tmp$ 
  </code></pre>
  <h3>Check Permission (00400000-00402000 rwxp), so it is executable.</h3>
  <pre><code>## Debug
  gef➤  shell cat /proc/`pgrep test`/maps
  00400000-00402000 rwxp 00000000 08:03 7471589                            /tmp/test
  7ffff7ffb000-7ffff7ffe000 r--p 00000000 00:00 0                          [vvar]
  7ffff7ffe000-7ffff7fff000 r-xp 00000000 00:00 0                          [vdso]
  7ffffffde000-7ffffffff000 rwxp 00000000 00:00 0                          [stack]
  ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0                  [vsyscall]
  gef➤
  </code></pre>
  <h2>[Linux 5.9.0-050900rc5-generic]</h2>
  <h3>Run (Segfault)</h3>
  <pre><code>root@esteh:/tmp# uname -r
  5.9.0-050900rc5-generic
  root@esteh:/tmp# cat test.asm
  [section .data]
  global _start
  _start:
    mov eax, 60
    xor edi, edi
    syscall
  root@esteh:/tmp# nasm --version
  NASM version 2.14.02
  root@esteh:/tmp# nasm -felf64 test.asm -o test.o
  root@esteh:/tmp# ld test.o -o test
  root@esteh:/tmp# ./test
  Segmentation fault (core dumped)
  root@esteh:/tmp# echo $?
  139
  root@esteh:/tmp# md5sum test
  7ffff5fd44e6ff0a278e881732fba525  test
  root@esteh:/tmp# 
  </code></pre>
  <h3>Check Permission (00400000-00402000 rw-p), so it is NOT executable.</h3>
  <pre><code>## Debug
  gef➤  shell cat /proc/`pgrep test`/maps
  00400000-00402000 rw-p 00000000 fc:01 2412                               /tmp/test
  7ffff7ff9000-7ffff7ffd000 r--p 00000000 00:00 0                          [vvar]
  7ffff7ffd000-7ffff7fff000 r-xp 00000000 00:00 0                          [vdso]
  7ffffffde000-7ffffffff000 rw-p 00000000 00:00 0                          [stack]
  ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0                  [vsyscall]
  gef➤  
  </code></pre>
  <h1>objdump -p</h1>
  <pre><code>root@esteh:/tmp# objdump -p test
  
  test:     file format elf64-x86-64
  
  Program Header:
      LOAD off    0x0000000000000000 vaddr 0x0000000000400000 paddr 0x0000000000400000 align 2**12
           filesz 0x0000000000001009 memsz 0x0000000000001009 flags rw-
  
  </code></pre>
  <h1>Questions</h1>
  <ol>
  <li>Where is the configuration on Linux that manages default ELF sections permission?</li>
  <li>Are my observations on permissions correct?</li>
  </ol>
  <h1>Summary</h1>
  <ul>
  <li>Default permission for <code>.data</code> section on Linux <code>5.4.0-53-generic</code> is executable.</li>
  <li>Default permission for <code>.data</code> section on Linux <code>5.9.0-050900rc5-generic</code> is <strong>NOT</strong> executable.</li>
  </ul>