Bug: getcwd: cannot access parent directories

From: Roel Van de Paar
Date: Fri Sep 21 2018 - 04:17:11 EST


[1.] One line summary of the problem:

"cd: error retrieving current directory: getcwd: cannot access parent
directories: No such file or directory" on move of directories to
another volume

[2.] Full description of the problem/report:

Example output (testcase below):

/tmp/1/2$ cd ..
cd: error retrieving current directory: getcwd: cannot access parent
directories: No such file or directory
/tmp/1/2/..$ cd ..
cd: error retrieving current directory: getcwd: cannot access parent
directories: No such file or directory
/tmp/1/2/../..$ cd ..
cd: error retrieving current directory: getcwd: cannot access parent
directories: No such file or directory
/tmp/1/2/../../..$ cd ..
cd: error retrieving current directory: getcwd: cannot access parent
directories: No such file or directory
/tmp/1/2/../../../..$ cd ..
cd: error retrieving current directory: getcwd: cannot access parent
directories: No such file or directory
/tmp/1/2/../../../../..$ cd ..
cd: error retrieving current directory: getcwd: cannot access parent
directories: No such file or directory
/tmp/1/2/../../../../../..$ cd ..
/tmp$

- The number of ".." required is not correct
- The number of ".." matches the number of subdirs (see below)

[4.] Kernel information

Tested on latest updates of:
* Ubuntu Xenial
* Ubuntu Bionic
* Centos 7

[7.] A small shell script or example program which triggers the
problem (if possible)

In session 1
cd /tmp
mkdir -p 1/2
cd 1/2

In session 2 (another terminal session)
cd /tmp
mkdir -p 3/4/5/6/7
mv 1 3/4/5/6/7
mv 3 /dev/shm # where /dev/shm is some other disk. /dev/shm
reproduction works too. If the disk is the same, the issue will not
show.

Back to session 1
cd .. # fail
cd .. # fail
cd .. # fail
cd .. # fail
cd .. # fail
cd .. # fail
cd .. # works, but to completely incorrect directory given the
many 'cd ..'```

The problem is made more clear here by using 3/4/5/6/7 but you can
also just use a single subdir to see it