linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs: xattr: use vmemdup_user instead of kvmalloc and copy_from_user
@ 2021-12-14 12:19 Qing Wang
  2021-12-14 13:20 ` Christian Brauner
  2021-12-16 12:23 ` [fs] 7db4f49247: WARNING:at_mm/slub.c:#kfree kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Qing Wang @ 2021-12-14 12:19 UTC (permalink / raw)
  To: Alexander Viro, linux-fsdevel, linux-kernel; +Cc: Wang Qing

From: Wang Qing <wangqing@vivo.com>

fix memdup_user.cocci warning:
fs/xattr.c:563:11-19: WARNING opportunity for vmemdup_user

Signed-off-by: Wang Qing <wangqing@vivo.com>
---
 fs/xattr.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/fs/xattr.c b/fs/xattr.c
index 5c8c517..71c301d
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -560,11 +560,9 @@ 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;
+		kvalue = vmemdup_user(value, size);
+		if (IS_ERR(kvalue)) {
+			error = PTR_ERR(kvalue);
 			goto out;
 		}
 		if ((strcmp(kname, XATTR_NAME_POSIX_ACL_ACCESS) == 0) ||
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-12-16 12:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-14 12:19 [PATCH] fs: xattr: use vmemdup_user instead of kvmalloc and copy_from_user Qing Wang
2021-12-14 13:20 ` Christian Brauner
2021-12-16 12:23 ` [fs] 7db4f49247: WARNING:at_mm/slub.c:#kfree kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).