Back to Blog

Weekly Commit #018

December 2, 20262 min read
... views
WeeklyCommitSoftware SecurityConcurrencySoftware EngineeringIST

Last week I ended with one line: the gap between check and use is the claim token problem again. This week that gap followed me from a lab at university to work.

Same bug, two places

In the Software Security lab, we exploited a TOCTOU (Time-of-Check to Time-of-Use) bug. A program checked whether a file was safe to write, and before it opened it, we swapped the file for a symlink. The check was right. It just wasn't true anymore.

A few days later, I ran into the same problem in a task at work. No attacker this time, just two requests arriving at the same moment. Both asked “is this free?”, both heard “yes”, and both acted on it.

The fix depended on what I was checking.

When the row already exists, the check can live inside the write: “save this only if it's still mine”. That's last week's token.

When nothing exists yet, there is no row to put a condition on. “Is there already a batch for this folder?” checks an absence, so the check and the create go under one lock.

And when the work is too big to hold at once, like cancelling thousands of items while workers are still taking them, you flip one flag first. Then you go through the items, re-checking each one, and clean up whatever slips through.

My takeaway: a check only tells you about the past. With an attacker in the gap, security calls it TOCTOU. Without one, it's just a race condition. Seeing it twice in one week is what made it stick.

Smaller things this week

  • Network and Computer Security: the eSports project moved on to choosing technologies and designing our own secure protocol on top of standard primitives. The professor's feedback was that our design looked too much like the bank example from class, so we're pushing for something more specific to eSports.

See you next week.

#WeeklyCommit #SoftwareSecurity #Concurrency #SoftwareEngineering #IST

Follow along here or on LinkedIn where I'll be sharing each new commit.