• Miklos Szeredi's avatar
    John Johansen pointed out, that getcwd(2) will give a garbled result if a · 8d51b62b
    Miklos Szeredi authored
    bind mount of a non-filesystem-root directory is detached:
    
       > mkdir /mnt/foo
       > mount --bind /etc /mnt/foo
       > cd /mnt/foo/skel
       > umount -l /mnt/foo
       > /bin/pwd
       etcskel
    
    If it was the root of the filesystem which was detached, it will give a
    saner looking result, but it still won't be a valid absolute path by which
    the CWD can be reached (assuming the process's root is not also on the
    detached mount).
    
    A similar issue happens if the CWD is outside the process's root or in a
    different namespace.  These problems are relevant to symlinks under
    /proc/<pid>/ and /proc/<pid>/fd/ as well.
    
    This patch addresses all these issues, by prefixing such unreachable paths
    with "(unreachable)".  This isn't perfect since the returned path may
    still be a valid _relative_ path, and applications may not check the
    result of getcwd() for starting with a '/' before using it.
    
    For this reason Andreas Gruenbacher thinks getcwd(2) should return ENOENT
    in these cases, but that breaks /bin/pwd and bash in the above cases.
    Reported-by: default avatarJohn Johansen <jjohansen@suse.de>
    Cc: Matthew Wilcox <matthew@wil.cx>
    Cc: Andreas Gruenbacher <agruen@suse.de>
    Signed-off-by: default avatarMiklos Szeredi <mszeredi@suse.cz>
    Cc: Al Viro <viro@zeniv.linux.org.uk>
    Cc: Christoph Hellwig <hch@lst.de>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    8d51b62b
dcache.c 59.4 KB