Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2817302ybl; Sun, 2 Feb 2020 07:22:49 -0800 (PST) X-Google-Smtp-Source: APXvYqyZsBEnMXGLeV1PG0n3qZpbT7pUWS6u8Oqz3JU/jujcmZHrbiHWew8TeyOuu7F35RvU+D0p X-Received: by 2002:a05:6808:50:: with SMTP id v16mr11695282oic.133.1580656969259; Sun, 02 Feb 2020 07:22:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580656969; cv=none; d=google.com; s=arc-20160816; b=jn8Kx2DM3kX/JxeqGMFdqpw2SaqQv5yvjDsAVkdallaoFp5+mq30WY63QvbC7WxBnm me4xgrLGlW9sgFFzFIIAWG3zao4XwNG6slubKlA0Esdi+sOEZKEpNwAhwWHYvGiB/2m5 K76l4nR9dkoZER+ypHNcuJUTWBvH24bS2t0h8KM+OFfIsSkgOAHA/nlwBMFAjbEujWoZ vdmF9QGfMQx89qWLsogW9MvFCB25dAr3Jz9eCawtKGwfOZmk/lnZZ5Fk8QYZybb8yJQJ DU/g6SM2m2ydQKNNxhSDheU7Zp1MfdzogcwfItQwuzcoZJDZkGT5n+U8Y2cfpQucyszH PsjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=01NH6NvxgBSP43PAaHuIFNJZ7DpISONAMjUVnND5fD8=; b=BqTTD3PKvmWReN5GkWnlcT547kyIs+06Ygb5X2bq5Mlq5/UuL72/3zJUDHKj61OA7H /rNSUxbzWL2TRDJQx8l7OeJUiL6ILTr95PHFOktXXl4kFwj0OG+4tLr6SQKV54S35Uy7 rjlYHFh9lRzl63dCSYlxYW9lwQBTJ0rYYCv8fm+Iqfn+a49Z69BQjz6vzvpsV8bEaTtF EMT312lbquiVIqsMhrYuE0+nHZVjSDsG+BDhh/LdrkVD9XnmacEhMrN57EdHjQgDy0Le mrmCRnFp1jlt6ITL80cvoJFj5IaXKuC50ggvsFgN2wQ0J9gEa9bORhV/lveUG4vVTCqg cGUw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s7si7891933otd.280.2020.02.02.07.22.37; Sun, 02 Feb 2020 07:22:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726967AbgBBPTs (ORCPT + 99 others); Sun, 2 Feb 2020 10:19:48 -0500 Received: from mout-p-202.mailbox.org ([80.241.56.172]:52466 "EHLO mout-p-202.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726837AbgBBPTr (ORCPT ); Sun, 2 Feb 2020 10:19:47 -0500 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 489ZPr2Jw1zQl9q; Sun, 2 Feb 2020 16:19:44 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) (amavisd-new, port 10030) with ESMTP id B_sD2xxs5Q40; Sun, 2 Feb 2020 16:19:38 +0100 (CET) From: Aleksa Sarai To: Al Viro , Michael Kerrisk Cc: Aleksa Sarai , Christian Brauner , Aleksa Sarai , linux-man@vger.kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH man-pages v2 1/2] path_resolution.7: update to mention openat2(2) features Date: Mon, 3 Feb 2020 02:19:06 +1100 Message-Id: <20200202151907.23587-2-cyphar@cyphar.com> In-Reply-To: <20200202151907.23587-1-cyphar@cyphar.com> References: <20200202151907.23587-1-cyphar@cyphar.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Aleksa Sarai --- man7/path_resolution.7 | 56 ++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/man7/path_resolution.7 b/man7/path_resolution.7 index 07664ed8faec..b4a65cc53120 100644 --- a/man7/path_resolution.7 +++ b/man7/path_resolution.7 @@ -29,30 +29,38 @@ path_resolution \- how a pathname is resolved to a file Some UNIX/Linux system calls have as parameter one or more filenames. A filename (or pathname) is resolved as follows. .SS Step 1: start of the resolution process -If the pathname starts with the \(aq/\(aq 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 +If the pathname starts with the \(aq/\(aq 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 .BR chroot (2) -system call. +system call, or may temporarily use a different root directory by using +.BR openat2 (2) +with the +.B RESOLVE_IN_ROOT +flag set. +.PP A process may get an entirely private mount namespace in case it\(emor one of its ancestors\(emwas started by an invocation of the .BR clone (2) system call that had the .B CLONE_NEWNS -flag set.) +flag set. This handles the \(aq/\(aq part of the pathname. .PP -If the pathname does not start with the \(aq/\(aq 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 +If the pathname does not start with the \(aq/\(aq character, the starting +lookup directory of the resolution process is the current working directory of +the process \(em or in the case of +.BR openat (2)-style +system calls, the +.I dfd +argument (or the current working directory if +.B AT_FDCWD +is passed as the +.I dfd +argument). The current working directory is inherited from the parent, and can +be changed by use of the .BR chdir (2) system call.) .PP @@ -91,7 +99,7 @@ Upon error, that error is returned. If the result is not a directory, an .B ENOTDIR error is returned. -If the resolution of the symlink is successful and returns a directory, +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 @@ -124,6 +132,12 @@ 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. +.PP +The resolution of symbolic links during this stage can be blocked by using +.BR openat2 (2), +with the +.B RESOLVE_NO_SYMLINKS +flag set. .SS Step 3: find the final entry The lookup of the final component of the pathname goes just like that of all other components, as described in the previous step, @@ -145,7 +159,7 @@ The path resolution process will assume that these entries have their conventional meanings, regardless of whether they are actually present in the physical filesystem. .PP -One cannot walk down past the root: "/.." is the same as "/". +One cannot walk up past the root: "/.." is the same as "/". .SS Mount points After a "mount dev path" command, the pathname "path" refers to the root of the filesystem hierarchy on the device "dev", and no @@ -154,6 +168,12 @@ longer to whatever it referred to earlier. One can walk out of a mounted filesystem: "path/.." refers to the parent directory of "path", outside of the filesystem hierarchy on "dev". +.PP +Traversal of mount points can be blocked by using +.BR openat2 (2), +with the +.B RESOLVE_NO_XDEV +flag set (though note that this also restricts bind mount traversal). .SS Trailing slashes If a pathname ends in a \(aq/\(aq, that forces resolution of the preceding component as in Step 2: it has to exist and resolve to a directory. -- 2.25.0