359 lines
11 KiB
HTML
359 lines
11 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of PATH_RESOLUTION</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>PATH_RESOLUTION</H1>
|
|
Section: Linux Programmer's Manual (7)<BR>Updated: 2017-11-26<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
path_resolution - how a pathname is resolved to a file
|
|
<A NAME="lbAC"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
Some UNIX/Linux system calls have as parameter one or more filenames.
|
|
A filename (or pathname) is resolved as follows.
|
|
<A NAME="lbAD"> </A>
|
|
<H3>Step 1: start of the resolution process</H3>
|
|
|
|
If the pathname starts with the '/' character,
|
|
the starting lookup directory
|
|
is the root directory of the calling process.
|
|
(A process inherits its
|
|
root directory from its parent.
|
|
Usually this will be the root directory
|
|
of the file hierarchy.
|
|
A process may get a different root directory
|
|
by use of the
|
|
<B><A HREF="/cgi-bin/man/man2html?2+chroot">chroot</A></B>(2)
|
|
|
|
system call.
|
|
A process may get an entirely private mount namespace in case
|
|
it---or one of its ancestors---was started by an invocation of the
|
|
<B><A HREF="/cgi-bin/man/man2html?2+clone">clone</A></B>(2)
|
|
|
|
system call that had the
|
|
<B>CLONE_NEWNS</B>
|
|
|
|
flag set.)
|
|
This handles the '/' part of the pathname.
|
|
<P>
|
|
|
|
If the pathname does not start with the '/' character, the
|
|
starting lookup directory of the resolution process is the current working
|
|
directory of the process.
|
|
(This is also inherited from the parent.
|
|
It can be changed by use of the
|
|
<B><A HREF="/cgi-bin/man/man2html?2+chdir">chdir</A></B>(2)
|
|
|
|
system call.)
|
|
<P>
|
|
|
|
Pathnames starting with a '/' character are called absolute pathnames.
|
|
Pathnames not starting with a '/' are called relative pathnames.
|
|
<A NAME="lbAE"> </A>
|
|
<H3>Step 2: walk along the path</H3>
|
|
|
|
Set the current lookup directory to the starting lookup directory.
|
|
Now, for each nonfinal component of the pathname, where a component
|
|
is a substring delimited by '/' characters, this component is looked up
|
|
in the current lookup directory.
|
|
<P>
|
|
|
|
If the process does not have search permission on
|
|
the current lookup directory,
|
|
an
|
|
<B>EACCES</B>
|
|
|
|
error is returned ("Permission denied").
|
|
<P>
|
|
|
|
If the component is not found, an
|
|
<B>ENOENT</B>
|
|
|
|
error is returned
|
|
("No such file or directory").
|
|
<P>
|
|
|
|
If the component is found, but is neither a directory nor a symbolic link,
|
|
an
|
|
<B>ENOTDIR</B>
|
|
|
|
error is returned ("Not a directory").
|
|
<P>
|
|
|
|
If the component is found and is a directory, we set the
|
|
current lookup directory to that directory, and go to the
|
|
next component.
|
|
<P>
|
|
|
|
If the component is found and is a symbolic link (symlink), we first
|
|
resolve this symbolic link (with the current lookup directory
|
|
as starting lookup directory).
|
|
Upon error, that error is returned.
|
|
If the result is not a directory, an
|
|
<B>ENOTDIR</B>
|
|
|
|
error is returned.
|
|
If the resolution of the symlink is successful and returns a directory,
|
|
we set the current lookup directory to that directory, and go to
|
|
the next component.
|
|
Note that the resolution process here can involve recursion if the
|
|
prefix ('dirname') component of a pathname contains a filename
|
|
that is a symbolic link that resolves to a directory (where the
|
|
prefix component of that directory may contain a symbolic link, and so on).
|
|
In order to protect the kernel against stack overflow, and also
|
|
to protect against denial of service, there are limits on the
|
|
maximum recursion depth, and on the maximum number of symbolic links
|
|
followed.
|
|
An
|
|
<B>ELOOP</B>
|
|
|
|
error is returned when the maximum is
|
|
exceeded ("Too many levels of symbolic links").
|
|
<P>
|
|
|
|
|
|
|
|
|
|
|
|
As currently implemented on Linux, the maximum number
|
|
|
|
of symbolic links that will be followed while resolving a pathname is 40.
|
|
In kernels before 2.6.18, the limit on the recursion depth was 5.
|
|
Starting with Linux 2.6.18, this limit
|
|
|
|
was raised to 8.
|
|
In Linux 4.2,
|
|
|
|
the kernel's pathname-resolution code
|
|
was reworked to eliminate the use of recursion,
|
|
so that the only limit that remains is the maximum of 40
|
|
resolutions for the entire pathname.
|
|
<A NAME="lbAF"> </A>
|
|
<H3>Step 3: find the final entry</H3>
|
|
|
|
The lookup of the final component of the pathname goes just like
|
|
that of all other components, as described in the previous step,
|
|
with two differences: (i) the final component need not be a
|
|
directory (at least as far as the path resolution process is
|
|
concerned---it may have to be a directory, or a nondirectory, because of
|
|
the requirements of the specific system call), and (ii) it
|
|
is not necessarily an error if the component is not found---maybe
|
|
we are just creating it.
|
|
The details on the treatment
|
|
of the final entry are described in the manual pages of the specific
|
|
system calls.
|
|
<A NAME="lbAG"> </A>
|
|
<H3>. and ..</H3>
|
|
|
|
By convention, every directory has the entries "." and "..",
|
|
which refer to the directory itself and to its parent directory,
|
|
respectively.
|
|
<P>
|
|
|
|
The path resolution process will assume that these entries have
|
|
their conventional meanings, regardless of whether they are
|
|
actually present in the physical filesystem.
|
|
<P>
|
|
|
|
One cannot walk down past the root: "/.." is the same as "/".
|
|
<A NAME="lbAH"> </A>
|
|
<H3>Mount points</H3>
|
|
|
|
After a "mount dev path" command, the pathname "path" refers to
|
|
the root of the filesystem hierarchy on the device "dev", and no
|
|
longer to whatever it referred to earlier.
|
|
<P>
|
|
|
|
One can walk out of a mounted filesystem: "path/.." refers to
|
|
the parent directory of "path",
|
|
outside of the filesystem hierarchy on "dev".
|
|
<A NAME="lbAI"> </A>
|
|
<H3>Trailing slashes</H3>
|
|
|
|
If a pathname ends in a '/', that forces resolution of the preceding
|
|
component as in Step 2: it has to exist and resolve to a directory.
|
|
Otherwise, a trailing '/' is ignored.
|
|
(Or, equivalently, a pathname with a trailing '/' is equivalent to
|
|
the pathname obtained by appending '.' to it.)
|
|
<A NAME="lbAJ"> </A>
|
|
<H3>Final symlink</H3>
|
|
|
|
If the last component of a pathname is a symbolic link, then it
|
|
depends on the system call whether the file referred to will be
|
|
the symbolic link or the result of path resolution on its contents.
|
|
For example, the system call
|
|
<B><A HREF="/cgi-bin/man/man2html?2+lstat">lstat</A></B>(2)
|
|
|
|
will operate on the symlink, while
|
|
<B><A HREF="/cgi-bin/man/man2html?2+stat">stat</A></B>(2)
|
|
|
|
operates on the file pointed to by the symlink.
|
|
<A NAME="lbAK"> </A>
|
|
<H3>Length limit</H3>
|
|
|
|
There is a maximum length for pathnames.
|
|
If the pathname (or some
|
|
intermediate pathname obtained while resolving symbolic links)
|
|
is too long, an
|
|
<B>ENAMETOOLONG</B>
|
|
|
|
error is returned ("Filename too long").
|
|
<A NAME="lbAL"> </A>
|
|
<H3>Empty pathname</H3>
|
|
|
|
In the original UNIX, the empty pathname referred to the current directory.
|
|
Nowadays POSIX decrees that an empty pathname must not be resolved
|
|
successfully.
|
|
Linux returns
|
|
<B>ENOENT</B>
|
|
|
|
in this case.
|
|
<A NAME="lbAM"> </A>
|
|
<H3>Permissions</H3>
|
|
|
|
The permission bits of a file consist of three groups of three bits; see
|
|
<B><A HREF="/cgi-bin/man/man2html?1+chmod">chmod</A></B>(1)
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?2+stat">stat</A></B>(2).
|
|
|
|
The first group of three is used when the effective user ID of
|
|
the calling process equals the owner ID of the file.
|
|
The second group
|
|
of three is used when the group ID of the file either equals the
|
|
effective group ID of the calling process, or is one of the
|
|
supplementary group IDs of the calling process (as set by
|
|
<B><A HREF="/cgi-bin/man/man2html?2+setgroups">setgroups</A></B>(2)).
|
|
|
|
When neither holds, the third group is used.
|
|
<P>
|
|
|
|
Of the three bits used, the first bit determines read permission,
|
|
the second write permission, and the last execute permission
|
|
in case of ordinary files, or search permission in case of directories.
|
|
<P>
|
|
|
|
Linux uses the fsuid instead of the effective user ID in permission checks.
|
|
Ordinarily the fsuid will equal the effective user ID, but the fsuid can be
|
|
changed by the system call
|
|
<B><A HREF="/cgi-bin/man/man2html?2+setfsuid">setfsuid</A></B>(2).
|
|
|
|
<P>
|
|
|
|
(Here "fsuid" stands for something like "filesystem user ID".
|
|
The concept was required for the implementation of a user space
|
|
NFS server at a time when processes could send a signal to a process
|
|
with the same effective user ID.
|
|
It is obsolete now.
|
|
Nobody should use
|
|
<B><A HREF="/cgi-bin/man/man2html?2+setfsuid">setfsuid</A></B>(2).)
|
|
|
|
<P>
|
|
|
|
Similarly, Linux uses the fsgid ("filesystem group ID")
|
|
instead of the effective group ID.
|
|
See
|
|
<B><A HREF="/cgi-bin/man/man2html?2+setfsgid">setfsgid</A></B>(2).
|
|
|
|
|
|
<A NAME="lbAN"> </A>
|
|
<H3>Bypassing permission checks: superuser and capabilities</H3>
|
|
|
|
On a traditional UNIX system, the superuser
|
|
(<I>root</I>,
|
|
|
|
user ID 0) is all-powerful, and bypasses all permissions restrictions
|
|
when accessing files.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<P>
|
|
|
|
On Linux, superuser privileges are divided into capabilities (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+capabilities">capabilities</A></B>(7)).
|
|
|
|
Two capabilities are relevant for file permissions checks:
|
|
<B>CAP_DAC_OVERRIDE</B>
|
|
|
|
and
|
|
<B>CAP_DAC_READ_SEARCH</B>.
|
|
|
|
(A process has these capabilities if its fsuid is 0.)
|
|
<P>
|
|
|
|
The
|
|
<B>CAP_DAC_OVERRIDE</B>
|
|
|
|
capability overrides all permission checking,
|
|
but grants execute permission only when at least one
|
|
of the file's three execute permission bits is set.
|
|
<P>
|
|
|
|
The
|
|
<B>CAP_DAC_READ_SEARCH</B>
|
|
|
|
capability grants read and search permission
|
|
on directories, and read permission on ordinary files.
|
|
|
|
|
|
<A NAME="lbAO"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+readlink">readlink</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+capabilities">capabilities</A></B>(7),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+credentials">credentials</A></B>(7),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+symlink">symlink</A></B>(7)
|
|
|
|
<A NAME="lbAP"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">DESCRIPTION</A><DD>
|
|
<DL>
|
|
<DT id="3"><A HREF="#lbAD">Step 1: start of the resolution process</A><DD>
|
|
<DT id="4"><A HREF="#lbAE">Step 2: walk along the path</A><DD>
|
|
<DT id="5"><A HREF="#lbAF">Step 3: find the final entry</A><DD>
|
|
<DT id="6"><A HREF="#lbAG">. and ..</A><DD>
|
|
<DT id="7"><A HREF="#lbAH">Mount points</A><DD>
|
|
<DT id="8"><A HREF="#lbAI">Trailing slashes</A><DD>
|
|
<DT id="9"><A HREF="#lbAJ">Final symlink</A><DD>
|
|
<DT id="10"><A HREF="#lbAK">Length limit</A><DD>
|
|
<DT id="11"><A HREF="#lbAL">Empty pathname</A><DD>
|
|
<DT id="12"><A HREF="#lbAM">Permissions</A><DD>
|
|
<DT id="13"><A HREF="#lbAN">Bypassing permission checks: superuser and capabilities</A><DD>
|
|
</DL>
|
|
<DT id="14"><A HREF="#lbAO">SEE ALSO</A><DD>
|
|
<DT id="15"><A HREF="#lbAP">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:06:09 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|