Skip to content

Interview question · Systems, OS & Memory Safety

What is a TOCTOU race, how does it turn into privilege escalation through files, and how do you write privileged code that avoids it?

Check, then use: two system calls, and an attacker in between. The answer interviewers want replaces names with handles and checks with atomic operations, and can show it in code.

hardNewPreparation tags: Google, Microsoft, AppleUpdated Nov 2026

Check, then use: two system calls, and an attacker in between. The answer interviewers want replaces names with handles and checks with atomic operations, and can show it in code.

Make your first attempt

What would you say before reading the answer?

  1. 01 State the assumptions your answer depends on.
  2. 02 Explain the mechanism and choose a control.
  3. 03 Name a condition that would change your decision.

The worked answer includes an approach, scoring criteria and follow-up questions. Compare the reasoning with your own.

signing in unlocks more free answers per topic

What if · the follow-ups in this answer

The answer works through 6 follow-ups like an interviewer would

A privileged backup script checks that a file in /tmp belongs to the user, then opens and copies it.

  1. What is a time-of-check to time-of-use race?
  2. Why is this script dangerous?
  3. How do you fix it?
  4. What about creating temporary files?
  5. Can the script avoid the problem entirely?
  6. How would you fix the script?

Each rung has a nudge, a model answer, the principle that carries over and the weak answer to avoid. Sign in free to open it.

UP NEXT ON YOUR JOURNEY
DISCUSSION · 0

No comments yet. Share a correction or a different way to answer it.