Lion Cipher Lab

Win a TOCTOU symlink race, then defend against it

Why it matters

TOCTOU (Time-Of-Check-to-Time-Of-Use) is one of the oldest and most stubborn bug classes in privileged software: a program checks that a path is safe, then acts on that same path a moment later, and an attacker changes what the path points to in the gap. It has produced real local-privilege-escalation CVEs in installers, backup agents, container runtimes, package managers, and setuid tools for decades, and it keeps recurring because the naive fix ('check the path again, more carefully') is itself racy. Feeling the race win on your own machine — watching a success counter climb, then watching…

What you'll learn

Steps in this lab

  1. The one idea: 'check' and 'use' are two moments, not one
  2. Set up a scratch lab (no root, self-contained)
  3. Build the vulnerable helper (lstat, then open — CWE-367)
  4. Build the attacker (an atomic symlink swap with RENAME_EXCHANGE)
  5. Wire up the spool, the secret, and the swap pair
  6. Build the measurement harness
  7. Win the race and measure it
  8. Read the result: widening the window, and how a pro wins at delay 0
  9. Defense 1: open first with O_NOFOLLOW, then fstat the descriptor
  10. Re-run the attacker against Defense 1 — watch it hit zero
  11. Defense 2: openat2 with RESOLVE_NO_SYMLINKS / RESOLVE_BENEATH
  12. Re-run against Defense 2 — zero, and it covers more ground
  13. The access() trap: why the naive privileged version is doubly broken
  14. Name the failure modes (and when NOT to worry)

Open the full interactive lab →