[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20220307022456.2074945-1-lv.ruyi@zte.com.cn>
Date: Mon, 7 Mar 2022 02:24:56 +0000
From: cgel.zte@...il.com
To: viro@...iv.linux.org.uk
Cc: linux-kernel@...r.kernel.org, Lv Ruyi <lv.ruyi@....com.cn>,
Zeal Robot <zealci@....com.cn>
Subject: [PATCH] xattr: use vmemdup_user make code cleaner
From: Lv Ruyi (CGEL ZTE) <lv.ruyi@....com.cn>
fix coccinelle warning:
./fs/xattr.c +563 WARNING opportunity for vmemdup_user
Reported-by: Zeal Robot <zealci@....com.cn>
Signed-off-by: Lv Ruyi (CGEL ZTE) <lv.ruyi@....com.cn>
---
fs/xattr.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/fs/xattr.c b/fs/xattr.c
index 5c8c5175b385..77798f0c76ae 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -560,20 +560,15 @@ setxattr(struct user_namespace *mnt_userns, struct dentry *d,
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;
- goto out;
- }
+ kvalue = vmemdup_user(value, size);
+ if (IS_ERR(kvalue))
+ return PTR_ERR(kvalue);
if ((strcmp(kname, XATTR_NAME_POSIX_ACL_ACCESS) == 0) ||
(strcmp(kname, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
posix_acl_fix_xattr_from_user(mnt_userns, kvalue, size);
}
error = vfs_setxattr(mnt_userns, d, kname, kvalue, size, flags);
-out:
kvfree(kvalue);
return error;
--
2.25.1
Powered by blists - more mailing lists