I'm reading this paper. On the page 11 the paper says:
Unix applications can obtain access to files without encountering symlink races. This is important for normal application programmers who, for example, might want to write an ftp server that securely checks file system accesses against a security policy. The programmer can accomplish this by leveraging the fact that the current working directory of a process is private state and will not change between the time that it performs a check on a file relative to this directory, and the time that the call completes. The programmer can leverage this to perform a race free open by recursively expanding (via readlink) and following a path one component at a time until they have reached a file, or until they have found that the path violates policy.
The paper is describing a technique for avoiding time-of-check to time-of-use issues when checking and opening a file path. In other words, we have a file path that we want to make sure that it doesn't violate some security policy before opening it. But we should avoid time-of-check to time-of-use issues. The paper is describing a method for doing so using the readlink function. I can't understand the technique that it is describing. Can someone elaborate this technique?
alarm()
or some variation of it to interrupt my process with a signal and run a signal handler asynchronously. – Negatereadlink()
race condition vulnerability disappears if you only pass the value(s) into the kernel once and evaluate them there and the value acted is always the value that was evaluated. Whatever file the link(s) that were copied into kernel space and evaluated refer to will be the file checked for access and then opened. Or not. There's then no way to evaluate a link to/tmp/foo
, allow further access, and then have the actual system call act on an unallowed link to/etc/shadow
because something modified the data. – Negate