I have just noticed that my simple program has its data and stack segments executable. I saw it in /proc/[pid]/maps, and simple code confirmed it.
For example:
; prog.asm
section .data
code: db 0xCC ;int3
section .text
global _start
_start:
jmp code
mov rax, 60 ; sys_exit
mov rdi, 0
syscall
then
nasm -f elf64 prog.asm
ld -o prog prog.o
./prog
causes prog to execute int3 instruction.
Programs written in C and built with gcc have their data, stack and heap non-executable, so why those written in assembly behave in a different manner?