public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v4 3/3] crypto: Add Mediatek EIP-93 crypto engine support
       [not found] <20241025094734.1614-3-ansuelsmth@gmail.com>
@ 2024-10-26 12:14 ` kernel test robot
  2024-10-28  8:47 ` Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2024-10-26 12:14 UTC (permalink / raw)
  To: Christian Marangi, Herbert Xu, David S. Miller, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Antoine Tenart, Peter Zijlstra,
	Ingo Molnar, Will Deacon, Waiman Long, Boqun Feng,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	linux-crypto, devicetree, linux-kernel, llvm, upstream
  Cc: oe-kbuild-all, netdev, Richard van Schagen

Hi Christian,

kernel test robot noticed the following build warnings:

[auto build test WARNING on herbert-cryptodev-2.6/master]
[also build test WARNING on herbert-crypto-2.6/master tip/locking/core linus/master v6.12-rc4 next-20241025]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/dt-bindings-crypto-Add-Inside-Secure-SafeXcel-EIP-93-crypto-engine/20241025-175032
base:   https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master
patch link:    https://lore.kernel.org/r/20241025094734.1614-3-ansuelsmth%40gmail.com
patch subject: [PATCH v4 3/3] crypto: Add Mediatek EIP-93 crypto engine support
config: powerpc64-randconfig-r123-20241026 (https://download.01.org/0day-ci/archive/20241026/202410261900.DyTk6FZW-lkp@intel.com/config)
compiler: powerpc64-linux-gcc (GCC) 14.1.0
reproduce: (https://download.01.org/0day-ci/archive/20241026/202410261900.DyTk6FZW-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410261900.DyTk6FZW-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> drivers/crypto/inside-secure/eip93/eip93-hash.c:423:37: sparse: sparse: cast to restricted __be32
>> drivers/crypto/inside-secure/eip93/eip93-hash.c:596:38: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned int [usertype] @@     got restricted __be32 [usertype] @@
   drivers/crypto/inside-secure/eip93/eip93-hash.c:596:38: sparse:     expected unsigned int [usertype]
   drivers/crypto/inside-secure/eip93/eip93-hash.c:596:38: sparse:     got restricted __be32 [usertype]
--
>> drivers/crypto/inside-secure/eip93/eip93-common.c:542:39: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned int @@     got restricted __be32 [usertype] @@
   drivers/crypto/inside-secure/eip93/eip93-common.c:542:39: sparse:     expected unsigned int
   drivers/crypto/inside-secure/eip93/eip93-common.c:542:39: sparse:     got restricted __be32 [usertype]
>> drivers/crypto/inside-secure/eip93/eip93-common.c:546:23: sparse: sparse: cast to restricted __be32
   drivers/crypto/inside-secure/eip93/eip93-common.c:668:43: sparse: sparse: cast to restricted __be32
>> drivers/crypto/inside-secure/eip93/eip93-common.c:811:38: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned int [usertype] @@     got restricted __be32 [usertype] @@
   drivers/crypto/inside-secure/eip93/eip93-common.c:811:38: sparse:     expected unsigned int [usertype]
   drivers/crypto/inside-secure/eip93/eip93-common.c:811:38: sparse:     got restricted __be32 [usertype]
   drivers/crypto/inside-secure/eip93/eip93-common.c:812:38: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned int [usertype] @@     got restricted __be32 [usertype] @@
   drivers/crypto/inside-secure/eip93/eip93-common.c:812:38: sparse:     expected unsigned int [usertype]
   drivers/crypto/inside-secure/eip93/eip93-common.c:812:38: sparse:     got restricted __be32 [usertype]
   drivers/crypto/inside-secure/eip93/eip93-common.c:101:5: sparse: sparse: context imbalance in 'eip93_put_descriptor' - wrong count at exit
   drivers/crypto/inside-secure/eip93/eip93-common.c:127:6: sparse: sparse: context imbalance in 'eip93_get_descriptor' - wrong count at exit

vim +423 drivers/crypto/inside-secure/eip93/eip93-hash.c

   396	
   397	void eip93_hash_handle_result(struct crypto_async_request *async, int err)
   398	{
   399		struct ahash_request *req = ahash_request_cast(async);
   400		struct eip93_hash_reqctx *rctx = ahash_request_ctx(req);
   401		struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
   402		struct eip93_hash_ctx *ctx = crypto_ahash_ctx(ahash);
   403		int digestsize = crypto_ahash_digestsize(ahash);
   404		struct sa_state *sa_state = rctx->sa_state;
   405		int i;
   406	
   407		/* Unmap and sync sa_state for host */
   408		dma_unmap_single(rctx->mtk->dev, rctx->sa_state_base,
   409				 sizeof(*sa_state), DMA_FROM_DEVICE);
   410	
   411		/*
   412		 * With no_finalize assume SHA256_DIGEST_SIZE buffer is passed.
   413		 * This is to handle SHA224 that have a 32 byte intermediate digest.
   414		 */
   415		if (rctx->no_finalize)
   416			digestsize = SHA256_DIGEST_SIZE;
   417	
   418		/* bytes needs to be swapped for req->result */
   419		if (!IS_HASH_MD5(ctx->flags)) {
   420			for (i = 0; i < digestsize / sizeof(u32); i++) {
   421				u32 *digest = (u32 *)sa_state->state_i_digest;
   422	
 > 423				digest[i] = be32_to_cpu(digest[i]);
   424			}
   425		}
   426	
   427		memcpy(req->result, sa_state->state_i_digest, digestsize);
   428	
   429		kfree(sa_state);
   430		eip93_hash_free_data_blocks(req);
   431		eip93_hash_free_sa_record(req);
   432	
   433		ahash_request_complete(req, err);
   434	}
   435	
   436	static int eip93_hash_final(struct ahash_request *req)
   437	{
   438		struct eip93_hash_reqctx *rctx = ahash_request_ctx(req);
   439		struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
   440		struct eip93_hash_ctx *ctx = crypto_ahash_ctx(ahash);
   441		struct crypto_async_request *async = &req->base;
   442		struct eip93_device *mtk = rctx->mtk;
   443		struct mkt_hash_block *block;
   444		int ret;
   445	
   446		/* EIP93 can't handle zero bytes hash */
   447		if (!rctx->len && !IS_HMAC(ctx->flags)) {
   448			switch ((ctx->flags & EIP93_HASH_MASK)) {
   449			case EIP93_HASH_SHA256:
   450				memcpy(req->result, sha256_zero_message_hash,
   451				       SHA256_DIGEST_SIZE);
   452				break;
   453			case EIP93_HASH_SHA224:
   454				memcpy(req->result, sha224_zero_message_hash,
   455				       SHA224_DIGEST_SIZE);
   456				break;
   457			case EIP93_HASH_SHA1:
   458				memcpy(req->result, sha1_zero_message_hash,
   459				       SHA1_DIGEST_SIZE);
   460				break;
   461			case EIP93_HASH_MD5:
   462				memcpy(req->result, md5_zero_message_hash,
   463				       MD5_DIGEST_SIZE);
   464				break;
   465			default: /* Impossible */
   466				return -EINVAL;
   467			}
   468	
   469			eip93_hash_free_sa_state(req);
   470			eip93_hash_free_sa_record(req);
   471	
   472			return 0;
   473		}
   474	
   475		/* Send last block */
   476		block = list_first_entry(&rctx->blocks, struct mkt_hash_block, list);
   477	
   478		block->data_dma = dma_map_single(mtk->dev, block->data,
   479						 SHA256_BLOCK_SIZE, DMA_TO_DEVICE);
   480		ret = dma_mapping_error(mtk->dev, block->data_dma);
   481		if (ret)
   482			return ret;
   483	
   484		eip93_send_hash_req(async, block->data_dma,
   485				    SHA256_BLOCK_SIZE - rctx->left_last,
   486				    true);
   487	
   488		return -EINPROGRESS;
   489	}
   490	
   491	static int eip93_hash_finup(struct ahash_request *req)
   492	{
   493		int ret;
   494	
   495		ret = eip93_hash_update(req);
   496		if (ret)
   497			return ret;
   498	
   499		return eip93_hash_final(req);
   500	}
   501	
   502	static int eip93_hash_hmac_setkey(struct crypto_ahash *ahash, const u8 *key,
   503					  u32 keylen)
   504	{
   505		unsigned int digestsize = crypto_ahash_digestsize(ahash);
   506		struct crypto_tfm *tfm = crypto_ahash_tfm(ahash);
   507		struct eip93_hash_ctx *ctx = crypto_tfm_ctx(tfm);
   508		struct crypto_ahash *ahash_tfm;
   509		struct eip93_hash_reqctx *rctx;
   510		struct scatterlist sg[1];
   511		struct ahash_request *req;
   512		DECLARE_CRYPTO_WAIT(wait);
   513		const char *alg_name;
   514		int i, ret = 0;
   515		u8 *opad;
   516	
   517		switch ((ctx->flags & EIP93_HASH_MASK)) {
   518		case EIP93_HASH_SHA256:
   519			alg_name = "sha256-eip93";
   520			break;
   521		case EIP93_HASH_SHA224:
   522			alg_name = "sha224-eip93";
   523			break;
   524		case EIP93_HASH_SHA1:
   525			alg_name = "sha1-eip93";
   526			break;
   527		case EIP93_HASH_MD5:
   528			alg_name = "md5-eip93";
   529			break;
   530		default: /* Impossible */
   531			return -EINVAL;
   532		}
   533	
   534		ahash_tfm = crypto_alloc_ahash(alg_name, 0, 0);
   535		if (IS_ERR(ahash_tfm))
   536			return PTR_ERR(ahash_tfm);
   537	
   538		req = ahash_request_alloc(ahash_tfm, GFP_KERNEL);
   539		if (!req) {
   540			ret = -ENOMEM;
   541			goto err_ahash;
   542		}
   543	
   544		opad = kzalloc(SHA256_BLOCK_SIZE, GFP_KERNEL);
   545		if (!opad) {
   546			ret = -ENOMEM;
   547			goto err_req;
   548		}
   549	
   550		rctx = ahash_request_ctx(req);
   551		crypto_init_wait(&wait);
   552		ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
   553					   crypto_req_done, &wait);
   554	
   555		/* Hash the key if > SHA256_BLOCK_SIZE */
   556		if (keylen > SHA256_BLOCK_SIZE) {
   557			sg_init_one(&sg[0], key, keylen);
   558	
   559			ahash_request_set_crypt(req, sg, ctx->ipad, keylen);
   560			ret = crypto_wait_req(crypto_ahash_digest(req), &wait);
   561	
   562			keylen = digestsize;
   563		} else {
   564			memcpy(ctx->ipad, key, keylen);
   565		}
   566	
   567		/* Copy to opad */
   568		memset(ctx->ipad + keylen, 0, SHA256_BLOCK_SIZE - keylen);
   569		memcpy(opad, ctx->ipad, SHA256_BLOCK_SIZE);
   570	
   571		/* Pad with HMAC constants */
   572		for (i = 0; i < SHA256_BLOCK_SIZE; i++) {
   573			ctx->ipad[i] ^= HMAC_IPAD_VALUE;
   574			opad[i] ^= HMAC_OPAD_VALUE;
   575		}
   576	
   577		sg_init_one(&sg[0], opad, SHA256_BLOCK_SIZE);
   578	
   579		/* Hash opad */
   580		ahash_request_set_crypt(req, sg, ctx->opad, SHA256_BLOCK_SIZE);
   581		ret = crypto_ahash_init(req);
   582		if (ret)
   583			goto exit;
   584	
   585		/* Disable HASH_FINALIZE for opad hash */
   586		rctx->no_finalize = true;
   587	
   588		ret = crypto_wait_req(crypto_ahash_finup(req), &wait);
   589		if (ret)
   590			goto exit;
   591	
   592		if (!IS_HASH_MD5(ctx->flags)) {
   593			u32 *opad_hash = (u32 *)ctx->opad;
   594	
   595			for (i = 0; i < SHA256_DIGEST_SIZE / sizeof(u32); i++)
 > 596				opad_hash[i] = cpu_to_be32(opad_hash[i]);
   597		}
   598	
   599	exit:
   600		kfree(opad);
   601	err_req:
   602		ahash_request_free(req);
   603	err_ahash:
   604		crypto_free_ahash(ahash_tfm);
   605	
   606		return ret;
   607	}
   608	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH v4 3/3] crypto: Add Mediatek EIP-93 crypto engine support
       [not found] <20241025094734.1614-3-ansuelsmth@gmail.com>
  2024-10-26 12:14 ` [PATCH v4 3/3] crypto: Add Mediatek EIP-93 crypto engine support kernel test robot
@ 2024-10-28  8:47 ` Dan Carpenter
  2024-10-28  8:54   ` Dan Carpenter
  1 sibling, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2024-10-28  8:47 UTC (permalink / raw)
  To: oe-kbuild, Christian Marangi, Herbert Xu, David S. Miller,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Antoine Tenart,
	Peter Zijlstra, Ingo Molnar, Will Deacon, Waiman Long, Boqun Feng,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	linux-crypto, devicetree, linux-kernel, llvm, upstream
  Cc: lkp, oe-kbuild-all, netdev, Richard van Schagen

Hi Christian,

kernel test robot noticed the following build warnings:

https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/dt-bindings-crypto-Add-Inside-Secure-SafeXcel-EIP-93-crypto-engine/20241025-175032
base:   https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master
patch link:    https://lore.kernel.org/r/20241025094734.1614-3-ansuelsmth%40gmail.com
patch subject: [PATCH v4 3/3] crypto: Add Mediatek EIP-93 crypto engine support
config: csky-randconfig-r071-20241028 (https://download.01.org/0day-ci/archive/20241028/202410281155.jEN0wSbS-lkp@intel.com/config)
compiler: csky-linux-gcc (GCC) 14.1.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
| Closes: https://lore.kernel.org/r/202410281155.jEN0wSbS-lkp@intel.com/

New smatch warnings:
drivers/crypto/inside-secure/eip93/eip93-cipher.c:118 eip93_skcipher_setkey() error: uninitialized symbol 'ret'.
drivers/crypto/inside-secure/eip93/eip93-aead.c:125 eip93_aead_setkey() error: uninitialized symbol 'ret'.
drivers/crypto/inside-secure/eip93/eip93-hash.c:26 eip93_hash_free_data_blocks() error: dereferencing freed memory 'block'
drivers/crypto/inside-secure/eip93/eip93-hash.c:162 _eip93_hash_init() error: uninitialized symbol 'sa_record_hmac'.

Old smatch warnings:
drivers/crypto/inside-secure/eip93/eip93-hash.c:285 eip93_send_hash_req() error: uninitialized symbol 'crypto_async_idr'.

vim +/ret +118 drivers/crypto/inside-secure/eip93/eip93-cipher.c

883ad7684f17d2 Christian Marangi 2024-10-25   78  static int eip93_skcipher_setkey(struct crypto_skcipher *ctfm, const u8 *key,
883ad7684f17d2 Christian Marangi 2024-10-25   79  				 unsigned int len)
883ad7684f17d2 Christian Marangi 2024-10-25   80  {
883ad7684f17d2 Christian Marangi 2024-10-25   81  	struct crypto_tfm *tfm = crypto_skcipher_tfm(ctfm);
883ad7684f17d2 Christian Marangi 2024-10-25   82  	struct eip93_crypto_ctx *ctx = crypto_tfm_ctx(tfm);
883ad7684f17d2 Christian Marangi 2024-10-25   83  	struct eip93_alg_template *tmpl = container_of(tfm->__crt_alg,
883ad7684f17d2 Christian Marangi 2024-10-25   84  						     struct eip93_alg_template,
883ad7684f17d2 Christian Marangi 2024-10-25   85  						     alg.skcipher.base);
883ad7684f17d2 Christian Marangi 2024-10-25   86  	struct sa_record *sa_record = ctx->sa_record;
883ad7684f17d2 Christian Marangi 2024-10-25   87  	unsigned int keylen = len;
883ad7684f17d2 Christian Marangi 2024-10-25   88  	u32 flags = tmpl->flags;
883ad7684f17d2 Christian Marangi 2024-10-25   89  	u32 nonce = 0;
883ad7684f17d2 Christian Marangi 2024-10-25   90  	int ret;
883ad7684f17d2 Christian Marangi 2024-10-25   91  
883ad7684f17d2 Christian Marangi 2024-10-25   92  	if (!key || !keylen)
883ad7684f17d2 Christian Marangi 2024-10-25   93  		return -EINVAL;
883ad7684f17d2 Christian Marangi 2024-10-25   94  
883ad7684f17d2 Christian Marangi 2024-10-25   95  	if (IS_RFC3686(flags)) {
883ad7684f17d2 Christian Marangi 2024-10-25   96  		if (len < CTR_RFC3686_NONCE_SIZE)
883ad7684f17d2 Christian Marangi 2024-10-25   97  			return -EINVAL;
883ad7684f17d2 Christian Marangi 2024-10-25   98  
883ad7684f17d2 Christian Marangi 2024-10-25   99  		keylen = len - CTR_RFC3686_NONCE_SIZE;
883ad7684f17d2 Christian Marangi 2024-10-25  100  		memcpy(&nonce, key + keylen, CTR_RFC3686_NONCE_SIZE);
883ad7684f17d2 Christian Marangi 2024-10-25  101  	}
883ad7684f17d2 Christian Marangi 2024-10-25  102  
883ad7684f17d2 Christian Marangi 2024-10-25  103  	if (flags & EIP93_ALG_DES) {
883ad7684f17d2 Christian Marangi 2024-10-25  104  		ctx->blksize = DES_BLOCK_SIZE;
883ad7684f17d2 Christian Marangi 2024-10-25  105  		ret = verify_skcipher_des_key(ctfm, key);
883ad7684f17d2 Christian Marangi 2024-10-25  106  	}
883ad7684f17d2 Christian Marangi 2024-10-25  107  	if (flags & EIP93_ALG_3DES) {
883ad7684f17d2 Christian Marangi 2024-10-25  108  		ctx->blksize = DES3_EDE_BLOCK_SIZE;
883ad7684f17d2 Christian Marangi 2024-10-25  109  		ret = verify_skcipher_des3_key(ctfm, key);
883ad7684f17d2 Christian Marangi 2024-10-25  110  	}
883ad7684f17d2 Christian Marangi 2024-10-25  111  
883ad7684f17d2 Christian Marangi 2024-10-25  112  	if (flags & EIP93_ALG_AES) {
883ad7684f17d2 Christian Marangi 2024-10-25  113  		struct crypto_aes_ctx aes;
883ad7684f17d2 Christian Marangi 2024-10-25  114  
883ad7684f17d2 Christian Marangi 2024-10-25  115  		ctx->blksize = AES_BLOCK_SIZE;
883ad7684f17d2 Christian Marangi 2024-10-25  116  		ret = aes_expandkey(&aes, key, keylen);
883ad7684f17d2 Christian Marangi 2024-10-25  117  	}

What about if none the flags are set?

883ad7684f17d2 Christian Marangi 2024-10-25 @118  	if (ret)
883ad7684f17d2 Christian Marangi 2024-10-25  119  		return ret;
883ad7684f17d2 Christian Marangi 2024-10-25  120  
883ad7684f17d2 Christian Marangi 2024-10-25  121  	eip93_set_sa_record(sa_record, keylen, flags);
883ad7684f17d2 Christian Marangi 2024-10-25  122  
883ad7684f17d2 Christian Marangi 2024-10-25  123  	memcpy(sa_record->sa_key, key, keylen);
883ad7684f17d2 Christian Marangi 2024-10-25  124  	ctx->sa_nonce = nonce;
883ad7684f17d2 Christian Marangi 2024-10-25  125  	sa_record->sa_nonce = nonce;
883ad7684f17d2 Christian Marangi 2024-10-25  126  
883ad7684f17d2 Christian Marangi 2024-10-25  127  	return 0;
883ad7684f17d2 Christian Marangi 2024-10-25  128  }

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


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

* Re: [PATCH v4 3/3] crypto: Add Mediatek EIP-93 crypto engine support
  2024-10-28  8:47 ` Dan Carpenter
@ 2024-10-28  8:54   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2024-10-28  8:54 UTC (permalink / raw)
  To: oe-kbuild, Christian Marangi, Herbert Xu, David S. Miller,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Antoine Tenart,
	Peter Zijlstra, Ingo Molnar, Will Deacon, Waiman Long, Boqun Feng,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	linux-crypto, devicetree, linux-kernel, llvm, upstream
  Cc: lkp, oe-kbuild-all, netdev, Richard van Schagen

On Mon, Oct 28, 2024 at 11:47:14AM +0300, Dan Carpenter wrote:
> drivers/crypto/inside-secure/eip93/eip93-hash.c:162 _eip93_hash_init() error: uninitialized symbol 'sa_record_hmac'.

This one is a false positive.  Smatch doesn't understand bit flags very well.

regards,
dan carpenter


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

end of thread, other threads:[~2024-10-28  8:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20241025094734.1614-3-ansuelsmth@gmail.com>
2024-10-26 12:14 ` [PATCH v4 3/3] crypto: Add Mediatek EIP-93 crypto engine support kernel test robot
2024-10-28  8:47 ` Dan Carpenter
2024-10-28  8:54   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox