[PATCH] xattr: switch to vmemdup_user()

From: Yang Li
Date: Tue Mar 02 2021 - 03:36:35 EST


Replace opencoded alloc and copy with vmemdup_user()

fixed the following coccicheck:
./fs/xattr.c:561:11-19: WARNING opportunity for vmemdup_user

Reported-by: Abaci Robot <abaci@xxxxxxxxxxxxxxxxx>
Signed-off-by: Yang Li <yang.lee@xxxxxxxxxxxxxxxxx>
---
fs/xattr.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/fs/xattr.c b/fs/xattr.c
index b3444e0..b947ad2 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -558,11 +558,10 @@ int __vfs_setxattr_noperm(struct user_namespace *mnt_userns,
if (size) {
if (size > XATTR_SIZE_MAX)
return -E2BIG;
- kvalue = kvmalloc(size, GFP_KERNEL);
- if (!kvalue)
- return -ENOMEM;
- if (copy_from_user(kvalue, value, size)) {
- error = -EFAULT;
+ kvalue = vmemdup_user(value, size);
+
+ if (IS_ERR(kvalue)) {
+ r = PTR_ERR(kvalue);
goto out;
}
if ((strcmp(kname, XATTR_NAME_POSIX_ACL_ACCESS) == 0) ||
--
1.8.3.1