lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 26 Apr 2022 20:25:03 +0800
From:   kernel test robot <lkp@...el.com>
To:     Thomas Gleixner <tglx@...utronix.de>
Cc:     kbuild-all@...ts.01.org, linux-kernel@...r.kernel.org,
        Borislav Petkov <bp@...e.de>
Subject: arch/x86/kernel/fpu/xstate.c:1117:7: warning: Local variable 'mask'
 shadows outer variable [shadowVariable]

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   d615b5416f8a1afeb82d13b238f8152c572d59c0
commit: 522e92743b35351bda1b6a9136560f833a9c2490 x86/fpu: Deduplicate copy_uabi_from_user/kernel_to_xstate()
date:   10 months ago
compiler: gcc-11 (Debian 11.2.0-20) 11.2.0
reproduce (cppcheck warning):
        # apt-get install cppcheck
        git checkout 522e92743b35351bda1b6a9136560f833a9c2490
        cppcheck --quiet --enable=style,performance,portability --template=gcc FILE

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


cppcheck warnings: (new ones prefixed by >>)
>> arch/x86/kernel/fpu/xstate.c:1117:7: warning: Local variable 'mask' shadows outer variable [shadowVariable]
     u64 mask = ((u64)1 << i);
         ^
   arch/x86/kernel/fpu/xstate.c:1086:6: note: Shadowed declaration
    u64 mask;
        ^
   arch/x86/kernel/fpu/xstate.c:1117:7: note: Shadow variable
     u64 mask = ((u64)1 << i);
         ^

vim +/mask +1117 arch/x86/kernel/fpu/xstate.c

947f4947cf00ea Thomas Gleixner           2021-06-23  1079  
522e92743b3535 Thomas Gleixner           2021-06-23  1080  
522e92743b3535 Thomas Gleixner           2021-06-23  1081  static int copy_uabi_to_xstate(struct xregs_state *xsave, const void *kbuf,
522e92743b3535 Thomas Gleixner           2021-06-23  1082  			       const void __user *ubuf)
79fecc2b7506f2 Ingo Molnar               2017-09-23  1083  {
79fecc2b7506f2 Ingo Molnar               2017-09-23  1084  	unsigned int offset, size;
80d8ae86b36791 Eric Biggers              2017-09-24  1085  	struct xstate_header hdr;
522e92743b3535 Thomas Gleixner           2021-06-23  1086  	u64 mask;
522e92743b3535 Thomas Gleixner           2021-06-23  1087  	int i;
79fecc2b7506f2 Ingo Molnar               2017-09-23  1088  
79fecc2b7506f2 Ingo Molnar               2017-09-23  1089  	offset = offsetof(struct xregs_state, header);
522e92743b3535 Thomas Gleixner           2021-06-23  1090  	if (copy_from_buffer(&hdr, offset, sizeof(hdr), kbuf, ubuf))
522e92743b3535 Thomas Gleixner           2021-06-23  1091  		return -EFAULT;
79fecc2b7506f2 Ingo Molnar               2017-09-23  1092  
5274e6c172c472 Fenghua Yu                2020-05-12  1093  	if (validate_user_xstate_header(&hdr))
79fecc2b7506f2 Ingo Molnar               2017-09-23  1094  		return -EINVAL;
79fecc2b7506f2 Ingo Molnar               2017-09-23  1095  
522e92743b3535 Thomas Gleixner           2021-06-23  1096  	/* Validate MXCSR when any of the related features is in use */
522e92743b3535 Thomas Gleixner           2021-06-23  1097  	mask = XFEATURE_MASK_FP | XFEATURE_MASK_SSE | XFEATURE_MASK_YMM;
522e92743b3535 Thomas Gleixner           2021-06-23  1098  	if (hdr.xfeatures & mask) {
522e92743b3535 Thomas Gleixner           2021-06-23  1099  		u32 mxcsr[2];
522e92743b3535 Thomas Gleixner           2021-06-23  1100  
522e92743b3535 Thomas Gleixner           2021-06-23  1101  		offset = offsetof(struct fxregs_state, mxcsr);
522e92743b3535 Thomas Gleixner           2021-06-23  1102  		if (copy_from_buffer(mxcsr, offset, sizeof(mxcsr), kbuf, ubuf))
522e92743b3535 Thomas Gleixner           2021-06-23  1103  			return -EFAULT;
522e92743b3535 Thomas Gleixner           2021-06-23  1104  
522e92743b3535 Thomas Gleixner           2021-06-23  1105  		/* Reserved bits in MXCSR must be zero. */
522e92743b3535 Thomas Gleixner           2021-06-23  1106  		if (mxcsr[0] & ~mxcsr_feature_mask)
947f4947cf00ea Thomas Gleixner           2021-06-23  1107  			return -EINVAL;
947f4947cf00ea Thomas Gleixner           2021-06-23  1108  
522e92743b3535 Thomas Gleixner           2021-06-23  1109  		/* SSE and YMM require MXCSR even when FP is not in use. */
522e92743b3535 Thomas Gleixner           2021-06-23  1110  		if (!(hdr.xfeatures & XFEATURE_MASK_FP)) {
522e92743b3535 Thomas Gleixner           2021-06-23  1111  			xsave->i387.mxcsr = mxcsr[0];
522e92743b3535 Thomas Gleixner           2021-06-23  1112  			xsave->i387.mxcsr_mask = mxcsr[1];
522e92743b3535 Thomas Gleixner           2021-06-23  1113  		}
522e92743b3535 Thomas Gleixner           2021-06-23  1114  	}
522e92743b3535 Thomas Gleixner           2021-06-23  1115  
79fecc2b7506f2 Ingo Molnar               2017-09-23  1116  	for (i = 0; i < XFEATURE_MAX; i++) {
79fecc2b7506f2 Ingo Molnar               2017-09-23 @1117  		u64 mask = ((u64)1 << i);
79fecc2b7506f2 Ingo Molnar               2017-09-23  1118  
b89eda482d7849 Eric Biggers              2017-09-24  1119  		if (hdr.xfeatures & mask) {
07baeb04f37c95 Sebastian Andrzej Siewior 2019-04-03  1120  			void *dst = __raw_xsave_addr(xsave, i);
79fecc2b7506f2 Ingo Molnar               2017-09-23  1121  
79fecc2b7506f2 Ingo Molnar               2017-09-23  1122  			offset = xstate_offsets[i];
79fecc2b7506f2 Ingo Molnar               2017-09-23  1123  			size = xstate_sizes[i];
79fecc2b7506f2 Ingo Molnar               2017-09-23  1124  
522e92743b3535 Thomas Gleixner           2021-06-23  1125  			if (copy_from_buffer(dst, offset, size, kbuf, ubuf))
522e92743b3535 Thomas Gleixner           2021-06-23  1126  				return -EFAULT;
79fecc2b7506f2 Ingo Molnar               2017-09-23  1127  		}
79fecc2b7506f2 Ingo Molnar               2017-09-23  1128  	}
79fecc2b7506f2 Ingo Molnar               2017-09-23  1129  
79fecc2b7506f2 Ingo Molnar               2017-09-23  1130  	/*
79fecc2b7506f2 Ingo Molnar               2017-09-23  1131  	 * The state that came in from userspace was user-state only.
79fecc2b7506f2 Ingo Molnar               2017-09-23  1132  	 * Mask all the user states out of 'xfeatures':
79fecc2b7506f2 Ingo Molnar               2017-09-23  1133  	 */
8ab22804efefea Fenghua Yu                2020-05-12  1134  	xsave->header.xfeatures &= XFEATURE_MASK_SUPERVISOR_ALL;
79fecc2b7506f2 Ingo Molnar               2017-09-23  1135  
79fecc2b7506f2 Ingo Molnar               2017-09-23  1136  	/*
79fecc2b7506f2 Ingo Molnar               2017-09-23  1137  	 * Add back in the features that came in from userspace:
79fecc2b7506f2 Ingo Molnar               2017-09-23  1138  	 */
b89eda482d7849 Eric Biggers              2017-09-24  1139  	xsave->header.xfeatures |= hdr.xfeatures;
79fecc2b7506f2 Ingo Molnar               2017-09-23  1140  
79fecc2b7506f2 Ingo Molnar               2017-09-23  1141  	return 0;
79fecc2b7506f2 Ingo Molnar               2017-09-23  1142  }
79fecc2b7506f2 Ingo Molnar               2017-09-23  1143  

:::::: The code at line 1117 was first introduced by commit
:::::: 79fecc2b7506f29fb91becc65e8788e5ae7eba9f x86/fpu: Split copy_user_to_xstate() into copy_kernel_to_xstate() & copy_user_to_xstate()

:::::: TO: Ingo Molnar <mingo@...nel.org>
:::::: CC: Ingo Molnar <mingo@...nel.org>

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ