CS FundamentalsVery hardGATE CS

A setuid-root program calls `access(path, R_OK)` to check the real user may read path, then calls `open(path)`. Which vulnerability does this pattern create?

  1. A. A time-of-check-to-time-of-use (TOCTOU) race: an attacker can swap path for a symlink to a protected file between the two calls
  2. B. A buffer overflow in access()
  3. C. A deadlock between access() and open()
  4. D. No vulnerability: access() and open() are atomic together

Correct answer: A. A time-of-check-to-time-of-use (TOCTOU) race: an attacker can swap path for a symlink to a protected file between the two calls

The check and the use are separate system calls, so the file named by path can change in between. The fix is to drop privileges (seteuid) before open or to use open flags such as O_NOFOLLOW and check the opened descriptor.

More Operating Systems questions

Exams that ask this topic