LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] xattr: switch to vmemdup_user()
@ 2021-03-02  6:32 Yang Li
  2021-03-04 12:17 ` Matthew Wilcox
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yang Li @ 2021-03-02  6:32 UTC (permalink / raw)
  To: viro; +Cc: linux-fsdevel, linux-kernel, Yang Li

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

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


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

* Re: [PATCH] xattr: switch to vmemdup_user()
  2021-03-02  6:32 [PATCH] xattr: switch to vmemdup_user() Yang Li
@ 2021-03-04 12:17 ` Matthew Wilcox
  2021-09-29 21:20 ` kernel test robot
  2021-09-29 22:38 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: Matthew Wilcox @ 2021-03-04 12:17 UTC (permalink / raw)
  To: Yang Li; +Cc: viro, linux-fsdevel, linux-kernel

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>

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

* Re: [PATCH] xattr: switch to vmemdup_user()
  2021-03-02  6:32 [PATCH] xattr: switch to vmemdup_user() Yang Li
  2021-03-04 12:17 ` Matthew Wilcox
@ 2021-09-29 21:20 ` kernel test robot
  2021-09-29 22:38 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2021-09-29 21:20 UTC (permalink / raw)
  To: Yang Li, viro; +Cc: llvm, kbuild-all, linux-fsdevel, linux-kernel, Yang Li

[-- Attachment #1: Type: text/plain, Size: 3099 bytes --]

Hi Yang,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.15-rc3 next-20210922]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Yang-Li/xattr-switch-to-vmemdup_user/20210929-221309
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git a4e6f95a891ac08bd09d62e3e6dae239b150f4c1
config: hexagon-randconfig-r045-20210929 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project dc6e8dfdfe7efecfda318d43a06fae18b40eb498)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/c26396dd8ad04ac32a6dee98d97706c53432ee2f
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Yang-Li/xattr-switch-to-vmemdup_user/20210929-221309
        git checkout c26396dd8ad04ac32a6dee98d97706c53432ee2f
        # save the attached .config to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> fs/xattr.c:566:4: error: use of undeclared identifier 'r'
                           r = PTR_ERR(kvalue);
                           ^
   1 error generated.


vim +/r +566 fs/xattr.c

   538	
   539	/*
   540	 * Extended attribute SET operations
   541	 */
   542	static long
   543	setxattr(struct user_namespace *mnt_userns, struct dentry *d,
   544		 const char __user *name, const void __user *value, size_t size,
   545		 int flags)
   546	{
   547		int error;
   548		void *kvalue = NULL;
   549		char kname[XATTR_NAME_MAX + 1];
   550	
   551		if (flags & ~(XATTR_CREATE|XATTR_REPLACE))
   552			return -EINVAL;
   553	
   554		error = strncpy_from_user(kname, name, sizeof(kname));
   555		if (error == 0 || error == sizeof(kname))
   556			error = -ERANGE;
   557		if (error < 0)
   558			return error;
   559	
   560		if (size) {
   561			if (size > XATTR_SIZE_MAX)
   562				return -E2BIG;
   563			kvalue = vmemdup_user(value, size);
   564	
   565			if (IS_ERR(kvalue)) {
 > 566				r = PTR_ERR(kvalue);
   567				goto out;
   568			}
   569			if ((strcmp(kname, XATTR_NAME_POSIX_ACL_ACCESS) == 0) ||
   570			    (strcmp(kname, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
   571				posix_acl_fix_xattr_from_user(mnt_userns, kvalue, size);
   572		}
   573	
   574		error = vfs_setxattr(mnt_userns, d, kname, kvalue, size, flags);
   575	out:
   576		kvfree(kvalue);
   577	
   578		return error;
   579	}
   580	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 31763 bytes --]

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

* Re: [PATCH] xattr: switch to vmemdup_user()
  2021-03-02  6:32 [PATCH] xattr: switch to vmemdup_user() Yang Li
  2021-03-04 12:17 ` Matthew Wilcox
  2021-09-29 21:20 ` kernel test robot
@ 2021-09-29 22:38 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2021-09-29 22:38 UTC (permalink / raw)
  To: Yang Li, viro; +Cc: kbuild-all, linux-fsdevel, linux-kernel, Yang Li

[-- Attachment #1: Type: text/plain, Size: 2942 bytes --]

Hi Yang,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.15-rc3 next-20210922]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Yang-Li/xattr-switch-to-vmemdup_user/20210929-221309
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git a4e6f95a891ac08bd09d62e3e6dae239b150f4c1
config: x86_64-randconfig-c001-20210929 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/c26396dd8ad04ac32a6dee98d97706c53432ee2f
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Yang-Li/xattr-switch-to-vmemdup_user/20210929-221309
        git checkout c26396dd8ad04ac32a6dee98d97706c53432ee2f
        # save the attached .config to linux build tree
        mkdir build_dir
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   fs/xattr.c: In function 'setxattr':
>> fs/xattr.c:566:4: error: 'r' undeclared (first use in this function)
     566 |    r = PTR_ERR(kvalue);
         |    ^
   fs/xattr.c:566:4: note: each undeclared identifier is reported only once for each function it appears in


vim +/r +566 fs/xattr.c

   538	
   539	/*
   540	 * Extended attribute SET operations
   541	 */
   542	static long
   543	setxattr(struct user_namespace *mnt_userns, struct dentry *d,
   544		 const char __user *name, const void __user *value, size_t size,
   545		 int flags)
   546	{
   547		int error;
   548		void *kvalue = NULL;
   549		char kname[XATTR_NAME_MAX + 1];
   550	
   551		if (flags & ~(XATTR_CREATE|XATTR_REPLACE))
   552			return -EINVAL;
   553	
   554		error = strncpy_from_user(kname, name, sizeof(kname));
   555		if (error == 0 || error == sizeof(kname))
   556			error = -ERANGE;
   557		if (error < 0)
   558			return error;
   559	
   560		if (size) {
   561			if (size > XATTR_SIZE_MAX)
   562				return -E2BIG;
   563			kvalue = vmemdup_user(value, size);
   564	
   565			if (IS_ERR(kvalue)) {
 > 566				r = PTR_ERR(kvalue);
   567				goto out;
   568			}
   569			if ((strcmp(kname, XATTR_NAME_POSIX_ACL_ACCESS) == 0) ||
   570			    (strcmp(kname, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
   571				posix_acl_fix_xattr_from_user(mnt_userns, kvalue, size);
   572		}
   573	
   574		error = vfs_setxattr(mnt_userns, d, kname, kvalue, size, flags);
   575	out:
   576		kvfree(kvalue);
   577	
   578		return error;
   579	}
   580	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 32918 bytes --]

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

end of thread, other threads:[~2021-09-29 22:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-02  6:32 [PATCH] xattr: switch to vmemdup_user() Yang Li
2021-03-04 12:17 ` Matthew Wilcox
2021-09-29 21:20 ` kernel test robot
2021-09-29 22:38 ` 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).