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: <c8073b8e-7b9e-0830-4177-87c12f16349c@intel.com>
Date:   Tue, 12 Jul 2022 11:10:20 +0800
From:   kernel test robot <yujie.liu@...el.com>
To:     Daniel Latypov <dlatypov@...gle.com>
CC:     <llvm@...ts.linux.dev>, <kbuild-all@...ts.01.org>,
        "Linux Kernel Mailing List" <linux-kernel@...r.kernel.org>,
        Shuah Khan <skhan@...uxfoundation.org>,
        Brendan Higgins <brendanhiggins@...gle.com>
Subject: lib/kunit/executor.c:80:10: warning: Potential leak of memory pointed
 to by 'copy' [clang-analyzer-unix.Malloc]

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   5a29232d870d9e63fe5ff30b081be6ea7cc2465d
commit: a02353f491622e49c7ddedc6a6dc4f1d6ed2150a kunit: bail out of test filtering logic quicker if OOM
date:   9 weeks ago
config: riscv-randconfig-c006-20220707 (https://download.01.org/0day-ci/archive/20220712/202207120840.9F6TBqZD-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 77a38f6839980bfac61babb40d83772c51427011)
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-riscv-linux-gnu
         # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a02353f491622e49c7ddedc6a6dc4f1d6ed2150a
         git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
         git fetch --no-tags linus master
         git checkout a02353f491622e49c7ddedc6a6dc4f1d6ed2150a
         # 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 where applicable
Reported-by: kernel test robot <yujie.liu@...el.com>


clang-analyzer warnings: (new ones prefixed by >>)

 >> lib/kunit/executor.c:80:10: warning: Potential leak of memory pointed to by 'copy' [clang-analyzer-unix.Malloc]
                    return ERR_PTR(-ENOMEM);
                           ^

vim +/copy +80 lib/kunit/executor.c

a127b154a8f231 Daniel Latypov 2021-09-14  55
a127b154a8f231 Daniel Latypov 2021-09-14  56  /* Create a copy of suite with only tests that match test_glob. */
a127b154a8f231 Daniel Latypov 2021-09-14  57  static struct kunit_suite *
a127b154a8f231 Daniel Latypov 2021-09-14  58  kunit_filter_tests(struct kunit_suite *const suite, const char *test_glob)
a127b154a8f231 Daniel Latypov 2021-09-14  59  {
a127b154a8f231 Daniel Latypov 2021-09-14  60  	int n = 0;
a127b154a8f231 Daniel Latypov 2021-09-14  61  	struct kunit_case *filtered, *test_case;
a127b154a8f231 Daniel Latypov 2021-09-14  62  	struct kunit_suite *copy;
a127b154a8f231 Daniel Latypov 2021-09-14  63
a127b154a8f231 Daniel Latypov 2021-09-14  64  	kunit_suite_for_each_test_case(suite, test_case) {
a127b154a8f231 Daniel Latypov 2021-09-14  65  		if (!test_glob || glob_match(test_glob, test_case->name))
a127b154a8f231 Daniel Latypov 2021-09-14  66  			++n;
a127b154a8f231 Daniel Latypov 2021-09-14  67  	}
a127b154a8f231 Daniel Latypov 2021-09-14  68
a127b154a8f231 Daniel Latypov 2021-09-14  69  	if (n == 0)
a127b154a8f231 Daniel Latypov 2021-09-14  70  		return NULL;
a127b154a8f231 Daniel Latypov 2021-09-14  71
a127b154a8f231 Daniel Latypov 2021-09-14  72  	/* Use memcpy to workaround copy->name being const. */
a127b154a8f231 Daniel Latypov 2021-09-14  73  	copy = kmalloc(sizeof(*copy), GFP_KERNEL);
a02353f491622e Daniel Latypov 2022-05-11  74  	if (!copy)
a02353f491622e Daniel Latypov 2022-05-11  75  		return ERR_PTR(-ENOMEM);
a127b154a8f231 Daniel Latypov 2021-09-14  76  	memcpy(copy, suite, sizeof(*copy));
a127b154a8f231 Daniel Latypov 2021-09-14  77
a127b154a8f231 Daniel Latypov 2021-09-14  78  	filtered = kcalloc(n + 1, sizeof(*filtered), GFP_KERNEL);
a02353f491622e Daniel Latypov 2022-05-11  79  	if (!filtered)
a02353f491622e Daniel Latypov 2022-05-11 @80  		return ERR_PTR(-ENOMEM);
a127b154a8f231 Daniel Latypov 2021-09-14  81
a127b154a8f231 Daniel Latypov 2021-09-14  82  	n = 0;
a127b154a8f231 Daniel Latypov 2021-09-14  83  	kunit_suite_for_each_test_case(suite, test_case) {
a127b154a8f231 Daniel Latypov 2021-09-14  84  		if (!test_glob || glob_match(test_glob, test_case->name))
a127b154a8f231 Daniel Latypov 2021-09-14  85  			filtered[n++] = *test_case;
a127b154a8f231 Daniel Latypov 2021-09-14  86  	}
a127b154a8f231 Daniel Latypov 2021-09-14  87
a127b154a8f231 Daniel Latypov 2021-09-14  88  	copy->test_cases = filtered;
a127b154a8f231 Daniel Latypov 2021-09-14  89  	return copy;
a127b154a8f231 Daniel Latypov 2021-09-14  90  }
5d31f71efcb6bc Daniel Latypov 2021-02-05  91

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ