Why is there no O_SEARCH flag under Linux for open function?

Viewed 827
3 Answers

On Linux, you can obtain an fd for a directory that only has search permission using O_PATH. On other POSIX systems, you can fork a process and chdir to the directory; whenever you want to do openat relative to that directory, you can have the process perform open for you and send the fd to your main process (AF_UNIX and SCM_RIGHTS are a portable way of doing this).

Neither is strictly equivalent to O_SEARCH in the case where search permissions are revoked from the directory before access. POSIX guarantees that there will be no further permissions checks for an fd opened with O_SEARCH, but both O_PATH and chdir will check on every access.

Related