summaryrefslogtreecommitdiff
path: root/fs/xattr.c
diff options
context:
space:
mode:
authorSasha Levin <levinsasha928@gmail.com>2012-07-30 14:39:13 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2012-07-30 17:25:11 -0700
commit779302e67835fe9a6b74327e54969ba59cb3478a (patch)
tree1e808fa81616ddf170879652f86e3d755694af81 /fs/xattr.c
parent32b4560b04af6e4fee241ea6de6db780eaf354f2 (diff)
downloadlinux-3.10-779302e67835fe9a6b74327e54969ba59cb3478a.tar.gz
linux-3.10-779302e67835fe9a6b74327e54969ba59cb3478a.tar.bz2
linux-3.10-779302e67835fe9a6b74327e54969ba59cb3478a.zip
fs/xattr.c:getxattr(): improve handling of allocation failures
This allocation can be as large as 64k. - Add __GFP_NOWARN so the falied kmalloc() is silent - Fall back to vmalloc() if the kmalloc() failed Signed-off-by: Sasha Levin <levinsasha928@gmail.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/xattr.c')
-rw-r--r--fs/xattr.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/fs/xattr.c b/fs/xattr.c
index 1d7ac379045..4d45b7189e7 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -427,6 +427,7 @@ getxattr(struct dentry *d, const char __user *name, void __user *value,
{
ssize_t error;
void *kvalue = NULL;
+ void *vvalue = NULL;
char kname[XATTR_NAME_MAX + 1];
error = strncpy_from_user(kname, name, sizeof(kname));
@@ -438,9 +439,13 @@ getxattr(struct dentry *d, const char __user *name, void __user *value,
if (size) {
if (size > XATTR_SIZE_MAX)
size = XATTR_SIZE_MAX;
- kvalue = kzalloc(size, GFP_KERNEL);
- if (!kvalue)
- return -ENOMEM;
+ kvalue = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
+ if (!kvalue) {
+ vvalue = vmalloc(size);
+ if (!vvalue)
+ return -ENOMEM;
+ kvalue = vvalue;
+ }
}
error = vfs_getxattr(d, kname, kvalue, size);
@@ -452,7 +457,10 @@ getxattr(struct dentry *d, const char __user *name, void __user *value,
than XATTR_SIZE_MAX bytes. Not possible. */
error = -E2BIG;
}
- kfree(kvalue);
+ if (vvalue)
+ vfree(vvalue);
+ else
+ kfree(kvalue);
return error;
}