Skip to content

Commit

Permalink
fs/xattr.c:setxattr(): improve handling of allocation failures
Browse files Browse the repository at this point in the history
This allocation can be as large as 64k.

 - Add __GFP_NOWARN so the a falied kmalloc() is silent

 - Fall back to vmalloc() if the kmalloc() failed

Cc: Dave Chinner <[email protected]>
Cc: Dave Jones <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Al Viro <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
akpm00 authored and torvalds committed Apr 5, 2012
1 parent 0d08d7b commit 44c8249
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions fs/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
{
int error;
void *kvalue = NULL;
void *vvalue = NULL; /* If non-NULL, we used vmalloc() */
char kname[XATTR_NAME_MAX + 1];

if (flags & ~(XATTR_CREATE|XATTR_REPLACE))
Expand All @@ -335,13 +336,25 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
if (size) {
if (size > XATTR_SIZE_MAX)
return -E2BIG;
kvalue = memdup_user(value, size);
if (IS_ERR(kvalue))
return PTR_ERR(kvalue);
kvalue = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
if (!kvalue) {
vvalue = vmalloc(size);
if (!vvalue)
return -ENOMEM;
kvalue = vvalue;
}
if (copy_from_user(kvalue, value, size)) {
error = -EFAULT;
goto out;
}
}

error = vfs_setxattr(d, kname, kvalue, size, flags);
kfree(kvalue);
out:
if (vvalue)
vfree(vvalue);
else
kfree(kvalue);
return error;
}

Expand Down

0 comments on commit 44c8249

Please sign in to comment.