Man page - path_resolution(7)

Packages contains this manual

Available languages:

en fr pl ja ro de

Manual

PATH_RESOLUTION

名 前
説 明
ス テ ッ プ 1: 解 決 過 程 を 開 始 す る
ス テ ッ プ 2: パ ス を 辿 る
ス テ ッ プ 3: 最 後 の エ ン ト リ ー を 見 つ け る
. と ..
マ ウ ン ト 位 置
末 尾 の ス ラ ッ シ ュ
最 後 が シ ン ボ リ ッ ク リ ン ク の と き
長 さ の 制 限
空 の パ ス 名
許 可
許 可 の 確 認 を ス キ ッ プ す る : ス ー パ ー ユ ー ザ ー と ケ ー パ ビ リ テ ィ
関 連 項 目
こ の 文 書 に つ い て

名 前

path_resolution - フ ァ イ ル の パ ス 名 の 解 決 方 法

説 明

い く つ か の UNIX/Linux シ ス テ ム コ ー ル は 、 1 つ 以 上 の フ ァ イ ル 名 を 引 数 と し て 持 つ 。 フ ァ イ ル 名 (ま た は パ ス 名 ) は 以 下 の よ う に し て 解 決 さ れ る 。

ス テ ッ プ 1: 解 決 過 程 を 開 始 す る

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 chroot (2) system call, or may temporarily use a different root directory by using openat2 (2) with the RESOLVE_IN_ROOT flag set.

A process may get an entirely private mount namespace in case it—or one of its ancestors—was started by an invocation of the clone (2) system call that had the CLONE_NEWNS flag set. This handles the '/' part of the pathname.

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 — or in the case of openat (2)-style system calls, the dfd argument (or the current working directory if AT_FDCWD is passed as the dfd argument). The current working directory is inherited from the parent, and can be changed by use of the chdir (2) system call.)

'/' 文 字 で 始 ま る パ ス 名 は 絶 対 パ ス 名 と 呼 ば れ 、 '/' 文 字 で 始 ま ら な い パ ス 名 は 相 対 パ ス 名 と 呼 ば れ る 。

ス テ ッ プ 2: パ ス を 辿 る

現 在 の 検 索 デ ィ レ ク ト リ を デ ィ レ ク ト リ 検 索 の 開 始 点 と す る 。 そ し て 、 パ ス 名 の 最 後 の 構 成 要 素 (component) で な い 各 構 成 要 素 に つ い て 、 現 在 の 検 索 デ ィ レ ク ト リ で 検 索 を 行 う 。 こ こ で 構 成 要 素 は '/' で 区 切 ら れ た 部 分 文 字 列 で あ る 。

プ ロ セ ス が 現 在 の 検 索 デ ィ レ ク ト リ の 検 索 許 可 を 持 た な い 場 合 、 EACCES エ ラ ー が 返 さ れ る ("Permission denied")。

構 成 要 素 が 見 つ か ら な い 場 合 、 ENOENT エ ラ ー が 返 さ れ る ("No such file or directory")。

構 成 要 素 は 見 つ か っ た が 、 デ ィ レ ク ト リ で も シ ン ボ リ ッ ク リ ン ク で も な い 場 合 、 ENOTDIR エ ラ ー が 返 さ れ る ("Not a directory")。

構 成 要 素 が 見 つ か っ て 、 か つ デ ィ レ ク ト リ で あ る 場 合 、 現 在 の 検 索 デ ィ レ ク ト リ を そ の デ ィ レ ク ト リ に 設 定 し 、 次 の 構 成 要 素 に 移 動 す る 。

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 ENOTDIR error is returned. If the resolution of the symbolic link 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 ELOOP error is returned when the maximum is exceeded ("Too many levels of symbolic links").

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.

The resolution of symbolic links during this stage can be blocked by using openat2 (2), with the RESOLVE_NO_SYMLINKS flag set.

ス テ ッ プ 3: 最 後 の エ ン ト リ ー を 見 つ け る

パ ス 名 の 最 後 の 構 成 要 素 の 検 索 は 、 前 の ス テ ッ プ で 説 明 し た 他 の 全 て の 構 成 要 素 と 同 じ よ う に 実 行 さ れ る が 、 2 つ の 違 い が あ る 。 (i) 最 後 の 構 成 要 素 は デ ィ レ ク ト リ で あ る 必 要 が な い (パ ス 解 決 過 程 に 関 す る 限 り は ど ち ら で も 構 わ な い — 特 定 の シ ス テ ム コ ー ル が 要 求 す る も の に よ っ て 、 デ ィ レ ク ト リ で な け れ ば な ら な い 場 合 も あ る し 、 デ ィ レ ク ト リ 以 外 で な け れ ば な ら な い 場 合 も あ る )。 (ii) 構 成 要 素 が 見 つ か ら な い 場 合 に エ ラ ー に す る 必 要 は な い — そ の 構 成 要 素 を 作 成 す る だ け で よ い 場 合 も あ る 。 最 後 の エ ン ト リ ー の 詳 細 な 扱 い は 、 特 定 の シ ス テ ム コ ー ル の man ペ ー ジ で 説 明 さ れ て い る 。

. と ..

慣 習 と し て 、 全 て の デ ィ レ ク ト リ は エ ン ト リ ー "." と ".." を 持 つ 。 こ れ ら は そ れ ぞ れ 、 そ の デ ィ レ ク ト リ 自 身 と そ の 親 デ ィ レ ク ト リ を 参 照 す る 。

パ ス 解 決 過 程 で は 、 こ れ ら の エ ン ト リ ー が 物 理 的 な フ ァ イ ル シ ス テ ム に 実 際 に 存 在 す る か 否 か に 関 わ ら ず 、 慣 習 的 な 意 味 を 持 つ と 仮 定 す る 。

ル ー ト よ り 上 に 辿 る こ と は で き な い : "/.." は "/" と 同 じ で あ る 。

マ ウ ン ト 位 置

"mount dev path" コ マ ン ド を 実 行 し た 後 、 パ ス 名 "path" は デ バ イ ス "dev" 上 の フ ァ イ ル シ ス テ ム 階 層 の ル ー ト デ ィ レ ク ト リ を 参 照 す る よ う に な り 、 以 前 の 位 置 を 参 照 し な い 。

マ ウ ン ト さ れ た フ ァ イ ル シ ス テ ム の 外 に 出 る こ と が で き る : "path/.." は "dev" 上 の フ ァ イ ル シ ス テ ム 階 層 の 外 で あ る "path" の 親 デ ィ レ ク ト リ を 参 照 す る 。

Traversal of mount points can be blocked by using openat2 (2), with the RESOLVE_NO_XDEV flag set (though note that this also restricts bind mount traversal).

末 尾 の ス ラ ッ シ ュ

パ ス 名 が '/' で 終 わ っ て い る 場 合 、 ス テ ッ プ 2 に お い て 、 そ の 前 に あ る 構 成 要 素 の 解 決 法 を 次 の よ う に 強 制 す る : そ の 構 成 要 素 が 存 在 し な け れ ば な ら ず 、 デ ィ レ ク ト リ と し て 解 決 さ れ る 。 存 在 し な い 場 合 は 、 末 尾 の '/' が 無 視 さ れ る 。 (ま た 同 様 に 、 末 尾 に '/' が あ る パ ス 名 は 、 '.' を 末 尾 に 加 え て 得 ら れ る パ ス 名 と 等 し い 。 )

最 後 が シ ン ボ リ ッ ク リ ン ク の と き

パ ス 名 の 最 後 の 構 成 要 素 が シ ン ボ リ ッ ク リ ン ク で あ る 場 合 、 参 照 さ れ る フ ァ イ ル を シ ン ボ リ ッ ク リ ン ク と す る か 、 そ の 内 容 に つ い て パ ス を 解 決 し た 結 果 と す る か は 、 シ ス テ ム コ ー ル に 依 存 す る 。 た と え ば 、 シ ス テ ム コ ー ル lstat (2) は シ ン ボ リ ッ ク リ ン ク に 作 用 す る 。 一 方 、 stat (2) は シ ン ボ リ ッ ク リ ン ク で 指 さ れ た フ ァ イ ル に 作 用 す る 。

長 さ の 制 限

パ ス 名 に は 最 大 長 が あ る 。 パ ス 名 (ま た は シ ン ボ リ ッ ク リ ン ク を 解 決 す る と き に 得 ら れ る 中 間 パ ス 名 ) が 長 す ぎ る 場 合 、 ENAMETOOLONG エ ラ ー が 返 さ れ る ("Filename too long")。

空 の パ ス 名

元 々 の UNIX で は 、 空 の パ ス 名 は 現 在 の デ ィ レ ク ト リ を 参 照 し て い た 。 最 近 、 POSIX で は 空 の パ ス 名 を 解 決 す る べ き で は な い と い う 決 定 が な さ れ た 。 こ の 場 合 、 Linux は ENOENT を 返 す 。

許 可

The permission bits of a file consist of three groups of three bits; see chmod (1) and stat (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 setgroups (2)). When neither holds, the third group is used.

3 ビ ッ ト が 使 わ れ る 場 合 、 最 初 の ビ ッ ト は 読 み 込 み 許 可 を 決 定 し 、 2 番 目 の ビ ッ ト は 書 き 込 み 許 可 を 決 定 す る 。 ま た 3 番 目 の ビ ッ ト は 、 通 常 の フ ァ イ ル の 場 合 は 実 行 許 可 を 表 し 、 デ ィ レ ク ト リ の 場 合 は 検 索 許 可 を 表 す 。

Linux は 、 許 可 の チ ェ ッ ク に お い て 、 実 効 ユ ー ザ ー ID で は な く fsuid を 使 う 。 通 常 は fsuid は 実 効 ユ ー ザ ー ID と 等 し い が 、 fsuid は シ ス テ ム コ ー ル setfsuid (2) で 変 更 す る こ と が で き る 。

(こ こ で "fsuid" は "file system user ID" を 表 し て い る 。 こ の 概 念 は 「 プ ロ セ ス が 同 じ 実 効 ユ ー ザ ー ID を 持 つ プ ロ セ ス に 同 時 に シ グ ナ ル を 送 る こ と が で き る 」 と い う ユ ー ザ ー 空 間 NFS サ ー バ を 実 装 す る 際 に 必 要 で あ っ た 。 こ れ は 今 で は 廃 れ て し ま っ た 。 setfsuid (2) を 使 う べ き で は な い 。

同 様 に 、 Linux で は 実 効 グ ル ー プ ID の 代 わ り に fsgid ("フ ァ イ ル シ ス テ ム グ ル ー プ ID") を 使 う 。 setfsgid (2) を 参 照 す る こ と 。

許 可 の 確 認 を ス キ ッ プ す る : ス ー パ ー ユ ー ザ ー と ケ ー パ ビ リ テ ィ

伝 統 的 な UNIX シ ス テ ム で は 、 ス ー パ ー ユ ー ザ ー ( root , ユ ー ザ ー ID 0) は 非 常 に 強 力 で あ り 、 フ ァ イ ル ア ク セ ス 時 の 許 可 に よ る 制 限 を 全 て ス キ ッ プ す る 。

Linux で は 、 ス ー パ ー ユ ー ザ ー 権 限 が 複 数 の ケ ー パ ビ リ テ ィ に 分 割 さ れ て い る ( capabilities (7) 参 照 )。 フ ァ イ ル の 許 可 の 確 認 に は 、 CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH の 2つ の ケ ー パ ビ リ テ ィ が 関 係 す る (プ ロ セ ス の fsuid が 0 の 場 合 、 そ の プ ロ セ ス は こ れ ら の ケ ー パ ビ リ テ ィ を 持 つ )。

CAP_DAC_OVERRIDE ケ ー パ ビ リ テ ィ は 全 て の 許 可 チ ェ ッ ク を 上 書 き す る 。 実 際 に は 、 対 象 と な る フ ァ イ ル の 3 つ の 実 行 許 可 ビ ッ ト の う ち の 少 な く と も 1 つ が 設 定 さ れ て い る 場 合 の み 、 実 行 を 許 可 す る 。

CAP_DAC_READ_SEARCH ケ ー パ ビ リ テ ィ は 、 デ ィ レ ク ト リ に 対 し て 読 み 込 み と 検 索 を 許 可 し 、 通 常 の フ ァ イ ル に 対 し て 読 み 込 み を 許 可 す る 。

関 連 項 目

readlink (2), capabilities (7), credentials (7), symlink (7)

こ の 文 書 に つ い て

こ の man ペ ー ジ は Linux man-pages プ ロ ジ ェ ク ト の リ リ ー ス 5.10 の 一 部 で あ る 。 プ ロ ジ ェ ク ト の 説 明 と バ グ 報 告 に 関 す る 情 報 は https://www.kernel.org/doc/man-pages/ に 書 か れ て い る 。