Skip to content

Commit

Permalink
ovl: fix race in private xattr checks
Browse files Browse the repository at this point in the history
Xattr operations can race with copy up.  This does not matter as long as
we consistently fiter out "trunsted.overlay.opaque" attribute on upper
directories.

Previously we checked parent against OVL_PATH_MERGE.  This is too general,
and prone to race with copy-up.  I.e. we found the parent to be on the
lower layer but ovl_dentry_real() would return the copied-up dentry,
possibly with the "opaque" attribute.

So instead use ovl_path_real() and decide to filter the attributes based on
the actual type of the dentry we'll use.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
  • Loading branch information
Miklos Szeredi committed Nov 20, 2014
1 parent a105d68 commit 5214846
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions fs/overlayfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,26 +235,36 @@ int ovl_setxattr(struct dentry *dentry, const char *name,
return err;
}

static bool ovl_need_xattr_filter(struct dentry *dentry,
enum ovl_path_type type)
{
return type == OVL_PATH_UPPER && S_ISDIR(dentry->d_inode->i_mode);
}

ssize_t ovl_getxattr(struct dentry *dentry, const char *name,
void *value, size_t size)
{
if (ovl_path_type(dentry->d_parent) == OVL_PATH_MERGE &&
ovl_is_private_xattr(name))
struct path realpath;
enum ovl_path_type type = ovl_path_real(dentry, &realpath);

if (ovl_need_xattr_filter(dentry, type) && ovl_is_private_xattr(name))
return -ENODATA;

return vfs_getxattr(ovl_dentry_real(dentry), name, value, size);
return vfs_getxattr(realpath.dentry, name, value, size);
}

ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size)
{
struct path realpath;
enum ovl_path_type type = ovl_path_real(dentry, &realpath);
ssize_t res;
int off;

res = vfs_listxattr(ovl_dentry_real(dentry), list, size);
res = vfs_listxattr(realpath.dentry, list, size);
if (res <= 0 || size == 0)
return res;

if (ovl_path_type(dentry->d_parent) != OVL_PATH_MERGE)
if (!ovl_need_xattr_filter(dentry, type))
return res;

/* filter out private xattrs */
Expand All @@ -279,17 +289,16 @@ int ovl_removexattr(struct dentry *dentry, const char *name)
{
int err;
struct path realpath;
enum ovl_path_type type;
enum ovl_path_type type = ovl_path_real(dentry, &realpath);

err = ovl_want_write(dentry);
if (err)
goto out;

if (ovl_path_type(dentry->d_parent) == OVL_PATH_MERGE &&
ovl_is_private_xattr(name))
err = -ENODATA;
if (ovl_need_xattr_filter(dentry, type) && ovl_is_private_xattr(name))
goto out_drop_write;

type = ovl_path_real(dentry, &realpath);
if (type == OVL_PATH_LOWER) {
err = vfs_getxattr(realpath.dentry, name, NULL, 0);
if (err < 0)
Expand Down

0 comments on commit 5214846

Please sign in to comment.