GDB temporarily sets write permissions
No.
On Linux / * 86, ptrace() (which is what GDB uses to read and write incomplete (being debugged) RAM) allows you to read and write pages that are not read / write inferior, which leads exactly to the confusion that you described .
This can be considered a bug in the kernel.
It should be noted that the kernel should allow ptrace to write to the normally non-writable .text section for the debugger in order to be able to set breakpoints (which is done by overwriting the original command with the breakpoint / trap - int3 through the PTRACE_POKETEXT request).
The kernel does not have to do the same for POKE_DATA , but man ptrace says:
PTRACE_POKETEXT, PTRACE_POKEDATA Copies the word data to location addr in the child memory. As above, the two requests are currently equivalent.
I believe the equivalence that causes the current behavior.
source share