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>
This commit is contained in:
parent
32b4560b04
commit
779302e678
1 changed files with 12 additions and 4 deletions
12
fs/xattr.c
12
fs/xattr.c
|
@ -427,6 +427,7 @@ getxattr(struct dentry *d, const char __user *name, void __user *value,
|
||||||
{
|
{
|
||||||
ssize_t error;
|
ssize_t error;
|
||||||
void *kvalue = NULL;
|
void *kvalue = NULL;
|
||||||
|
void *vvalue = NULL;
|
||||||
char kname[XATTR_NAME_MAX + 1];
|
char kname[XATTR_NAME_MAX + 1];
|
||||||
|
|
||||||
error = strncpy_from_user(kname, name, sizeof(kname));
|
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) {
|
||||||
if (size > XATTR_SIZE_MAX)
|
if (size > XATTR_SIZE_MAX)
|
||||||
size = XATTR_SIZE_MAX;
|
size = XATTR_SIZE_MAX;
|
||||||
kvalue = kzalloc(size, GFP_KERNEL);
|
kvalue = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
|
||||||
if (!kvalue)
|
if (!kvalue) {
|
||||||
|
vvalue = vmalloc(size);
|
||||||
|
if (!vvalue)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
kvalue = vvalue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
error = vfs_getxattr(d, kname, kvalue, size);
|
error = vfs_getxattr(d, kname, kvalue, size);
|
||||||
|
@ -452,6 +457,9 @@ getxattr(struct dentry *d, const char __user *name, void __user *value,
|
||||||
than XATTR_SIZE_MAX bytes. Not possible. */
|
than XATTR_SIZE_MAX bytes. Not possible. */
|
||||||
error = -E2BIG;
|
error = -E2BIG;
|
||||||
}
|
}
|
||||||
|
if (vvalue)
|
||||||
|
vfree(vvalue);
|
||||||
|
else
|
||||||
kfree(kvalue);
|
kfree(kvalue);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue