Skip to content

Lesson 1 of 14 · 10m

The Address Space: Reading /proc/self/maps

How execve maps an ELF into virtual memory — r-xp code, rw-p data, the stack — and why page-table permissions, not conventions, decide what you can run.

The address space is a fiction that happens to be convenient

Here is what happens when your program starts. The kernel's loader — execve() down through load_elf_binary() in fs/binfmt_elf.c — reads the ELF headers, mmap()s the loadable segments into a fresh virtual address space, maps the stack near the top, and hands the CPU a starting rip. Your process never touches physical RAM directly. Every address it will ever see is virtual, translated per-page by hardware page tables the kernel maintains.

You can watch the whole map without a debugger:

cat /proc/self/maps

You'll get lines like:

555555554000-555555558000 r-xp 00001000 08:01 ... /bin/cat
7ffff7dd9000-7ffff7fae000 r-xp 00022000 08:01 ... /usr/lib/libc.so.6
7ffffffde000-7ffffffff000 rw-p 00000000 00:00  [stack]

Three regions matter for everything that follows: the executable mapping (.text, r-xp — read/execute, not writable), the writable data (rw-p — .data, .bss, and every heap allocation malloc ever gives you), and the stack, growing downward from near 0x7ffffffff000 on x86-64. The r-xp/rw-p flags are not suggestions. They are page-table permission bits the CPU enforces on every access. When a lesson later says "NX stops you from executing the stack," this is the mechanism: the stack's pages are mapped rw-p, and the MMU refuses to fetch instructions from them.

The wrong mental model

The model you probably have is "memory is a flat array and C indexes into it." That fails the first time you meet two facts: the stack grows down while buffers fill up, and every region you can see is private to the process. Your 0x7fffffffe450 is not my 0x7fffffffe450; identical virtual addresses in two processes resolve to different physical pages. Pointer addresses are only meaningful inside one process's map — which is why leaking an address is half of every real exploit. The address tells you where a gadget lives this run. ASLR exists to make that answer change every run.

What's actually in the map

  • .text — your compiled code. Mapped r-xp. w^x means the loader can't write it after mapping without mprotect.
  • .data / .bss — globals. .data holds initialized values; .bss is zeroed-on-demand and costs no bytes in the file.
  • Heap — what brk/sbrk grows upward and what glibc's malloc carves into chunks. Large allocations skip the heap entirely: malloc(200 * 1024 * 1024) goes through mmap and gets its own region.
  • Libraries — libc, ld.so, everything dlopen pulls in, each mmap'd as r-xp for code plus rw-p for its globals (including the GOT — remember that for RELRO).
  • Stack — per-thread, rw-p, default 8 MB (ulimit -s). The kernel seeds it with argv, envp, and the ELF auxiliary vector.
  • [vdso] / [vvar] — kernel-provided code pages mapped into your address space so gettimeofday doesn't need a syscall.

GDB will show you the same thing with better labels: info proc mappings inside a session, or gef vmmap if you run GEF. checksec reads PT_GNU_STACK and friends out of the ELF — the binary itself declares whether its stack may execute, and the loader honors the declaration. (pwninit is the other tool you'll meet in this lane, but it's a patchelf wrapper — it relinks the binary against the libc/ld you hand it; it doesn't inspect mitigations.)

Land on practice

Before you exploit anything, read the map. checksec --file=./target tells you which permissions and mitigations are compiled in. /proc/<pid>/maps on a running process tells you where ASLR put libc this run — attach GDB and the debugger disables ASLR by default, so maps under GDB will show you stable addresses that will not match the real world. That's the trap that eats beginners' first ret2libc: addresses captured under gdb are wrong outside it. Either set disable-randomization off, or leak addresses at runtime like every working exploit does.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.