Lion Cipher Lab
Record and replay a bug backwards with rr: find who overwrote a value
- Cyber / Security Engineer
- Advanced
- ~75 min
- Free · no account required
Why it matters
The hardest bugs are the ones where the damage and the cause are far apart in time. A value is wrong when you print it, but whatever made it wrong ran a long time ago, in code you may not suspect. The usual tools force you to guess: add prints, run again, hope the bug happens again in the same way. A recorder removes the guessing. You capture the bad run once, then replay the same run as many times as you like, including backwards, and ask the question directly: who wrote this byte? Memory corruption, stack and heap overflows and use-after-free bugs are exactly this kind of bug, and the same…
What you'll learn
- explaining record and replay, a trace, and why a replay is deterministic
- checking whether a machine and its virtualisation can run rr, with the perf counter test from the rr wiki
- recording a program with rr record and debugging it with rr replay and gdb
- using watch -l with reverse-continue to find the statement that overwrote a value
- moving backwards through a run with reverse-step and reading the old and new values
- stating the limits of rr: hardware counters, VMs, single-core replay, overhead and untrusted code
Steps in this lab
- The vocabulary, in plain words
- Can your machine run rr? Check before you spend an hour
- Write the buggy program and predict what it does
- Record the run, then replay it in gdb
- Ask the question: who wrote this value?
- Fix it and prove the fix
- Limits, when NOT to use rr, and how a pro does it better
Open the full interactive lab →