Re: [PATCH v14 4/5] security: keys: trusted: use ASN.1 TPM2 key format for the blobs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi James,

I love your patch! Perhaps something to improve:

[auto build test WARNING on integrity/next-integrity]
[also build test WARNING on linus/master v5.10-rc5 next-20201127]
[cannot apply to security/next-testing dhowells-fs/fscache-next]
[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/0day-ci/linux/commits/James-Bottomley/TPM-2-0-trusted-key-rework/20201130-063029
base:   https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git next-integrity
config: x86_64-randconfig-m001-20201130 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

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

smatch warnings:
security/keys/trusted-keys/trusted_tpm2.c:331 tpm2_seal_trusted() warn: unsigned 'payload->blob_len' is never less than zero.

vim +331 security/keys/trusted-keys/trusted_tpm2.c

   217	
   218	/**
   219	 * tpm2_seal_trusted() - seal the payload of a trusted key
   220	 *
   221	 * @chip: TPM chip to use
   222	 * @payload: the key data in clear and encrypted form
   223	 * @options: authentication values and other options
   224	 *
   225	 * Return: < 0 on error and 0 on success.
   226	 */
   227	int tpm2_seal_trusted(struct tpm_chip *chip,
   228			      struct trusted_key_payload *payload,
   229			      struct trusted_key_options *options)
   230	{
   231		unsigned int blob_len;
   232		struct tpm_buf buf;
   233		u32 hash;
   234		int i;
   235		int rc;
   236	
   237		for (i = 0; i < ARRAY_SIZE(tpm2_hash_map); i++) {
   238			if (options->hash == tpm2_hash_map[i].crypto_id) {
   239				hash = tpm2_hash_map[i].tpm_id;
   240				break;
   241			}
   242		}
   243	
   244		if (i == ARRAY_SIZE(tpm2_hash_map))
   245			return -EINVAL;
   246	
   247		if (!options->keyhandle)
   248			return -EINVAL;
   249	
   250		rc = tpm_buf_init(&buf, TPM2_ST_SESSIONS, TPM2_CC_CREATE);
   251		if (rc)
   252			return rc;
   253	
   254		tpm_buf_append_u32(&buf, options->keyhandle);
   255		tpm2_buf_append_auth(&buf, TPM2_RS_PW,
   256				     NULL /* nonce */, 0,
   257				     0 /* session_attributes */,
   258				     options->keyauth /* hmac */,
   259				     TPM_DIGEST_SIZE);
   260	
   261		/* sensitive */
   262		tpm_buf_append_u16(&buf, 4 + options->blobauth_len + payload->key_len + 1);
   263	
   264		tpm_buf_append_u16(&buf, options->blobauth_len);
   265		if (options->blobauth_len)
   266			tpm_buf_append(&buf, options->blobauth, options->blobauth_len);
   267	
   268		tpm_buf_append_u16(&buf, payload->key_len + 1);
   269		tpm_buf_append(&buf, payload->key, payload->key_len);
   270		tpm_buf_append_u8(&buf, payload->migratable);
   271	
   272		/* public */
   273		tpm_buf_append_u16(&buf, 14 + options->policydigest_len);
   274		tpm_buf_append_u16(&buf, TPM_ALG_KEYEDHASH);
   275		tpm_buf_append_u16(&buf, hash);
   276	
   277		/* policy */
   278		if (options->policydigest_len) {
   279			tpm_buf_append_u32(&buf, 0);
   280			tpm_buf_append_u16(&buf, options->policydigest_len);
   281			tpm_buf_append(&buf, options->policydigest,
   282				       options->policydigest_len);
   283		} else {
   284			tpm_buf_append_u32(&buf, TPM2_OA_USER_WITH_AUTH);
   285			tpm_buf_append_u16(&buf, 0);
   286		}
   287	
   288		/* public parameters */
   289		tpm_buf_append_u16(&buf, TPM_ALG_NULL);
   290		tpm_buf_append_u16(&buf, 0);
   291	
   292		/* outside info */
   293		tpm_buf_append_u16(&buf, 0);
   294	
   295		/* creation PCR */
   296		tpm_buf_append_u32(&buf, 0);
   297	
   298		if (buf.flags & TPM_BUF_OVERFLOW) {
   299			rc = -E2BIG;
   300			goto out;
   301		}
   302	
   303		rc = tpm_send(chip, buf.data, tpm_buf_length(&buf));
   304		if (rc)
   305			goto out;
   306	
   307		blob_len = be32_to_cpup((__be32 *) &buf.data[TPM_HEADER_SIZE]);
   308		if (blob_len > MAX_BLOB_SIZE) {
   309			rc = -E2BIG;
   310			goto out;
   311		}
   312		if (tpm_buf_length(&buf) < TPM_HEADER_SIZE + 4 + blob_len) {
   313			rc = -EFAULT;
   314			goto out;
   315		}
   316	
   317		payload->blob_len =
   318			tpm2_key_encode(payload, options,
   319					&buf.data[TPM_HEADER_SIZE + 4],
   320					blob_len);
   321	
   322	out:
   323		tpm_buf_destroy(&buf);
   324	
   325		if (rc > 0) {
   326			if (tpm2_rc_value(rc) == TPM2_RC_HASH)
   327				rc = -EINVAL;
   328			else
   329				rc = -EPERM;
   330		}
 > 331		if (payload->blob_len < 0)
   332			return payload->blob_len;
   333	
   334		return rc;
   335	}
   336	

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

Attachment: .config.gz
Description: application/gzip


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux Kernel]     [Linux Kernel Hardening]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux