All of lore.kernel.org
 help / color / mirror / Atom feed
* [linux-next:master 1957/2389] drivers/md/dm-ima.c:184:6: warning: variable 'tfm' is used uninitialized whenever 'if' condition is true
@ 2021-07-22  2:04 ` kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2021-07-22  2:04 UTC (permalink / raw)
  To: Tushar Sugandhi
  Cc: clang-built-linux, kbuild-all, Linux Memory Management List,
	Mike Snitzer

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

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   b1347210b01daa977ea980268927aa99198ceccc
commit: c2608cebed20bb307056d202258cc96ae8a9631d [1957/2389] dm ima: measure data on table load
config: arm-randconfig-r016-20210721 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 9625ca5b602616b2f5584e8a49ba93c52c141e40)
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 arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=c2608cebed20bb307056d202258cc96ae8a9631d
        git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
        git fetch --no-tags linux-next master
        git checkout c2608cebed20bb307056d202258cc96ae8a9631d
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm 

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

All warnings (new ones prefixed by >>):

>> drivers/md/dm-ima.c:184:6: warning: variable 'tfm' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (dm_ima_alloc_and_copy_device_data(table->md, &device_data_buf, num_targets, noio))
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/md/dm-ima.c:325:20: note: uninitialized use occurs here
           crypto_free_shash(tfm);
                             ^~~
   drivers/md/dm-ima.c:184:2: note: remove the 'if' if its condition is always false
           if (dm_ima_alloc_and_copy_device_data(table->md, &device_data_buf, num_targets, noio))
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/md/dm-ima.c:179:6: warning: variable 'tfm' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (!target_data_buf)
               ^~~~~~~~~~~~~~~~
   drivers/md/dm-ima.c:325:20: note: uninitialized use occurs here
           crypto_free_shash(tfm);
                             ^~~
   drivers/md/dm-ima.c:179:2: note: remove the 'if' if its condition is always false
           if (!target_data_buf)
           ^~~~~~~~~~~~~~~~~~~~~
   drivers/md/dm-ima.c:175:6: warning: variable 'tfm' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (!target_metadata_buf)
               ^~~~~~~~~~~~~~~~~~~~
   drivers/md/dm-ima.c:325:20: note: uninitialized use occurs here
           crypto_free_shash(tfm);
                             ^~~
   drivers/md/dm-ima.c:175:2: note: remove the 'if' if its condition is always false
           if (!target_metadata_buf)
           ^~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/md/dm-ima.c:166:26: note: initialize the variable 'tfm' to silence this warning
           struct crypto_shash *tfm;
                                   ^
                                    = NULL
   3 warnings generated.


vim +184 drivers/md/dm-ima.c

   152	
   153	/*
   154	 * Build up the IMA data for each target, and finally measure.
   155	 */
   156	void dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_flags)
   157	{
   158		size_t device_data_buf_len, target_metadata_buf_len, target_data_buf_len, l = 0;
   159		char *target_metadata_buf = NULL, *target_data_buf = NULL, *digest_buf = NULL;
   160		char *ima_buf = NULL, *device_data_buf = NULL;
   161		int digest_size, last_target_measured = -1, r;
   162		status_type_t type = STATUSTYPE_IMA;
   163		size_t cur_total_buf_len = 0;
   164		unsigned int num_targets, i;
   165		SHASH_DESC_ON_STACK(shash, NULL);
   166		struct crypto_shash *tfm;
   167		u8 *digest = NULL;
   168		bool noio = false;
   169	
   170		ima_buf = dm_ima_alloc(DM_IMA_MEASUREMENT_BUF_LEN, GFP_KERNEL, noio);
   171		if (!ima_buf)
   172			return;
   173	
   174		target_metadata_buf = dm_ima_alloc(DM_IMA_TARGET_METADATA_BUF_LEN, GFP_KERNEL, noio);
   175		if (!target_metadata_buf)
   176			goto error;
   177	
   178		target_data_buf = dm_ima_alloc(DM_IMA_TARGET_DATA_BUF_LEN, GFP_KERNEL, noio);
   179		if (!target_data_buf)
   180			goto error;
   181	
   182		num_targets = dm_table_get_num_targets(table);
   183	
 > 184		if (dm_ima_alloc_and_copy_device_data(table->md, &device_data_buf, num_targets, noio))
   185			goto error;
   186	
   187		tfm = crypto_alloc_shash("sha256", 0, 0);
   188		if (IS_ERR(tfm))
   189			goto error;
   190	
   191		shash->tfm = tfm;
   192		digest_size = crypto_shash_digestsize(tfm);
   193		digest = dm_ima_alloc(digest_size, GFP_KERNEL, noio);
   194		if (!digest)
   195			goto error;
   196	
   197		r = crypto_shash_init(shash);
   198		if (r)
   199			return;
   200	
   201		device_data_buf_len = strlen(device_data_buf);
   202		memcpy(ima_buf + l, device_data_buf, device_data_buf_len);
   203		l += device_data_buf_len;
   204	
   205		for (i = 0; i < num_targets; i++) {
   206			struct dm_target *ti = dm_table_get_target(table, i);
   207	
   208			if (!ti)
   209				goto error;
   210	
   211			last_target_measured = 0;
   212	
   213			/*
   214			 * First retrieve the target metadata.
   215			 */
   216			scnprintf(target_metadata_buf, DM_IMA_TARGET_METADATA_BUF_LEN,
   217				  "target_index=%d,target_begin=%llu,target_len=%llu,",
   218				  i, ti->begin, ti->len);
   219			target_metadata_buf_len = strlen(target_metadata_buf);
   220	
   221			/*
   222			 * Then retrieve the actual target data.
   223			 */
   224			if (ti->type->status)
   225				ti->type->status(ti, type, status_flags, target_data_buf,
   226						 DM_IMA_TARGET_DATA_BUF_LEN);
   227			else
   228				target_data_buf[0] = '\0';
   229	
   230			target_data_buf_len = strlen(target_data_buf);
   231	
   232			/*
   233			 * Check if the total data can fit into the IMA buffer.
   234			 */
   235			cur_total_buf_len = l + target_metadata_buf_len + target_data_buf_len;
   236	
   237			/*
   238			 * IMA measurements for DM targets are best-effort.
   239			 * If the total data buffered so far, including the current target,
   240			 * is too large to fit into DM_IMA_MEASUREMENT_BUF_LEN, measure what
   241			 * we have in the current buffer, and continue measuring the remaining
   242			 * targets by prefixing the device metadata again.
   243			 */
   244			if (unlikely(cur_total_buf_len >= DM_IMA_MEASUREMENT_BUF_LEN)) {
   245				dm_ima_measure_data("table_load", ima_buf, l, noio);
   246				r = crypto_shash_update(shash, (const u8 *)ima_buf, l);
   247				if (r < 0)
   248					goto error;
   249	
   250				memset(ima_buf, 0, DM_IMA_MEASUREMENT_BUF_LEN);
   251				l = 0;
   252	
   253				/*
   254				 * Each new "table_load" entry in IMA log should have device data
   255				 * prefix, so that multiple records from the same table_load for
   256				 * a given device can be linked together.
   257				 */
   258				memcpy(ima_buf + l, device_data_buf, device_data_buf_len);
   259				l += device_data_buf_len;
   260	
   261				/*
   262				 * If this iteration of the for loop turns out to be the last target
   263				 * in the table, dm_ima_measure_data("table_load", ...) doesn't need
   264				 * to be called again, just the hash needs to be finalized.
   265				 * "last_target_measured" tracks this state.
   266				 */
   267				last_target_measured = 1;
   268			}
   269	
   270			/*
   271			 * Fill-in all the target metadata, so that multiple targets for the same
   272			 * device can be linked together.
   273			 */
   274			memcpy(ima_buf + l, target_metadata_buf, target_metadata_buf_len);
   275			l += target_metadata_buf_len;
   276	
   277			memcpy(ima_buf + l, target_data_buf, target_data_buf_len);
   278			l += target_data_buf_len;
   279		}
   280	
   281		if (!last_target_measured) {
   282			dm_ima_measure_data("table_load", ima_buf, l, noio);
   283	
   284			r = crypto_shash_update(shash, (const u8 *)ima_buf, l);
   285			if (r < 0)
   286				goto error;
   287		}
   288	
   289		/*
   290		 * Finalize the table hash, and store it in table->md->ima.inactive_table.hash,
   291		 * so that the table data can be verified against the future device state change
   292		 * events, e.g. resume, rename, remove, table-clear etc.
   293		 */
   294		r = crypto_shash_final(shash, digest);
   295		if (r < 0)
   296			goto error;
   297	
   298		digest_buf = dm_ima_alloc((digest_size*2)+1, GFP_KERNEL, noio);
   299		if (!digest_buf)
   300			goto error;
   301	
   302		for (i = 0; i < digest_size; i++)
   303			snprintf((digest_buf+(i*2)), 3, "%02x", digest[i]);
   304	
   305		if (table->md->ima.active_table.hash != table->md->ima.inactive_table.hash)
   306			kfree(table->md->ima.inactive_table.hash);
   307	
   308		table->md->ima.inactive_table.hash = digest_buf;
   309		table->md->ima.inactive_table.hash_len = strlen(digest_buf);
   310		table->md->ima.inactive_table.num_targets = num_targets;
   311	
   312		if (table->md->ima.active_table.device_metadata !=
   313		    table->md->ima.inactive_table.device_metadata)
   314			kfree(table->md->ima.inactive_table.device_metadata);
   315	
   316		table->md->ima.inactive_table.device_metadata = device_data_buf;
   317		table->md->ima.inactive_table.device_metadata_len = device_data_buf_len;
   318	
   319		goto exit;
   320	error:
   321		kfree(digest_buf);
   322		kfree(device_data_buf);
   323	exit:
   324		kfree(digest);
   325		crypto_free_shash(tfm);
   326		kfree(ima_buf);
   327		kfree(target_metadata_buf);
   328		kfree(target_data_buf);
   329	}
   330	

---
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: 31637 bytes --]

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

* [linux-next:master 1957/2389] drivers/md/dm-ima.c:184:6: warning: variable 'tfm' is used uninitialized whenever 'if' condition is true
@ 2021-07-22  2:04 ` kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2021-07-22  2:04 UTC (permalink / raw)
  To: kbuild-all

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

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   b1347210b01daa977ea980268927aa99198ceccc
commit: c2608cebed20bb307056d202258cc96ae8a9631d [1957/2389] dm ima: measure data on table load
config: arm-randconfig-r016-20210721 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 9625ca5b602616b2f5584e8a49ba93c52c141e40)
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 arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=c2608cebed20bb307056d202258cc96ae8a9631d
        git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
        git fetch --no-tags linux-next master
        git checkout c2608cebed20bb307056d202258cc96ae8a9631d
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm 

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

All warnings (new ones prefixed by >>):

>> drivers/md/dm-ima.c:184:6: warning: variable 'tfm' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (dm_ima_alloc_and_copy_device_data(table->md, &device_data_buf, num_targets, noio))
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/md/dm-ima.c:325:20: note: uninitialized use occurs here
           crypto_free_shash(tfm);
                             ^~~
   drivers/md/dm-ima.c:184:2: note: remove the 'if' if its condition is always false
           if (dm_ima_alloc_and_copy_device_data(table->md, &device_data_buf, num_targets, noio))
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/md/dm-ima.c:179:6: warning: variable 'tfm' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (!target_data_buf)
               ^~~~~~~~~~~~~~~~
   drivers/md/dm-ima.c:325:20: note: uninitialized use occurs here
           crypto_free_shash(tfm);
                             ^~~
   drivers/md/dm-ima.c:179:2: note: remove the 'if' if its condition is always false
           if (!target_data_buf)
           ^~~~~~~~~~~~~~~~~~~~~
   drivers/md/dm-ima.c:175:6: warning: variable 'tfm' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (!target_metadata_buf)
               ^~~~~~~~~~~~~~~~~~~~
   drivers/md/dm-ima.c:325:20: note: uninitialized use occurs here
           crypto_free_shash(tfm);
                             ^~~
   drivers/md/dm-ima.c:175:2: note: remove the 'if' if its condition is always false
           if (!target_metadata_buf)
           ^~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/md/dm-ima.c:166:26: note: initialize the variable 'tfm' to silence this warning
           struct crypto_shash *tfm;
                                   ^
                                    = NULL
   3 warnings generated.


vim +184 drivers/md/dm-ima.c

   152	
   153	/*
   154	 * Build up the IMA data for each target, and finally measure.
   155	 */
   156	void dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_flags)
   157	{
   158		size_t device_data_buf_len, target_metadata_buf_len, target_data_buf_len, l = 0;
   159		char *target_metadata_buf = NULL, *target_data_buf = NULL, *digest_buf = NULL;
   160		char *ima_buf = NULL, *device_data_buf = NULL;
   161		int digest_size, last_target_measured = -1, r;
   162		status_type_t type = STATUSTYPE_IMA;
   163		size_t cur_total_buf_len = 0;
   164		unsigned int num_targets, i;
   165		SHASH_DESC_ON_STACK(shash, NULL);
   166		struct crypto_shash *tfm;
   167		u8 *digest = NULL;
   168		bool noio = false;
   169	
   170		ima_buf = dm_ima_alloc(DM_IMA_MEASUREMENT_BUF_LEN, GFP_KERNEL, noio);
   171		if (!ima_buf)
   172			return;
   173	
   174		target_metadata_buf = dm_ima_alloc(DM_IMA_TARGET_METADATA_BUF_LEN, GFP_KERNEL, noio);
   175		if (!target_metadata_buf)
   176			goto error;
   177	
   178		target_data_buf = dm_ima_alloc(DM_IMA_TARGET_DATA_BUF_LEN, GFP_KERNEL, noio);
   179		if (!target_data_buf)
   180			goto error;
   181	
   182		num_targets = dm_table_get_num_targets(table);
   183	
 > 184		if (dm_ima_alloc_and_copy_device_data(table->md, &device_data_buf, num_targets, noio))
   185			goto error;
   186	
   187		tfm = crypto_alloc_shash("sha256", 0, 0);
   188		if (IS_ERR(tfm))
   189			goto error;
   190	
   191		shash->tfm = tfm;
   192		digest_size = crypto_shash_digestsize(tfm);
   193		digest = dm_ima_alloc(digest_size, GFP_KERNEL, noio);
   194		if (!digest)
   195			goto error;
   196	
   197		r = crypto_shash_init(shash);
   198		if (r)
   199			return;
   200	
   201		device_data_buf_len = strlen(device_data_buf);
   202		memcpy(ima_buf + l, device_data_buf, device_data_buf_len);
   203		l += device_data_buf_len;
   204	
   205		for (i = 0; i < num_targets; i++) {
   206			struct dm_target *ti = dm_table_get_target(table, i);
   207	
   208			if (!ti)
   209				goto error;
   210	
   211			last_target_measured = 0;
   212	
   213			/*
   214			 * First retrieve the target metadata.
   215			 */
   216			scnprintf(target_metadata_buf, DM_IMA_TARGET_METADATA_BUF_LEN,
   217				  "target_index=%d,target_begin=%llu,target_len=%llu,",
   218				  i, ti->begin, ti->len);
   219			target_metadata_buf_len = strlen(target_metadata_buf);
   220	
   221			/*
   222			 * Then retrieve the actual target data.
   223			 */
   224			if (ti->type->status)
   225				ti->type->status(ti, type, status_flags, target_data_buf,
   226						 DM_IMA_TARGET_DATA_BUF_LEN);
   227			else
   228				target_data_buf[0] = '\0';
   229	
   230			target_data_buf_len = strlen(target_data_buf);
   231	
   232			/*
   233			 * Check if the total data can fit into the IMA buffer.
   234			 */
   235			cur_total_buf_len = l + target_metadata_buf_len + target_data_buf_len;
   236	
   237			/*
   238			 * IMA measurements for DM targets are best-effort.
   239			 * If the total data buffered so far, including the current target,
   240			 * is too large to fit into DM_IMA_MEASUREMENT_BUF_LEN, measure what
   241			 * we have in the current buffer, and continue measuring the remaining
   242			 * targets by prefixing the device metadata again.
   243			 */
   244			if (unlikely(cur_total_buf_len >= DM_IMA_MEASUREMENT_BUF_LEN)) {
   245				dm_ima_measure_data("table_load", ima_buf, l, noio);
   246				r = crypto_shash_update(shash, (const u8 *)ima_buf, l);
   247				if (r < 0)
   248					goto error;
   249	
   250				memset(ima_buf, 0, DM_IMA_MEASUREMENT_BUF_LEN);
   251				l = 0;
   252	
   253				/*
   254				 * Each new "table_load" entry in IMA log should have device data
   255				 * prefix, so that multiple records from the same table_load for
   256				 * a given device can be linked together.
   257				 */
   258				memcpy(ima_buf + l, device_data_buf, device_data_buf_len);
   259				l += device_data_buf_len;
   260	
   261				/*
   262				 * If this iteration of the for loop turns out to be the last target
   263				 * in the table, dm_ima_measure_data("table_load", ...) doesn't need
   264				 * to be called again, just the hash needs to be finalized.
   265				 * "last_target_measured" tracks this state.
   266				 */
   267				last_target_measured = 1;
   268			}
   269	
   270			/*
   271			 * Fill-in all the target metadata, so that multiple targets for the same
   272			 * device can be linked together.
   273			 */
   274			memcpy(ima_buf + l, target_metadata_buf, target_metadata_buf_len);
   275			l += target_metadata_buf_len;
   276	
   277			memcpy(ima_buf + l, target_data_buf, target_data_buf_len);
   278			l += target_data_buf_len;
   279		}
   280	
   281		if (!last_target_measured) {
   282			dm_ima_measure_data("table_load", ima_buf, l, noio);
   283	
   284			r = crypto_shash_update(shash, (const u8 *)ima_buf, l);
   285			if (r < 0)
   286				goto error;
   287		}
   288	
   289		/*
   290		 * Finalize the table hash, and store it in table->md->ima.inactive_table.hash,
   291		 * so that the table data can be verified against the future device state change
   292		 * events, e.g. resume, rename, remove, table-clear etc.
   293		 */
   294		r = crypto_shash_final(shash, digest);
   295		if (r < 0)
   296			goto error;
   297	
   298		digest_buf = dm_ima_alloc((digest_size*2)+1, GFP_KERNEL, noio);
   299		if (!digest_buf)
   300			goto error;
   301	
   302		for (i = 0; i < digest_size; i++)
   303			snprintf((digest_buf+(i*2)), 3, "%02x", digest[i]);
   304	
   305		if (table->md->ima.active_table.hash != table->md->ima.inactive_table.hash)
   306			kfree(table->md->ima.inactive_table.hash);
   307	
   308		table->md->ima.inactive_table.hash = digest_buf;
   309		table->md->ima.inactive_table.hash_len = strlen(digest_buf);
   310		table->md->ima.inactive_table.num_targets = num_targets;
   311	
   312		if (table->md->ima.active_table.device_metadata !=
   313		    table->md->ima.inactive_table.device_metadata)
   314			kfree(table->md->ima.inactive_table.device_metadata);
   315	
   316		table->md->ima.inactive_table.device_metadata = device_data_buf;
   317		table->md->ima.inactive_table.device_metadata_len = device_data_buf_len;
   318	
   319		goto exit;
   320	error:
   321		kfree(digest_buf);
   322		kfree(device_data_buf);
   323	exit:
   324		kfree(digest);
   325		crypto_free_shash(tfm);
   326		kfree(ima_buf);
   327		kfree(target_metadata_buf);
   328		kfree(target_data_buf);
   329	}
   330	

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

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

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

end of thread, other threads:[~2021-07-22  3:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-22  2:04 [linux-next:master 1957/2389] drivers/md/dm-ima.c:184:6: warning: variable 'tfm' is used uninitialized whenever 'if' condition is true kernel test robot
2021-07-22  2:04 ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.