From 592e50e271036068aad61144804d40d83b1bae66 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Mon, 31 Jan 2022 16:08:35 +0100 Subject: [PATCH] main: fix lookup if underlying file is a symlink fix lookup if the underlying file is a symlink, while it is a directory on the upper layer. Closes: https://github.com/containers/fuse-overlayfs/issues/337 Signed-off-by: Giuseppe Scrivano --- main.c | 21 +++++++++++++++++++-- tests/fedora-installs.sh | 14 +++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index e2bd46f..38aed0d 100644 --- a/main.c +++ b/main.c @@ -1485,6 +1485,9 @@ make_ovl_node (struct ovl_data *lo, const char *path, struct ovl_layer *layer, c int r; r = it->ds->file_exists (it, whiteout_path); + if (r < 0 && errno == EACCES) + break; + if (r < 0 && errno != ENOENT && errno != ENOTDIR && errno != ENAMETOOLONG) return NULL; @@ -1659,8 +1662,9 @@ load_dir (struct ovl_data *lo, struct ovl_node *n, struct ovl_layer *layer, char for (it = lo->layers; it && !stop_lookup; it = it->next) { - int ret; + struct stat st; DIR *dp = NULL; + int ret; if (n->last_layer == it) stop_lookup = true; @@ -1672,6 +1676,17 @@ load_dir (struct ovl_data *lo, struct ovl_node *n, struct ovl_layer *layer, char if (ret == 0) break; + ret = it->ds->statat (it, path, &st, AT_SYMLINK_NOFOLLOW, STATX_TYPE); + if (ret < 0) + { + if (errno == ENOENT || errno == ENOTDIR || errno == ENAMETOOLONG) + continue; + return NULL; + } + /* not a directory, stop lookup in lower layers. */ + if ((st.st_mode & S_IFMT) != S_IFDIR) + break; + dp = it->ds->opendir (it, path); if (dp == NULL) continue; @@ -1720,6 +1735,8 @@ load_dir (struct ovl_data *lo, struct ovl_node *n, struct ovl_layer *layer, char strconcat3 (node_path, PATH_MAX, n->path, "/", dent->d_name); ret = it->ds->file_exists (it, whiteout_path); + if (ret < 0 && errno == EACCES) + continue; if (ret < 0 && errno != ENOENT && errno != ENOTDIR && errno != ENAMETOOLONG) { it->ds->closedir (dp); @@ -2020,7 +2037,7 @@ do_lookup_file (struct ovl_data *lo, fuse_ino_t parent, const char *name) { int saved_errno = errno; - if (errno == ENOENT || errno == ENOTDIR) + if (errno == ENOENT || errno == ENOTDIR || errno == EACCES) { if (node) continue; diff --git a/tests/fedora-installs.sh b/tests/fedora-installs.sh index b215a80..c59d9b3 100755 --- a/tests/fedora-installs.sh +++ b/tests/fedora-installs.sh @@ -251,5 +251,17 @@ test \! -e upper/a/b mknod merged/dev-foo c 10 175 attr -l merged/dev-foo -umount merged +# https://github.com/containers/fuse-overlayfs/issues/337 +umount -l merged + +rm -rf lower upper workdir merged +mkdir lower upper workdir merged +mkdir upper/foo +ln -s not/existing lower/foo + +fuse-overlayfs -o lowerdir=lower,upperdir=upper,workdir=workdir merged + +stat merged/foo + +umount merged