11.2.2.1 O_NOFOLLOW

If your system supports the O_NOFOLLOW flag 4 to the open(2) system call, find uses it to safely change directories. The target directory is first opened and then find changes working directory with the fchdir() system call. This ensures that symbolic links are not followed, preventing the sort of race condition attack in which use is made of symbolic links.

If for any reason this approach does not work, find will fall back on the method which is normally used if O_NOFOLLOW is not supported.

You can tell if your system supports O_NOFOLLOW by running

find --version | grep Features

This will tell you the version number and which features are enabled. For example, if I run this on my system now, this gives:

Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION \
FTS(FTS_CWDFD) CBO(level=2)

Here, you can see that I am running a version of find which was built from the development (git) code prior to the release of findutils-4.5.12, and that several features including O_NOFOLLOW are present. O_NOFOLLOW is qualified with “enabled”. This simply means that the current system seems to support O_NOFOLLOW. This check is needed because it is possible to build find on a system that defines O_NOFOLLOW and then run it on a system that ignores the O_NOFOLLOW flag. We try to detect such cases at startup by checking the operating system and version number; when this happens you will see ‘O_NOFOLLOW(disabled)’ instead.


Footnotes

(4)

GNU/Linux (kernel version 2.1.126 and later) and FreeBSD (3.0-CURRENT and later) support this