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 <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2021-01-25 19:00:08 +01:00
parent 865b3b9dfb
commit 6f2af48a03
No known key found for this signature in database
GPG Key ID: E4730F97F60286ED

15
main.c
View File

@ -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;