Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1 from vcaputo/overlayfs-xattr-minalloc
Browse files Browse the repository at this point in the history
overlayfs: use a minimal buffer in ovl_copy_xattr
  • Loading branch information
vcaputo committed Oct 21, 2015
2 parents d9d92e7 + 885f27c commit cfc0008
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions fs/overlayfs/copy_up.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

int ovl_copy_xattr(struct dentry *old, struct dentry *new)
{
ssize_t list_size, size;
char *buf, *name, *value;
ssize_t list_size, size, value_size = 0;
char *buf, *name, *value = NULL;
int error;

if (!old->d_inode->i_op->getxattr ||
Expand All @@ -41,23 +41,36 @@ int ovl_copy_xattr(struct dentry *old, struct dentry *new)
if (!buf)
return -ENOMEM;

error = -ENOMEM;
value = kmalloc(XATTR_SIZE_MAX, GFP_KERNEL);
if (!value)
goto out;

list_size = vfs_listxattr(old, buf, list_size);
if (list_size <= 0) {
error = list_size;
goto out_free_value;
goto out;
}

for (name = buf; name < (buf + list_size); name += strlen(name) + 1) {
size = vfs_getxattr(old, name, value, XATTR_SIZE_MAX);
retry:
size = vfs_getxattr(old, name, value, value_size);
if (size == -ERANGE) {
size = vfs_getxattr(old, name, NULL, 0);
}

if (size <= 0) {
error = size;
goto out_free_value;
}

if (size > value_size) {
void *new;
new = krealloc(value, size, GFP_KERNEL);
if (!new) {
error = -ENOMEM;
goto out_free_value;
}
value = new;
value_size = size;
goto retry;
}

error = security_inode_copy_up_xattr(old, new,
name, value, &size);
if (error < 0)
Expand Down

0 comments on commit cfc0008

Please sign in to comment.