[kbuild] Re: [PATCH 2/2] btrfs: Use btrfs_try_lock_balance in btrfs_ioctl_balance

2022-05-04 Thread kernel test robot
CC: kbuild-...@lists.01.org
BCC: l...@intel.com
In-Reply-To: <20220503083637.1051023-3-nbori...@suse.com>
References: <20220503083637.1051023-3-nbori...@suse.com>
TO: Nikolay Borisov 
TO: linux-bt...@vger.kernel.org
CC: Nikolay Borisov 

Hi Nikolay,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on kdave/for-next]
[also build test WARNING on next-20220503]
[cannot apply to v5.18-rc5]
[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/intel-lab-lkp/linux/commits/Nikolay-Borisov/Refactor-btrfs_ioctl_balance/20220503-163837
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
:: branch date: 22 hours ago
:: commit date: 22 hours ago
config: i386-randconfig-m021-20220502 
(https://download.01.org/0day-ci/archive/20220504/202205041423.nvvjihsj-...@intel.com/config)
compiler: gcc-11 (Debian 11.2.0-20) 11.2.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 
Reported-by: Dan Carpenter 

smatch warnings:
fs/btrfs/ioctl.c:4493 btrfs_ioctl_balance() error: double free of 'bargs'

vim +/bargs +4493 fs/btrfs/ioctl.c

d383145190e87f Nikolay Borisov  2022-05-03  4402  
9ba1f6e44ed7a1 Liu Bo   2012-05-11  4403  static long 
btrfs_ioctl_balance(struct file *file, void __user *arg)
c9e9f97bdfb64d Ilya Dryomov 2012-01-16  4404  {
496ad9aa8ef448 Al Viro  2013-01-23  4405struct btrfs_root *root 
= BTRFS_I(file_inode(file))->root;
c9e9f97bdfb64d Ilya Dryomov 2012-01-16  4406struct btrfs_fs_info 
*fs_info = root->fs_info;
c9e9f97bdfb64d Ilya Dryomov 2012-01-16  4407struct 
btrfs_ioctl_balance_args *bargs;
c9e9f97bdfb64d Ilya Dryomov 2012-01-16  4408struct 
btrfs_balance_control *bctl;
c696e46e6ec2b3 Nikolay Borisov  2022-05-03  4409bool need_unlock = 
true; /* for mut. excl. ops lock */
c9e9f97bdfb64d Ilya Dryomov 2012-01-16  4410int ret;
c9e9f97bdfb64d Ilya Dryomov 2012-01-16  4411  
c9e9f97bdfb64d Ilya Dryomov 2012-01-16  4412if 
(!capable(CAP_SYS_ADMIN))
c9e9f97bdfb64d Ilya Dryomov 2012-01-16  4413return -EPERM;
c9e9f97bdfb64d Ilya Dryomov 2012-01-16  4414  
e54bfa31044d60 Liu Bo   2012-06-29  4415ret = 
mnt_want_write_file(file);
9ba1f6e44ed7a1 Liu Bo   2012-05-11  4416if (ret)
9ba1f6e44ed7a1 Liu Bo   2012-05-11  4417return ret;
9ba1f6e44ed7a1 Liu Bo   2012-05-11  4418  
c746db1b6ed99f Nikolay Borisov  2022-03-30  4419bargs = 
memdup_user(arg, sizeof(*bargs));
c746db1b6ed99f Nikolay Borisov  2022-03-30  4420if (IS_ERR(bargs)) {
c746db1b6ed99f Nikolay Borisov  2022-03-30  4421ret = 
PTR_ERR(bargs);
c746db1b6ed99f Nikolay Borisov  2022-03-30  4422bargs = NULL;
c746db1b6ed99f Nikolay Borisov  2022-03-30  4423goto out;
c746db1b6ed99f Nikolay Borisov  2022-03-30  4424}
c746db1b6ed99f Nikolay Borisov  2022-03-30  4425  
c696e46e6ec2b3 Nikolay Borisov  2022-05-03  4426ret = 
btrfs_try_lock_balance(fs_info, _unlock);
c696e46e6ec2b3 Nikolay Borisov  2022-05-03  4427if (ret)
ed0fb78fb6aa29 Ilya Dryomov 2013-01-20  4428goto out;
ed0fb78fb6aa29 Ilya Dryomov 2013-01-20  4429  
c696e46e6ec2b3 Nikolay Borisov  2022-05-03  4430
lockdep_assert_held(_info->balance_mutex);
c696e46e6ec2b3 Nikolay Borisov  2022-05-03  4431  
de322263d3a6d4 Ilya Dryomov 2012-01-16  4432if (bargs->flags & 
BTRFS_BALANCE_RESUME) {
de322263d3a6d4 Ilya Dryomov 2012-01-16  4433if 
(!fs_info->balance_ctl) {
de322263d3a6d4 Ilya Dryomov 2012-01-16  4434ret = 
-ENOTCONN;
c746db1b6ed99f Nikolay Borisov  2022-03-30  4435goto 
out_unlock;
de322263d3a6d4 Ilya Dryomov 2012-01-16  4436}
de322263d3a6d4 Ilya Dryomov 2012-01-16  4437  
de322263d3a6d4 Ilya Dryomov 2012-01-16  4438bctl = 
fs_info->balance_ctl;
de322263d3a6d4 Ilya Dryomov 2012-01-16  4439
spin_lock(_info->balance_lock);
de322263d3a6d4 Ilya Dryomov 2012-01-16  4440bctl->flags |= 
BTRFS_BALANCE_RESUME;
de322263d3a6d4 Ilya Dryomov 2012-01-16  4441
spin_unlock(_info->balance_lock);
efc0e69c2feab8 Nikolay Borisov  2021-11-25  4442
btrfs_exclop_balance(fs_info, BTRFS_EXCLOP_BALANCE);
de322263d3a6d4 Ilya Dryomov 2012-01-16  4443  
de322263d3a6d4 Ilya Dryomov 2012-01-16  goto do_balance;
de322263d3a6d4 Ilya Dryomov 2012-01-16  4445}
c9e9f97bdfb64d Ilya Dryomov 2012-01-16  4446  
c746db1b6ed99f Nikolay Borisov  2022-03-30  4447if (bargs->flags & 

[kbuild] Re: [PATCH 2/2] btrfs: Use btrfs_try_lock_balance in btrfs_ioctl_balance

2022-05-03 Thread kernel test robot
CC: l...@lists.linux.dev
CC: kbuild-...@lists.01.org
BCC: l...@intel.com
In-Reply-To: <20220503083637.1051023-3-nbori...@suse.com>
References: <20220503083637.1051023-3-nbori...@suse.com>
TO: Nikolay Borisov 
TO: linux-bt...@vger.kernel.org
CC: Nikolay Borisov 

Hi Nikolay,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on kdave/for-next]
[also build test WARNING on next-20220503]
[cannot apply to v5.18-rc5]
[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/intel-lab-lkp/linux/commits/Nikolay-Borisov/Refactor-btrfs_ioctl_balance/20220503-163837
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
:: branch date: 15 hours ago
:: commit date: 15 hours ago
config: riscv-randconfig-c006-20220501 
(https://download.01.org/0day-ci/archive/20220504/202205040701.s7sa4dgy-...@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 
363b3a645a1e30011cc8da624f13dac5fd915628)
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
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# 
https://github.com/intel-lab-lkp/linux/commit/c696e46e6ec2b391d6e350b4323ef7e7bafa7bca
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review 
Nikolay-Borisov/Refactor-btrfs_ioctl_balance/20220503-163837
git checkout c696e46e6ec2b391d6e350b4323ef7e7bafa7bca
# save the config file
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=riscv 
clang-analyzer 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 


clang-analyzer warnings: (new ones prefixed by >>)
   #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,  \
^~~~
   include/linux/fortify-string.h:362:2: note: expanded from macro 
'__fortify_memcpy_chk'
   __underlying_##op(p, q, __fortify_size);\
   ^
   note: expanded from here
   include/linux/fortify-string.h:45:29: note: expanded from macro 
'__underlying_memcpy'
   #define __underlying_memcpy __builtin_memcpy
   ^~~~
   fs/btrfs/ioctl.c:4333:2: note: Call to function 'memcpy' is insecure as it 
does not provide security checks introduced in the C11 standard. Replace with 
analogous functions that support length arguments or provides boundary checks 
such as 'memcpy_s' in case of C11
   memcpy(>stat, >stat, sizeof(bargs->stat));
   ^
   include/linux/fortify-string.h:369:26: note: expanded from macro 'memcpy'
   #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,  \
^~~~
   include/linux/fortify-string.h:362:2: note: expanded from macro 
'__fortify_memcpy_chk'
   __underlying_##op(p, q, __fortify_size);\
   ^
   note: expanded from here
   include/linux/fortify-string.h:45:29: note: expanded from macro 
'__underlying_memcpy'
   #define __underlying_memcpy __builtin_memcpy
   ^~~~
   fs/btrfs/ioctl.c:4463:2: warning: Call to function 'memcpy' is insecure as 
it does not provide security checks introduced in the C11 standard. Replace 
with analogous functions that support length arguments or provides boundary 
checks such as 'memcpy_s' in case of C11 
[clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
   memcpy(>data, >data, sizeof(bctl->data));
   ^
   include/linux/fortify-string.h:369:26: note: expanded from macro 'memcpy'
   #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,  \
^~~~
   include/linux/fortify-string.h:362:2: note: expanded from macro 
'__fortify_memcpy_chk'
   __underlying_##op(p, q, __fortify_size);\
   ^
   note: expanded from here
   include/linux/fortify-string.h:45:29: note: expanded from macro 
'__underlying_memcpy'
   #define __underlying_memcpy __builtin_memcpy
   ^~~~
   fs/btrfs/ioctl.c:4463:2: note: Call to function 'memcpy' is insecure as it 
does not provide security checks introduced in the C11 standard. Replace with 
analogous functions that support length arguments or provides boundary checks 
such as 'memcpy_s' in case of C11
   memcpy(>data, >data, sizeof(bctl->data));