Skip to main content
Be Bitwise

Address Space Layout

Virtual Memory Advanced · Memory & Systems track

7 min read

In this module

Mapping the Process Address Space

Every process has a virtual address space, which the kernel partitions into regions with distinct purposes and permissions. Knowing this layout pays off for debugging, exploit development, and systems programming alike. On Linux, you can peek at any process's memory layout through /proc/pid/maps.

Key Concept

A process's address space is a stack of named regions — text, data, BSS, heap, mmap'd files, libraries, the stack — each with its own permissions. Crashes and exploits often come down to which region holds which bytes, and what r/w/x flags those pages carry.

The Standard Layout

On a typical Linux x86-64 process, the address space is organised from low to high addresses:

That chart lists the regions in order but says nothing about scale. The visualiser below is closer to the real proportions, and it shows the region the chart skips: the enormous non-canonical hole between the top of user space at 0x00007FFFFFFFFFFF and the start of kernel space at 0xFFFF800000000000. With 48-bit virtual addresses, the top 16 bits of any valid address must all copy bit 47, so nothing can be mapped in that gap and touching it raises a general-protection fault. The addresses at the edges of the bars are the real boundaries.

64-bit Virtual Address Space Layout

Kernel SpaceDirect mapping, vmalloc, modules, fixmap0xFFFFFFFFFFFFFFFF0xFFFF800000000000Non-canonical HoleAccess causes #GP faultStackGrows downward0x00007FFFFFFFFFFFmmap RegionShared libraries, file mappingsHeapGrows upward (brk/sbrk)BSS / Data / TextProgram image0x0000000000000000

Hover over a region to see details

Text, Data, and BSS

The text segment holds the executable machine code. It's mapped read-only and executable (r-xp). The read-only protection stops accidental or malicious code modification; the executable permission lets the CPU fetch instructions from these pages.

The data segment (.data) holds initialised global and static variables, mapped read-write (rw-p). The BSS segment (.bss, short for "Block Started by Symbol") holds uninitialised globals. The kernel maps BSS pages as demand-zero: they're backed by zero-filled pages allocated on first access, which saves space in the executable file on disk.

The rodata segment stores read-only data: string literals, constant tables, switch-case jump tables. Mapped read-only (r--p). Whether rodata gets its own non-executable mapping is the linker's call: GNU ld has done it by default on x86-64 Linux since binutils 2.31 (-z separate-code), while older binaries often lump rodata in with the executable text. Keeping them apart stops the CPU from executing data as instructions — defence in depth.

Examining with /proc/pid/maps

The /proc/pid/maps file shows every mapped region in a process. Each line contains: address range, permissions (rwxp/s), offset, device, inode, and pathname. Reading this file reveals the exact layout of code, data, heap, stack, and all loaded libraries. Use cat /proc/self/maps to see your shell's layout, or cat /proc/$(pidof program)/maps for a specific process.

A program can read its own map too. This one takes an address from each region, then looks each address up in /proc/self/maps and prints the line that contains it. Before you run it, predict the permissions each one will show.

Try itAddresses change on every run thanks to ASLR, but each one lands in the same kind of region with the same permissions.
C (GCC 9.2.0)

Look at the permissions column: r-xp for code in your program and in libc (main's caller is the C library's startup code), usually r--p for the literal, rw-p for globals, heap and stack. The small malloc sits in the region labelled [heap], while the 1 MB one lands in an anonymous mapping up near the shared libraries. Depending on the build, initialised and zeroed may share one rw-p line, because BSS often continues straight on from the data segment.

Heap and mmap Region

The heap traditionally grows upward from the end of BSS using the brk() system call. Modern allocators reach mostly for mmap() for large allocations, which places them in the mmap region between heap and stack. Small allocations still use the brk-managed heap for efficiency.

The mmap region holds:

  • Shared libraries (libc.so, libpthread.so, etc.)
  • Large malloc allocations (typically > 128KB in glibc)
  • Memory-mapped files
  • Anonymous mappings (private memory regions)

The mmap region usually grows downward from a high address toward the heap, though the exact behaviour depends on the kernel's virtual address space layout.

Kernel Space

The upper half of the 48-bit address space — addresses starting with 0xFFFF on x86-64 — is reserved for the kernel. User-mode code can't touch any of it; an attempt yields a page fault. The kernel maps its own code, data, page tables, and device memory up there.

The VDSO (Virtual Dynamic Shared Object) is a special kernel-provided shared library mapped into every process at a randomized address near the top of user space. It holds user-space implementations of frequently-used system calls like clock_gettime() and gettimeofday(), dodging the overhead of a kernel transition.

The vsyscall page (legacy, at a fixed address 0xffffffffff600000) played the same role before VDSO came along. It's now emulated for backward compatibility, but new code should reach for VDSO instead.

Stack Layout

The stack starts at a high address and grows downward. Each function call pushes a new stack frame containing saved registers, local variables, the return address, and the frame pointer (if used). The kernel enforces a stack size limit, typically 8MB, configurable with ulimit -s.

Linux grows the stack mapping on demand. When the program touches memory just below the stack's current lowest page, the page fault handler extends the mapping, up to the stack size limit; past that limit, the process gets a SIGSEGV. Since the Stack Clash fixes in kernel 4.12, the kernel also keeps a guard gap (stack_guard_gap, 256 pages, so 1 MB with 4 KB pages) between the stack and any neighbouring mapping. A stack that grows too far faults in that gap instead of silently gnawing into another region.

The initial stack also carries command-line arguments (argv), environment variables (environ), and the auxiliary vector — ELF auxiliary entries with information about the system, used by the dynamic linker.

Why Layout Matters

Address space layout shapes both performance and security. On performance: the relative placement of code, data, and heap dictates cache behaviour and TLB pressure. On security: ASLR randomizes the layout so attackers can't predict addresses, and NX bits on data regions block code injection. Knowing the layout is the foundation for everything from debugging segfaults to writing exploits to tuning memory access patterns.