#Why this matters
Every security event, from a login check to a memory-corruption exploit, happens on real hardware. Passwords, encryption keys, and active payloads all exist as bytes in memory while the processor runs instructions one by one. Without understanding how a CPU reads instructions and data from memory, concepts like buffer overflows, shellcode, and memory forensics remain abstract.
#The hardware hierarchy: CPU, cache, and RAM
Modern computers balance speed against capacity in tiers. Storage closest to the processor is fastest and smallest; storage farther away is slower and larger.
- 1RegistersBytes inside each CPU core, instant access
- 2L1 / L2 / L3 CacheKilobytes to megabytes of fast SRAM near cores
- 3RAM (Main Memory)Gigabytes of volatile DRAM holding active programs
- 4SSD / HDD StorageTerabytes of persistent files when power is off
The CPU (Central Processing Unit) contains one or more cores, each running an instruction stream independently. Inside each core sit registers - small named slots (typically 64 bits wide on modern systems) holding numbers under active computation. Two registers matter constantly in security:
- Instruction pointer (
RIPon x86-64): holds the memory address of the next instruction to run. - Stack pointer (
RSPon x86-64): tracks the top of the current function's stack frame.
RAM (Random Access Memory) stores gigabytes of running programs and data, addressed byte by byte. Unlike an SSD, RAM is volatile: removing power clears it within seconds. Between the CPU and RAM sits CPU cache (L1, L2, L3), keeping copies of recently used bytes so the CPU avoids stalling on slower RAM.
#The fetch-decode-execute cycle
General-purpose computers use the von Neumann architecture, storing both program instructions and program data in the same RAM as raw bytes. Each CPU core repeats a three-step loop billions of times per second:
- FetchRead instruction bytes from RAM at the instruction pointer address
- DecodeInterpret the opcode and identify target registers or addresses
- ExecuteRun the operation and update the instruction pointer
Suppose an instruction at address 0x401000 adds 5 to register RAX. The core fetches the bytes from 0x401000, decodes the add operation, executes it in the arithmetic logic unit (ALU), and advances the instruction pointer to 0x401004. Branch instructions (jump, call, ret) redirect the instruction pointer to another address for loops and function calls. Because code and data share RAM, systems must prevent attackers from redirecting the instruction pointer into user-supplied data.
#How a program sits in memory
When a compiled program launches, its bytes map into four main regions:
| Region | Contents | Typical permissions | Security relevance |
|---|---|---|---|
| Text (code) | Compiled machine instructions | Read, Execute | Read-only so code cannot be overwritten |
| Data / BSS | Global and static variables | Read, Write | Holds persistent program state |
| Heap | Dynamically allocated blocks | Read, Write | Target of use-after-free and heap overflows |
| Stack | Local variables, return addresses | Read, Write | Classic buffer overflows overwrite return addresses |
The stack grows and shrinks automatically as functions are called and return; calling a function pushes a return address so execution knows where to resume. The heap holds data allocated explicitly at runtime (such as malloc in C) whose size is not fixed in advance.
#Inspecting CPU and memory in Linux
Check a host's architecture, core count, and memory in a terminal using lscpu and free -h (-h prints human-readable units such as Gi).
$ lscpu | grep -E "Architecture|Byte Order|CPU\(s\)|Model name|L[123]"
Architecture: x86_64
Byte Order: Little Endian
CPU(s): 4
Model name: Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz
L1d cache: 128 KiB
L1i cache: 128 KiB
L2 cache: 1 MiB
L3 cache: 6 MiB
$ free -h
total used free shared buff/cache available
Mem: 15Gi 4.2Gi 6.1Gi 312Mi 5.2Gi 10Gi
Swap: 2.0Gi 0B 2.0GiNotice free (6.1Gi) versus available (10Gi). Linux uses spare RAM as buff/cache to speed up disk reads and reclaims it automatically when programs need memory. Therefore, available shows how much RAM applications can actually use without touching Swap.
#Common mistakes
- Confusing
freewithavailable: Lowfreememory is normal when Linux caches files inbuff/cache; checkavailablebefore assuming memory exhaustion. - Powering off a compromised machine prematurely: Cutting power clears volatile RAM, erasing running scripts and encryption keys.
- Assuming data cannot execute: Without non-executable (
NX) memory protections, redirecting the instruction pointer into writable buffers can execute attacker bytes. - Ignoring byte order: Reading multi-byte addresses backwards on little-endian systems breaks memory analysis.
#Summary
- A CPU executes instructions using fast internal registers, caches, and larger volatile RAM.
- In the fetch-decode-execute cycle, the instruction pointer tracks which bytes in RAM run next.
- Programs split memory into text (code), data, heap, and stack regions.
- On Linux,
lscpureports architecture, endianness, cores, and caches, whilefree -hshows usable memory inavailable.