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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <202207060806.4qoJVWlL-lkp@intel.com>
Date:   Wed, 6 Jul 2022 08:23:18 +0800
From:   kernel test robot <lkp@...el.com>
To:     Keith Busch <kbusch@...nel.org>
Cc:     llvm@...ts.linux.dev, kbuild-all@...ts.01.org,
        linux-kernel@...r.kernel.org
Subject: [kbusch:alignment-fixes 3/3] block/bio.c:1229:6: warning: variable
 'i' is used uninitialized whenever 'if' condition is true

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/kbusch/linux.git alignment-fixes
head:   9d1ebc4c688471ccd3bffa5e6b08a82a71431f7b
commit: 9d1ebc4c688471ccd3bffa5e6b08a82a71431f7b [3/3] block: fix leaking page ref on truncated direct io
config: x86_64-randconfig-a012 (https://download.01.org/0day-ci/archive/20220706/202207060806.4qoJVWlL-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 142aca7741d5b06207e87bf4880fbe308c8d6823)
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://git.kernel.org/pub/scm/linux/kernel/git/kbusch/linux.git/commit/?id=9d1ebc4c688471ccd3bffa5e6b08a82a71431f7b
        git remote add kbusch https://git.kernel.org/pub/scm/linux/kernel/git/kbusch/linux.git
        git fetch --no-tags kbusch alignment-fixes
        git checkout 9d1ebc4c688471ccd3bffa5e6b08a82a71431f7b
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

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

All warnings (new ones prefixed by >>):

>> block/bio.c:1229:6: warning: variable 'i' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (unlikely(size <= 0)) {
               ^~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:78:22: note: expanded from macro 'unlikely'
   # define unlikely(x)    __builtin_expect(!!(x), 0)
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~
   block/bio.c:1251:9: note: uninitialized use occurs here
           while (i < nr_pages)
                  ^
   block/bio.c:1229:2: note: remove the 'if' if its condition is always false
           if (unlikely(size <= 0)) {
           ^~~~~~~~~~~~~~~~~~~~~~~~~~
   block/bio.c:1202:17: note: initialize the variable 'i' to silence this warning
           unsigned len, i;
                          ^
                           = 0
   1 warning generated.


vim +1229 block/bio.c

  1184	
  1185	/**
  1186	 * __bio_iov_iter_get_pages - pin user or kernel pages and add them to a bio
  1187	 * @bio: bio to add pages to
  1188	 * @iter: iov iterator describing the region to be mapped
  1189	 *
  1190	 * Pins pages from *iter and appends them to @bio's bvec array. The
  1191	 * pages will have to be released using put_page() when done.
  1192	 * For multi-segment *iter, this function only adds pages from the
  1193	 * next non-empty segment of the iov iterator.
  1194	 */
  1195	static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
  1196	{
  1197		unsigned short nr_pages = bio->bi_max_vecs - bio->bi_vcnt;
  1198		unsigned short entries_left = bio->bi_max_vecs - bio->bi_vcnt;
  1199		struct bio_vec *bv = bio->bi_io_vec + bio->bi_vcnt;
  1200		struct page **pages = (struct page **)bv;
  1201		ssize_t size, left;
  1202		unsigned len, i;
  1203		size_t offset;
  1204		int ret = 0;
  1205	
  1206		/*
  1207		 * Move page array up in the allocated memory for the bio vecs as far as
  1208		 * possible so that we can start filling biovecs from the beginning
  1209		 * without overwriting the temporary page array.
  1210		 */
  1211		BUILD_BUG_ON(PAGE_PTRS_PER_BVEC < 2);
  1212		pages += entries_left * (PAGE_PTRS_PER_BVEC - 1);
  1213	
  1214		/*
  1215		 * Each segment in the iov is required to be a block size multiple.
  1216		 * However, we may not be able to get the entire segment if it spans
  1217		 * more pages than bi_max_vecs allows, so we have to ALIGN_DOWN the
  1218		 * result to ensure the bio's total size is correct. The remainder of
  1219		 * the iov data will be picked up in the next bio iteration.
  1220		 */
  1221		size = iov_iter_get_pages(iter, pages, UINT_MAX - bio->bi_iter.bi_size,
  1222					  nr_pages, &offset);
  1223		if (size > 0) {
  1224			nr_pages = DIV_ROUND_UP(offset + size, PAGE_SIZE);
  1225			size = ALIGN_DOWN(size, bdev_logical_block_size(bio->bi_bdev));
  1226		} else
  1227			nr_pages = 0;
  1228	
> 1229		if (unlikely(size <= 0)) {
  1230			ret = size ? size : -EFAULT;
  1231			goto out;
  1232		}
  1233	
  1234		for (left = size, i = 0; left > 0; left -= len, i++) {
  1235			struct page *page = pages[i];
  1236	
  1237			len = min_t(size_t, PAGE_SIZE - offset, left);
  1238			if (bio_op(bio) == REQ_OP_ZONE_APPEND) {
  1239				ret = bio_iov_add_zone_append_page(bio, page, len,
  1240						offset);
  1241				if (ret)
  1242					break;
  1243			} else
  1244				bio_iov_add_page(bio, page, len, offset);
  1245	
  1246			offset = 0;
  1247		}
  1248	
  1249		iov_iter_advance(iter, size - left);
  1250	out:
  1251		while (i < nr_pages)
  1252			put_page(pages[i++]);
  1253	
  1254		return ret;
  1255	}
  1256	

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ