diff mbox series

xattr: switch to vmemdup_user()

Message ID 1614666741-16796-1-git-send-email-yang.lee@linux.alibaba.com (mailing list archive)
State New
Headers show
Series xattr: switch to vmemdup_user() | expand

Commit Message

Yang Li March 2, 2021, 6:32 a.m. UTC
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@linux.alibaba.com>
Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
---
 fs/xattr.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Comments

Matthew Wilcox March 4, 2021, 12:17 p.m. UTC | #1
On Tue, Mar 02, 2021 at 02:32:21PM +0800, Yang Li wrote:
> 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@linux.alibaba.com>
> Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>

Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
diff mbox series

Patch

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) ||