SyntaxPilot
Courses/Cybersecurity Fundamentals/Lesson 55
Video coming soonThis lesson’s video is being made

Start with the notes below; the video appears here as soon as it is on YouTube.

Cybersecurity Fundamentals · Lesson 55 of 90

Exploit mitigations and memory-safe languages

DEP/NXASLRstack canariesPIERELROcontrol-flow integrity (CFI)shadow stacksIntel CETARM pointer authenticationmemory tagging (MTE)sandboxingprivilege separationmemory-safe languages (Rust, Go, Java, C#)Rust ownership and borrow checker (concept)

These are the notes for Cybersecurity Fundamentals (defensive), episode 55. Episode 53 met the memory-corruption bugs (buffer overflows, use-after-free) and episode 54 showed how to write safer C and C++. But people make mistakes, and some bugs always slip through. This episode covers the two answers to that: mitigations built into the compiler, the operating system and the processor that make a leftover bug much harder to abuse, and memory-safe languages that stop these bugs from existing at all. Every term is defined the first time it appears; the Glossary collects them.

Scope. Defensive and educational only. Every program is a toy that works on its own memory; no real system is touched, and no working exploit is shown or explained. Samples were run on 12 Nov 2026 in the SyntaxPilot compiler (gcc 13.3 -O2 on Ubuntu 24.04, rustc 1.97, Go). Ubuntu's gcc turns on PIE, -fstack-protector-strong, full RELRO and a non-executable stack by default. The "no protections" build and the readelf output were produced separately with the same gcc. Addresses differ every run.

The problem: a bug that slips through

Picture the overflow from episode 53: a copy writes 33 characters into a 16-byte box. The extra bytes spill onto whatever is next to the box in memory.

  • The stack is the area of memory where a function keeps its local variables while it runs.
  • When a function is called, the computer stores a return address on the stack: where to go back to when the function finishes. It is like a bookmark.
  • If an overflow overwrites the return address, the function "returns" somewhere else.

To turn a bug into an attack, called an exploit, an attacker needs three things:

Need Mitigation that breaks it
Overwrite the return address stack canary, shadow stack, pointer authentication
Run something useful (their own bytes) DEP / NX (non-executable memory)
Know where things are in memory ASLR, PIE, RELRO

A mitigation is a defence that does not fix the bug but makes it much harder to abuse. With all the mitigations on, the usual worst case of a memory bug becomes "the program stops".

Problem 1: a tamper seal on the stack (stack canary)

Real-life example: a box of sweets has a paper seal across the lid. You can't open the box without tearing the seal, and the shop checks the seal before selling.

A stack canary is a secret random value the compiler places between a function's local buffers and its return address. Before the function returns, it checks the value. An overflow that reaches the return address must overwrite the canary first, so the check fails and the program stops itself (*** stack smashing detected ***). The name comes from the canaries miners once carried as an early warning of bad air.

  • gcc and clang add canaries with -fstack-protector (functions with char arrays), -fstack-protector-strong (more functions; Ubuntu's default) or -fstack-protector-all.
  • The value is random for every run, so an attacker can't just write the right value back.

Demo 1: stack smashing detected

// A copy loop with no size check, into a 16-byte box.
#include <stdio.h>

void save_name(const char *src) {
    char box[16];
    int i = 0;
    while (src[i] != '\0') {      // copies until the end of src...
        box[i] = src[i];          // ...even past the end of box!
        i++;
    }
    box[i] = '\0';
    printf("saved %d chars: %s\n", i, box);
}

int main(void) {
    setvbuf(stdout, NULL, _IONBF, 0);
    save_name("Ravi");                                // fits
    save_name("Ravi Kumar from Pune, Maharashtra");   // 33 chars
    printf("this line never runs\n");
    return 0;
}

Real output (default gcc on Ubuntu, canary on):

saved 4 chars: Ravi
saved 33 chars: Ravi Kumar from Pune, Maharashtra
*** stack smashing detected ***: terminated
Aborted                   (exit code 134)

With and without the canary

$ gcc -O2 -fno-stack-protector -no-pie main.c -o old
$ ./old
saved 4 chars: Ravi
saved 33 chars: Ravi Kumar from Pune, Maharashtra
Segmentation fault        (exit code 139)

$ gcc -O2 main.c -o new        # Ubuntu default: canary ON
$ ./new
saved 4 chars: Ravi
saved 33 chars: Ravi Kumar from Pune, Maharashtra
*** stack smashing detected ***: terminated
Aborted                   (exit code 134)

Without the canary, the function returned to a corrupted address and crashed wildly: a segmentation fault (the program touched memory it was not allowed to). With the canary, it stopped cleanly before returning. The bug is still there in both builds; the canary takes away the exploit, not the bug.

Problem 2: data that can't run (DEP / NX)

Real-life example: a cook follows the recipe book, but never "follows" the vegetable basket. Ingredients are not instructions.

  • Memory is split into pages (small blocks, usually 4 KB). Each page has permissions: read, write, execute.
  • The pages holding the program's code are executable: the processor may run them.
  • The stack and the heap, where input lands, are marked no-execute. The processor's NX bit ("no execute"; Intel calls it XD, AMD calls it NX) enforces this.
  • DEP, Data Execution Prevention, is Windows' name for the same protection.
  • The rule behind it is W^X, "write xor execute": a page may be writable or executable, never both.

Demo 2: running bytes from the stack

// Can data be run as code? Put one machine instruction in an array and call it.
#include <stdio.h>

int main(void) {
    setvbuf(stdout, NULL, _IONBF, 0);
    unsigned char bytes[16] = {0xC3};   // 0xC3 = x86 "ret": does nothing
    void (*run)(void) = (void (*)(void))bytes;
    printf("about to run bytes from the stack...\n");
    run();                              // NX: the stack is not executable
    printf("it ran (no NX)\n");
    return 0;
}

Real output:

about to run bytes from the stack...
Segmentation fault

The single byte 0xC3 is the x86 "return" instruction, which does nothing harmful. The processor still refused to run it, because it lives on the stack and the stack is marked no-execute. So bytes that arrive as input can't be run as code.

Problem 3: addresses that move (ASLR, PIE, RELRO)

Real-life example: a hotel that keeps the safe in room 204 every night is easy to rob once you know. A hotel that moves everything to random rooms every night makes yesterday's map useless.

  • ASLR, Address Space Layout Randomization: each time a program starts, the operating system loads the stack, the heap and the shared libraries at new random addresses. Linux controls it with /proc/sys/kernel/randomize_va_space (2 = full randomization, the default).
  • PIE, Position-Independent Executable: a program built so that its own code can be loaded at any address, so ASLR can move it too. A non-PIE program always loads its code at the same fixed address.
  • A hexadecimal address like 0x5650a3d390c0 is just a memory location written in base 16.

Demo 3: run it twice

// Where do things live in memory? Run it twice.
#include <stdio.h>
#include <stdlib.h>

int counter = 0;                      // a global

int main(void) {
    int local = 42;                   // on the stack
    int *heap = malloc(sizeof *heap); // on the heap
    printf("code   (main)    : %p\n", (void *)main);
    printf("global (counter) : %p\n", (void *)&counter);
    printf("heap   (malloc)  : %p\n", (void *)heap);
    printf("stack  (local)   : %p\n", (void *)&local);
    free(heap);
    return 0;
}

Two real runs (your addresses will differ):

code   (main)    : 0x5650a3d390c0
global (counter) : 0x5650a3d3c014
heap   (malloc)  : 0x5650b7bf72a0
stack  (local)   : 0x7ffe92300034

code   (main)    : 0x5601d3e020c0
global (counter) : 0x5601d3e05014
heap   (malloc)  : 0x5601d8e992a0
stack  (local)   : 0x7ffc1b490224

All four addresses changed between runs. Note the last three hex digits of main (0c0) stay the same: ASLR moves whole pages, so the offset inside a page is kept. ASLR is weaker if a separate bug leaks an address (prints or returns a pointer to the attacker), which is why it is combined with the other layers.

RELRO: protecting the address table

  • Functions like printf live in a shared library (libc), which ASLR also moves.
  • So the program keeps a table of where each library function is: the GOT, Global Offset Table. It is like a phone directory of addresses.
  • If the GOT stays writable, an overflow could change an entry and redirect the next printf call.
  • RELRO, RELocation Read-Only, makes these tables read-only after start-up. Partial RELRO protects some sections; full RELRO (-Wl,-z,relro,-z,now) resolves every library address when the program starts (BIND_NOW) and then makes the whole GOT read-only. Like laminating the phone list.

Check a binary's mitigations with readelf

readelf prints information from a Linux program file (ELF format). Real output on our build:

$ readelf -h new | grep Type
  Type:  DYN (Position-Independent Executable file)    <- PIE
$ readelf -lW new | grep -E "GNU_STACK|GNU_RELRO"
  GNU_STACK ... RW      <- stack: read+write, NOT execute (NX)
  GNU_RELRO ... R       <- this part becomes read-only (RELRO)
$ readelf -d new | grep FLAGS
  (FLAGS)    BIND_NOW   <- resolve all addresses at start
  (FLAGS_1)  Flags: NOW PIE              = FULL RELRO
$ nm -D new | grep stack_chk
  U __stack_chk_fail    <- the canary check is compiled in

The old build (-no-pie -z execstack -z norelro -fno-stack-protector) shows Type: EXEC and GNU_STACK ... RWE (the E means the stack is executable). Scripts such as checksec print the same checklist in one line.

With NX on, attackers can't bring their own code. So they reuse code that's already in the program, chaining small existing pieces together by faking return addresses. This is called return-oriented programming (ROP); a variant using indirect jumps is jump-oriented programming (JOP). We only name these ideas. Both still need control over where the program jumps.

  • Control-flow integrity (CFI): before an indirect call, jump or return, check that the destination is one the program was designed to go to. Like a bus that may only stop at its listed stops. Compilers offer software CFI (for example clang's -fsanitize=cfi, Microsoft's Control Flow Guard).
  • An indirect jump is a jump whose destination is read from memory at run time (a function pointer, a virtual method, a return address), rather than fixed in the code.

Hardware that checks the jumps

Feature Who What it does
Shadow stack idea a second, protected copy of every return address; on return both copies must match
Intel CET (Control-flow Enforcement Technology) Intel; specification 2016, first in Tiger Lake processors a hardware shadow stack, plus indirect branch tracking: an indirect jump must land on an "end branch" (endbr64) instruction
ARM PAC (Pointer Authentication) Arm, from Armv8.3-A adds a cryptographic signature to a pointer such as a return address; a tampered pointer fails the check. Arm: "aimed at thwarting ROP"
ARM BTI (Branch Target Identification) Arm, from Armv8.5-A indirect jumps may only land on marked instructions; against JOP
ARM MTE (Memory Tagging Extension) Arm, introduced 2019 with Armv8.5 gives each 16-byte block of memory and each pointer a small tag ("colour"); a pointer with the wrong tag, e.g. after a use-after-free, is caught

You saw a hint of CET in the disassembly of our build: functions begin with endbr64, the end-branch marker gcc adds with -fcf-protection (Ubuntu's default).

Problem 5: contain the damage (sandboxing, privilege separation)

Real-life example: a bank cashier sits in a locked glass cabin. A robber at the counter can't reach the vault, and the cashier can't open the vault alone.

  • Sandboxing: run risky code (for example the part of a browser that reads web pages) in a box with almost no permissions: no files, no other programs, limited system calls. Taking it over gets the attacker stuck in the box. Linux tools include seccomp, namespaces and containers; browsers sandbox each tab's renderer.
  • Privilege separation: split a program into parts and give each part only the access it needs (least privilege, episode 3). A bug in the part that parses input can't use the powers of the part that holds keys.
  • Google reported that after rewriting Chromium's QR-code generator in Rust and removing its sandbox, it became 20 times faster: sandboxes cost speed, which is another reason to prefer memory-safe code.

Problem 6: remove the bug (memory-safe languages)

How common are memory bugs?

From "The Case for Memory Safe Roadmaps" (December 2023) and Google's Android team (September 2024):

Source Finding
Microsoft about 70% of its CVEs from 2006 to 2018 were memory safety vulnerabilities
Google Chromium about 70% of its identified vulnerabilities were memory safety vulnerabilities
Google Project Zero 67% of zero-day vulnerabilities in 2021 were memory safety vulnerabilities
Android memory safety issues were 76% of vulnerabilities in 2019 and 24% in 2024, after new code moved to memory-safe languages

A CVE is a public ID for a known vulnerability (episode 4). A zero-day is a vulnerability attackers use before the vendor has a fix.

Memory-safe languages

A memory-safe language is one where the compiler or the runtime makes buffer overflows, use-after-free and similar bugs impossible in normal code. Examples: Rust, Go, Java, C#, Python, Swift, Kotlin.

  • Go, Java, C# and Python check every array index at run time (bounds checking) and free memory automatically with a garbage collector: a part of the runtime that frees memory no variable uses any more.
  • Rust gets memory safety without a garbage collector, using two compile-time ideas.

Real-life example: in a school library each book has exactly one owner on the register, who returns it exactly once. Friends may read it, but only while it is still checked out.

  • Ownership: every value in Rust has exactly one owner (a variable). When the owner goes out of scope, the value is freed, once. Assigning it to another variable moves ownership. So there are no leaks and no double frees.
  • Borrowing: a reference (&value) lets code look at a value without owning it.
  • The borrow checker is the part of the Rust compiler that proves no borrow outlives the value it points to, and that a value isn't changed while others are reading it. If it can't prove the code is safe, the program does not compile.
  • unsafe { } blocks turn some checks off for low-level code; keep them tiny and reviewed.

Demo 4: Rust refuses a use-after-free

// Rust: can a reference outlive the thing it points to?
fn main() {
    let r;
    {
        let order = String::from("2 chai mugs");
        r = &order;            // borrow order...
    }                          // ...order is freed here
    println!("r = {}", r);     // use after free?
}

Real compiler error:

error[E0597]: `order` does not live long enough
 --> main.rs:6:13
  |
5 |         let order = String::from("2 chai mugs");
  |             ----- binding `order` declared here
6 |         r = &order;            // borrow order...
  |             ^^^^^^ borrowed value does not live long enough
7 |     }                          // ...order is freed here
  |     - `order` dropped here while still borrowed
8 |     println!("r = {}", r);     // use after free?
  |                        - borrow later used here

In C this is a use-after-free that compiles and runs. In Rust it never becomes a program.

Demo 5: use after move

// Rust ownership: one owner at a time.
fn main() {
    let order = String::from("2 chai mugs");
    let moved = order;             // ownership MOVES to 'moved'
    println!("moved: {}", moved);
    println!("order: {}", order);  // use after move?
}
error[E0382]: borrow of moved value: `order`
 --> main.rs:6:27
  |
3 |     let order = String::from("2 chai mugs");
  |         ----- move occurs because `order` has type `String`, which does not implement the `Copy` trait
4 |     let moved = order;             // ownership MOVES to 'moved'
  |                 ----- value moved here
5 |     println!("moved: {}", moved);
6 |     println!("order: {}", order);  // use after move?
  |                           ^^^^^ value borrowed here after move
  |
help: consider cloning the value if the performance cost is acceptable

The fix: borrow instead of moving.

// Fix: BORROW it (&) instead of moving it.
fn main() {
    let order = String::from("2 chai mugs");
    let view = &order;             // a borrow: look, don't own
    println!("view:  {}", view);
    println!("order: {}", order);  // still the owner
}   // 'order' goes out of scope here: freed exactly once
view:  2 chai mugs
order: 2 chai mugs

Demo 6: Go checks every index

// Go checks every index at run time, too.
package main

import (
    "fmt"
    "os"
)

func main() {
    marks := []int{90, 85, 77, 68}
    i := len(os.Args) + 3 // 4, decided at run time
    fmt.Println("marks[2] =", marks[2])
    fmt.Println("marks[i] =", marks[i]) // index 4 of 4
    fmt.Println("this line never runs")
}

Real output:

marks[2] = 77
panic: runtime error: index out of range [4] with length 4

goroutine 1 [running]:
main.main()
    main.go:13 +0x17a
exit status 2

Java throws ArrayIndexOutOfBoundsException and C# throws IndexOutOfRangeException for the same mistake. A clear stop beats silent memory corruption.

CISA's memory-safe roadmaps

In December 2023, CISA (the US Cybersecurity and Infrastructure Security Agency), with the NSA, the FBI and the cyber agencies of Australia (ASD's ACSC), Canada (CCCS), the UK (NCSC-UK) and New Zealand (NCSC-NZ and CERT NZ), published "The Case for Memory Safe Roadmaps". It asks software manufacturers to:

  • publish a memory safe roadmap: their plan for moving to memory-safe languages;
  • "Publish the date after which the company will write new code solely in an MSL" (memory-safe language);
  • show customers they own security outcomes, with "radical transparency".

Billions of lines of C and C++ will not be rewritten overnight, so: new code in a memory-safe language, old code with every mitigation on.

The whole chain

  1. Overwrite the return address? → a stack canary notices and stops the program.
  2. Run injected bytes? → NX / DEP refuses: data pages can't execute.
  3. Know where things are? → ASLR + PIE move them every run; RELRO locks the GOT.
  4. Reuse existing code (ROP/JOP)? → CFI, shadow stacks (Intel CET), ARM PAC/BTI, MTE check every jump and pointer.
  5. Still got in? → sandboxing and privilege separation contain it.
  6. Best of all → a memory-safe language (Rust, Go, Java, C#) removes the bug itself.

Common mistakes (and the fix)

Mistake What you see Why Fix
gcc -fno-stack-protector app.c the overflow ends in Segmentation fault instead of a clean stop the seal was removed keep the default -fstack-protector-strong
gcc -no-pie app.c readelf -h: Type: EXEC (fixed address) the code can't move with ASLR build as PIE (-fPIE -pie, the default on most distros)
-z execstack GNU_STACK ... RWE the stack is executable again never use it; fix code that needs it
"mitigations are on, so bugs don't matter" a leaked pointer weakens ASLR mitigations make attacks harder, not impossible fix the bug and keep the layers
unsafe { } everywhere in Rust no E0597/E0382 errors to save you unsafe turns checks off keep unsafe tiny, documented and reviewed
using a reference after its value's scope (Rust) error[E0597]: ... does not live long enough the borrow outlives the owner keep the use inside the scope, or move/clone the value out
using a value after moving it (Rust) error[E0382]: borrow of moved value ownership moved borrow with &, or .clone()

Mini project: a mitigation report card

Write a small shell script report.sh that takes a program file and prints a line for each mitigation, using only readelf and nm:

#!/bin/sh
f=$1
readelf -h "$f" | grep -q 'DYN' && echo "PIE:    yes" || echo "PIE:    NO"
readelf -lW "$f" | grep GNU_STACK | grep -q 'RWE' && echo "NX:     NO" || echo "NX:     yes"
readelf -d "$f" | grep -q 'BIND_NOW' && echo "RELRO:  full" || \
  { readelf -lW "$f" | grep -q GNU_RELRO && echo "RELRO:  partial" || echo "RELRO:  none"; }
nm -D "$f" 2>/dev/null | grep -q __stack_chk_fail && echo "Canary: yes" || echo "Canary: NO"

Build the canary toy twice (default flags, and -fno-stack-protector -no-pie -z execstack -z norelro) and compare the two report cards. Only run it on programs you built yourself.

Practice

1. The canary toy printed stack smashing detected. Which line of code caused the problem, and when exactly was it detected?

Solution

box[i] = src[i]; inside the loop wrote past the 16-byte box when copying the 33-character name. It was detected when save_name tried to return: the compiler-inserted check compared the canary with its saved copy, found it changed, and called __stack_chk_fail, which printed the message and aborted.

2. Run the address toy twice. Which part of each address stays the same, and why?

Solution

The last three hex digits (for example 0c0 for main) stay the same. ASLR moves memory in whole pages (4 KB = 0x1000 bytes), so the position inside a page doesn't change; the page-aligned base is randomized.

3. Fix the Rust E0597 example in two different ways.

Solution
// Way 1: use the borrow inside the scope
fn main() {
    let order = String::from("2 chai mugs");
    let r = &order;
    println!("r = {}", r);
}

// Way 2: move the value out instead of borrowing it
fn main() {
    let r;
    {
        let order = String::from("2 chai mugs");
        r = order;           // r now OWNS the string
    }
    println!("r = {}", r);
}

4. Which mitigation stops each of these: (a) bytes from input placed on the stack and jumped to; (b) an overwritten return address; (c) an attacker who reuses a known fixed address from an old build?

Solution

(a) NX/DEP; (b) the stack canary (and a shadow stack or PAC on hardware that has them); (c) ASLR with PIE.

5. Why does sandboxing still matter if a program is written in Rust?

Solution

Memory safety removes one class of bugs, but logic bugs, unsafe blocks, bugs in C libraries the program calls, and mistakes in access control still exist. A sandbox limits the damage of any compromise, whatever its cause. Defence in depth.

Quick quiz

$ ./app
saved 4 chars: Ravi
saved 33 chars: Ravi Kumar from Pune, Maharashtra
*** stack smashing detected ***: terminated
Aborted

Which defence printed this? A: ASLR · B: NX / DEP · C: Stack canary · D: RELRO

Answer

C, the stack canary. The overflow changed the secret value between the buffer and the return address, and the check before return caught it. ASLR moves addresses, NX stops data from running, RELRO makes the GOT read-only.

Interview questions

  1. What is the difference between a mitigation and a fix? A fix removes the bug; a mitigation leaves the bug but makes it much harder to turn into an exploit (often turning it into a crash).
  2. How does a stack canary work, and what can't it stop? A random value sits between local buffers and the saved return address and is checked before return. It does not stop overflows that skip over it, overwrite other local variables or function pointers before the check, heap overflows, or reads (information leaks).
  3. Why do ASLR and NX work best together? NX stops injected code from running, so attackers reuse existing code (ROP), which needs known addresses; ASLR randomizes those addresses. Each covers the other's gap.
  4. What does PIE add to ASLR? It lets the program's own code be loaded at a random base; without PIE, the main executable stays at a fixed address even with ASLR on.
  5. Partial vs full RELRO? Partial makes some relocation sections read-only; full also resolves all symbols at start (BIND_NOW) and makes the whole GOT read-only.
  6. What is a shadow stack? A separate protected stack holding copies of return addresses; on return, the CPU (Intel CET) or software compares them and stops on a mismatch.
  7. How does Rust prevent use-after-free without a garbage collector? Ownership frees each value exactly once when its owner goes out of scope, and the borrow checker proves at compile time that no reference outlives its value.
  8. What did CISA's 2023 memory-safe roadmap guidance ask for? That software manufacturers publish a roadmap for moving to memory-safe languages, including a date after which new code is written only in one.

Glossary

Term Meaning
stack memory area where a running function keeps its local variables and return address
heap memory area for data allocated while the program runs (malloc, new)
return address where a function goes back to when it finishes; stored on the stack
exploit (concept) turning a bug into an attack that makes a program do what an attacker wants
mitigation a defence that makes a bug harder to abuse without fixing the bug
stack canary a random value between local buffers and the return address, checked before return
-fstack-protector-strong the gcc/clang flag that adds canaries to functions with arrays or local addresses
stack smashing detected glibc's message when a canary check fails; the program aborts
segmentation fault (SIGSEGV) the program touched memory it isn't allowed to; the OS stops it
page a small block of memory (usually 4 KB) with its own read/write/execute permissions
NX bit a processor flag marking a page "no execute" (Intel calls it XD)
DEP Data Execution Prevention: Windows' name for non-executable data memory
W^X "write xor execute": memory may be writable or executable, never both
ASLR Address Space Layout Randomization: stack, heap and libraries load at random addresses every run
PIE Position-Independent Executable: a program whose own code can load at any address, so ASLR can move it
shared library code used by many programs, loaded at run time (e.g. libc, which holds printf)
GOT Global Offset Table: the program's table of library function addresses
RELRO RELocation Read-Only: makes the GOT and related tables read-only after start-up (partial or full)
BIND_NOW resolve all library addresses at start; needed for full RELRO
readelf a tool that prints information from Linux (ELF) program files
checksec a popular script that lists a binary's mitigations
ROP return-oriented programming: reusing small pieces of existing code by faking return addresses (concept)
JOP jump-oriented programming: the same idea using indirect jumps (concept)
indirect jump a jump whose destination is read from memory at run time (function pointer, return address)
CFI control-flow integrity: checking that every indirect jump or return goes to a legal destination
shadow stack a protected second copy of return addresses, compared on return
Intel CET Control-flow Enforcement Technology: hardware shadow stack + indirect branch tracking (endbr64)
ARM PAC Pointer Authentication (Armv8.3-A): a cryptographic signature on pointers such as return addresses
ARM BTI Branch Target Identification (Armv8.5-A): indirect jumps may only land on marked instructions
MTE Memory Tagging Extension (Arm, 2019, Armv8.5): matching tags on memory and pointers catch wrong accesses
sandboxing running risky code with almost no permissions, so a compromise stays contained
privilege separation splitting a program into parts that each get only the access they need
least privilege give every part only the access it needs, nothing more
memory-safe language a language that prevents overflows, use-after-free and similar bugs in normal code (Rust, Go, Java, C#, Python)
bounds checking checking every array index at run time and stopping on an out-of-range one
garbage collector part of a runtime that frees memory no longer used, automatically
ownership (Rust) every value has one owner; it is freed exactly once when the owner goes out of scope
move (Rust) assigning a value transfers ownership; the old variable can't be used
borrow (Rust) a reference &x that looks at a value without owning it
borrow checker the Rust compiler stage that proves no borrow outlives its value
unsafe (Rust) a block where some compiler checks are switched off
E0597 / E0382 Rust errors: "does not live long enough" / "borrow of moved value"
panic (Go/Rust) a run-time stop on an unrecoverable error, such as an index out of range
CVE a public ID for a known vulnerability
zero-day a vulnerability used by attackers before a fix exists
CISA the US Cybersecurity and Infrastructure Security Agency
memory-safe roadmap a company's published plan and date for moving new code to memory-safe languages

Summary

  • A mitigation keeps the bug but shrinks the damage; layered mitigations turn most memory bugs into a clean stop.
  • Stack canaries detect a smashed stack before return; NX/DEP stops data from running; ASLR + PIE move everything each run; RELRO locks the GOT. All are on by default in modern compilers; check with readelf.
  • CFI and hardware (Intel CET shadow stacks, ARM PAC/BTI, MTE) stop code reuse and bad pointers.
  • Sandboxing and privilege separation contain whatever still gets through.
  • Memory-safe languages remove the bug class: Rust's ownership and borrow checker reject use-after-free at compile time; Go, Java and C# check bounds at run time. CISA and its partners ask vendors to publish memory-safe roadmaps.
  • Next episode: secure coding in Java: memory-safe, but with its own traps.

Sources (fetched 12 Nov 2026)

  • CISA, NSA, FBI and partners, "The Case for Memory Safe Roadmaps", December 2023: https://media.defense.gov/2023/Dec/06/2003352724/-1/-1/0/THE-CASE-FOR-MEMORY-SAFE-ROADMAPS-TLP-CLEAR.PDF and https://www.cisa.gov/resources-tools/resources/case-memory-safe-roadmaps
  • Google Security Blog, "Eliminating Memory Safety Vulnerabilities at the Source", 25 Sep 2024: https://security.googleblog.com/2024/09/eliminating-memory-safety-vulnerabilities-Android.html
  • Arm Newsroom, "Enabling Pointer Authentication and Branch Target Identification": https://newsroom.arm.com/blog/pac-bti
  • Dark Reading, "Intel Tackles Malware Related to Memory Security at Hardware Level" (Intel CET): https://www.darkreading.com/vulnerabilities-threats/intel-tackles-malware-related-to-memory-security-at-hardware-level