Skip to content

Commit f48cfdd

Browse files
committed
vfs: In d_path don't call d_dname on a mount point
Aditya Kali (adityakali@google.com) wrote: > Commit bf056bf: > "proc: Fix the namespace inode permission checks." converted > the namespace files into symlinks. The same commit changed > the way namespace bind mounts appear in /proc/mounts: > $ mount --bind /proc/self/ns/ipc /mnt/ipc > Originally: > $ cat /proc/mounts | grep ipc > proc /mnt/ipc proc rw,nosuid,nodev,noexec 0 0 > > After commit bf056bf: > $ cat /proc/mounts | grep ipc > proc ipc:[4026531839] proc rw,nosuid,nodev,noexec 0 0 > > This breaks userspace which expects the 2nd field in > /proc/mounts to be a valid path. The symlink /proc/<pid>/ns/{ipc,mnt,net,pid,user,uts} point to dentries allocated with d_alloc_pseudo that we can mount, and that have interesting names printed out with d_dname. When these files are bind mounted /proc/mounts is not currently displaying the mount point correctly because d_dname is called instead of just displaying the path where the file is mounted. Solve this by adding an explicit check to distinguish mounted pseudo inodes and unmounted pseudo inodes. Unmounted pseudo inodes always use mount of their filesstem as the mnt_root in their path making these two cases easy to distinguish. CC: stable@vger.kernel.org Acked-by: Serge Hallyn <serge.hallyn@canonical.com> Reported-by: Aditya Kali <adityakali@google.com> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent 0e4b074 commit f48cfdd

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎fs/dcache.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3061,8 +3061,13 @@ char *d_path(const struct path *path, char *buf, int buflen)
30613061
* thus don't need to be hashed. They also don't need a name until a
30623062
* user wants to identify the object in /proc/pid/fd/. The little hack
30633063
* below allows us to generate a name for these objects on demand:
3064+
*
3065+
* Some pseudo inodes are mountable. When they are mounted
3066+
* path->dentry == path->mnt->mnt_root. In that case don't call d_dname
3067+
* and instead have d_path return the mounted path.
30643068
*/
3065-
if (path->dentry->d_op && path->dentry->d_op->d_dname)
3069+
if (path->dentry->d_op && path->dentry->d_op->d_dname &&
3070+
(!IS_ROOT(path->dentry) || path->dentry != path->mnt->mnt_root))
30663071
return path->dentry->d_op->d_dname(path->dentry, buf, buflen);
30673072

30683073
rcu_read_lock();

0 commit comments

Comments
 (0)