Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 1 Nov 2012 15:25:05 -0700
From:      Garrett Cooper <yanegomi@gmail.com>
To:        FreeBSD FS <freebsd-fs@freebsd.org>
Subject:   Inconsistent/potentially incorrect behavior with relative lookups via chdir(2) on UFS/ZFS
Message-ID:  <CAGH67wSa7y-Nz=Pm%2BpxL3TRyKvBdDq2s3paSCu3LB-AFwmO_2g@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
--e89a8f839f6fb10b5f04cd767d72
Content-Type: text/plain; charset=ISO-8859-1

Hi,
    Just doing some interop testing on UFS/ZFS to develop a baseline for
filesystem behavior, and I noticed some inconsistencies with the ENOENT
requirement in chdir(2) when dealing with relative ".." paths (dot-dot
lookups). In particular...
    1. I would have expected chdir('.') to have failed in UFS/ZFS with
ENOENT if '.' wasn't present, but it didn't.
    2. I would have expected chdir('..') to have failed in ZFS with ENOENT
if '..' wasn't present, but it didn't.
    Sidenote: python doesn't do any special handling with os.chdir, per
Modules/posixmodule.c (I checked).
    The full test I ran is included below.
Thoughts?
Thanks,
-Garrett

# uname -a
FreeBSD forza.west.isilon.com 9.1-PRERELEASE FreeBSD 9.1-PRERELEASE #0
r240770: Thu Sep 20 19:28:45 PDT 2012
gcooper@forza.west.isilon.com:/usr/obj/usr/src/sys/FORZA
amd64

UFS:

# (set -x; rm -Rf *; for mc in '' 1; do export MUSICAL_CHAIRS=$mc; for d in
'' parent/child; do export BASEDIR=$d; python ~gcooper/pull_rug.py; env
CHROOT=1 python ~gcooper/pull_rug.py; done; done)
+ cd /tmp/foo/bar/baz/
+ rm -Rf child parent
+ for mc in ''\'''\''' 1
+ export MUSICAL_CHAIRS=
+ MUSICAL_CHAIRS=
+ for d in ''\'''\''' parent/child
+ export BASEDIR=
+ BASEDIR=
+ python /home/gcooper/pull_rug.py
did not fail with chdir(.)
cwd after is indeterminate
+ env CHROOT=1 python /home/gcooper/pull_rug.py
did not fail with chdir(.)
cwd after is indeterminate
+ for d in ''\'''\''' parent/child
+ export BASEDIR=parent/child
+ BASEDIR=parent/child
+ python /home/gcooper/pull_rug.py
did not fail with chdir(.)
cwd after is indeterminate
+ env CHROOT=1 python /home/gcooper/pull_rug.py
did not fail with chdir(.)
cwd after is indeterminate
+ for mc in ''\'''\''' 1
+ export MUSICAL_CHAIRS=1
+ MUSICAL_CHAIRS=1
+ for d in ''\'''\''' parent/child
+ export BASEDIR=
+ BASEDIR=
+ python /home/gcooper/pull_rug.py
[parent,before] inode is: 9985
[parent,after] inode is: 9988
[child] inode from fstat is: 9985
[child] inode from stat is: 9988
did not fail with chdir(.)
cwd after is indeterminate
+ env CHROOT=1 python /home/gcooper/pull_rug.py
[parent,before] inode is: 9989
[parent,after] inode is: 9985
[child] inode from fstat is: 4
did not fail with chdir(.)
cwd after is indeterminate
+ for d in ''\'''\''' parent/child
+ export BASEDIR=parent/child
+ BASEDIR=parent/child
+ python /home/gcooper/pull_rug.py
[parent,before] inode is: 5
[parent,after] inode is: 8
[child] inode from fstat is: 5
[child] inode from stat is: 8
did not fail with chdir(.)
cwd after is indeterminate
+ env CHROOT=1 python /home/gcooper/pull_rug.py
[parent,before] inode is: 10
[parent,after] inode is: 6
[child] inode from fstat is: 4
did not fail with chdir(.)
cwd after is indeterminate

ZFS:

# (set -x; rm -Rf *; for mc in '' 1; do export MUSICAL_CHAIRS=$mc; for d in
'' parent/child; do export BASEDIR=$d; python ~gcooper/pull_rug.py; env
CHROOT=1 python ~gcooper/pull_rug.py; done; done)
+ cd /root/foo/bar/baz/
+ rm -Rf child parent
+ for mc in ''\'''\''' 1
+ export MUSICAL_CHAIRS=
+ MUSICAL_CHAIRS=
+ for d in ''\'''\''' parent/child
+ export BASEDIR=
+ BASEDIR=
+ python /home/gcooper/pull_rug.py
did not fail with chdir(.)
did not fail with chdir(../..)
cwd after is /root/foo/bar
+ env CHROOT=1 python /home/gcooper/pull_rug.py
did not fail with chdir(.)
did not fail with chdir(../..)
cwd after is /
+ for d in ''\'''\''' parent/child
+ export BASEDIR=parent/child
+ BASEDIR=parent/child
+ python /home/gcooper/pull_rug.py
did not fail with chdir(.)
cwd after is indeterminate
+ env CHROOT=1 python /home/gcooper/pull_rug.py
did not fail with chdir(.)
cwd after is indeterminate
+ for mc in ''\'''\''' 1
+ export MUSICAL_CHAIRS=1
+ MUSICAL_CHAIRS=1
+ for d in ''\'''\''' parent/child
+ export BASEDIR=
+ BASEDIR=
+ python /home/gcooper/pull_rug.py
[parent,before] inode is: 3688787
[parent,after] inode is: 3688789
[child] inode from fstat is: 3688787
[child] inode from stat is: 3688789
did not fail with chdir(.)
did not fail with chdir(../..)
cwd after is /root/foo/bar
+ env CHROOT=1 python /home/gcooper/pull_rug.py
[parent,before] inode is: 3688790
[parent,after] inode is: 3688792
[child] inode from fstat is: 4
did not fail with chdir(.)
did not fail with chdir(../..)
cwd after is /
+ for d in ''\'''\''' parent/child
+ export BASEDIR=parent/child
+ BASEDIR=parent/child
+ python /home/gcooper/pull_rug.py
[parent,before] inode is: 3688794
[parent,after] inode is: 3688797
[child] inode from fstat is: 3688794
[child] inode from stat is: 3688797
did not fail with chdir(.)
cwd after is indeterminate
+ env CHROOT=1 python /home/gcooper/pull_rug.py
[parent,before] inode is: 3688799
[parent,after] inode is: 3688802
[child] inode from fstat is: 4
did not fail with chdir(.)
cwd after is indeterminate

--e89a8f839f6fb10b5f04cd767d72
Content-Type: application/octet-stream; name="pull_rug.py"
Content-Disposition: attachment; filename="pull_rug.py"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_h90fv7kp0

IyEvdXNyL2Jpbi9lbnYgcHl0aG9uCgppbXBvcnQgZXJybm8KaW1wb3J0IG9zCmltcG9ydCBzaHV0
aWwKaW1wb3J0IHNpZ25hbAppbXBvcnQgc3lzCmltcG9ydCB0cmFjZWJhY2sKaW1wb3J0IHRpbWUK
CkNIUk9PVCA9IG9zLmdldGVudignQ0hST09UJykKCmJhc2VkaXIgPSBvcy5lbnZpcm9uLmdldCgn
QkFTRURJUicpIG9yICdjaGl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2RpZCBu
b3QgZmFpbCB3aXRoIGNoZGlyKC4uLy4uKScKICAgIGV4Y2VwdCBPU0Vycm9yIGFzIG9zZToKICAg
ICAgICBpZiBvc2UuZXJybm8gIT0gZXJybm8uRU5PRU5UOgogICAgICAgICAgICByYWlzZQogICAg
dHJ5OgogICAgICAgIHByaW50ICdjd2QgYWZ0ZXIgaXMnLCBvcy5nZXRjd2QoKQogICAgZXhjZXB0
IE9TRXJyb3IgYXMgb3NlOgogICAgICAgIHByaW50ICdpbmRldGVybWluYXRlJwogICAgc2lnbmFs
LmFsYXJtKDApCiAgICBvcy5fZXhpdCgwKQoKc3lzLmV4aXQob3Mud2FpdHBpZChjaGlsZF9waWQs
IDApWzFdKQo=
--e89a8f839f6fb10b5f04cd767d72--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGH67wSa7y-Nz=Pm%2BpxL3TRyKvBdDq2s3paSCu3LB-AFwmO_2g>