diff options
author | Andrew Morton <akpm@linux-foundation.org> | 2012-04-05 14:25:07 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-04-05 15:25:50 -0700 |
commit | 44c824982fd37a578da23cc90885e9690a6a3f0e (patch) | |
tree | cc4180263258049e5b59fa019f6c686df2ff4caa | |
parent | 0d08d7b7e13b5060181b11ecdde82d8fda322123 (diff) | |
download | op-kernel-dev-44c824982fd37a578da23cc90885e9690a6a3f0e.zip op-kernel-dev-44c824982fd37a578da23cc90885e9690a6a3f0e.tar.gz |
fs/xattr.c:setxattr(): improve handling of allocation failures
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 <david@fromorbit.com>
Cc: Dave Jones <davej@codemonkey.org.uk>
Cc: David Rientjes <rientjes@google.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>
-rw-r--r-- | fs/xattr.c | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -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)) @@ -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; } |