Skip to content

Commit 92f0d6c

Browse files
author
Miklos Szeredi
committed
ovl: fold ovl_getxattr() into ovl_get_redirect_xattr()
This is a partial revert (with some cleanups) of commit 993a0b2 ("ovl: Do not lose security.capability xattr over metadata file copy-up"), which introduced ovl_getxattr() in the first place. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent de7a52c commit 92f0d6c

1 file changed

Lines changed: 17 additions & 36 deletions

File tree

fs/overlayfs/util.c

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -882,49 +882,26 @@ bool ovl_is_metacopy_dentry(struct dentry *dentry)
882882
return (oe->numlower > 1);
883883
}
884884

885-
static ssize_t ovl_getxattr(struct dentry *dentry, char *name, char **value,
886-
size_t padding)
887-
{
888-
ssize_t res;
889-
char *buf = NULL;
890-
891-
res = vfs_getxattr(dentry, name, NULL, 0);
892-
if (res < 0) {
893-
if (res == -ENODATA || res == -EOPNOTSUPP)
894-
return -ENODATA;
895-
goto fail;
896-
}
897-
898-
if (res != 0) {
899-
buf = kzalloc(res + padding, GFP_KERNEL);
900-
if (!buf)
901-
return -ENOMEM;
902-
903-
res = vfs_getxattr(dentry, name, buf, res);
904-
if (res < 0)
905-
goto fail;
906-
}
907-
*value = buf;
908-
909-
return res;
910-
911-
fail:
912-
pr_warn_ratelimited("failed to get xattr %s: err=%zi)\n",
913-
name, res);
914-
kfree(buf);
915-
return res;
916-
}
917-
918885
char *ovl_get_redirect_xattr(struct dentry *dentry, int padding)
919886
{
920887
int res;
921888
char *s, *next, *buf = NULL;
922889

923-
res = ovl_getxattr(dentry, OVL_XATTR_REDIRECT, &buf, padding + 1);
924-
if (res == -ENODATA)
890+
res = vfs_getxattr(dentry, OVL_XATTR_REDIRECT, NULL, 0);
891+
if (res == -ENODATA || res == -EOPNOTSUPP)
925892
return NULL;
926893
if (res < 0)
927-
return ERR_PTR(res);
894+
goto fail;
895+
if (res == 0)
896+
goto invalid;
897+
898+
buf = kzalloc(res + padding + 1, GFP_KERNEL);
899+
if (!buf)
900+
return ERR_PTR(-ENOMEM);
901+
902+
res = vfs_getxattr(dentry, OVL_XATTR_REDIRECT, buf, res);
903+
if (res < 0)
904+
goto fail;
928905
if (res == 0)
929906
goto invalid;
930907

@@ -943,6 +920,10 @@ char *ovl_get_redirect_xattr(struct dentry *dentry, int padding)
943920
invalid:
944921
pr_warn_ratelimited("invalid redirect (%s)\n", buf);
945922
res = -EINVAL;
923+
goto err_free;
924+
fail:
925+
pr_warn_ratelimited("failed to get redirect (%i)\n", res);
926+
err_free:
946927
kfree(buf);
947928
return ERR_PTR(res);
948929
}

0 commit comments

Comments
 (0)