From 6f2af48a03fb29ac6cb35cfee2c370f7ce8645ce Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Mon, 25 Jan 2021 19:00:08 +0100 Subject: [PATCH] main: check if whiteout device already exists on newer kernels unprivileged users can create whiteout devices. If the whiteout device creation failed with EEXIST, check whether the existing file is already a whiteout. Closes: https://github.com/containers/fuse-overlayfs/issues/271 Signed-off-by: Giuseppe Scrivano --- main.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main.c b/main.c index 3898e52..50afdf8 100644 --- a/main.c +++ b/main.c @@ -733,6 +733,21 @@ create_whiteout (struct ovl_data *lo, struct ovl_node *parent, const char *name, if (ret == 0) return 0; + if (errno == EEXIST) + { + int saved_errno = errno; + struct stat st; + + /* Check whether it is already a whiteout. */ + if (TEMP_FAILURE_RETRY (fstatat (get_upper_layer (lo)->fd, whiteout_path, &st, AT_SYMLINK_NOFOLLOW)) == 0 + && (st.st_mode & S_IFMT) == S_IFCHR + && major (st.st_rdev) == 0 + && minor (st.st_rdev) == 0) + return 0; + + errno = saved_errno; + } + if (errno != EPERM && errno != ENOTSUP) return -1;