mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@lists.01.org, Corentin Labbe <clabbe@baylibre.com>
Cc: lkp@intel.com, kbuild-all@lists.01.org,
	linux-kernel@vger.kernel.org,
	Herbert Xu <herbert@gondor.apana.org.au>
Subject: [kbuild] drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c:443 sun8i_ss_hash_run() warn: possible memory leak of 'result'
Date: Thu, 7 Jan 2021 16:12:36 +0300	[thread overview]
Message-ID: <20210107131236.GB5105@kadam> (raw)

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

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git  master
head:   e71ba9452f0b5b2e8dc8aa5445198cd9214a6a62
commit: d9b45418a91773b7672e4c60037a28074b495c6d crypto: sun8i-ss - support hash algorithms
config: arc-randconfig-m031-20210106 (attached as .config)
compiler: arc-elf-gcc (GCC) 9.3.0

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

smatch warnings:
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c:443 sun8i_ss_hash_run() warn: possible memory leak of 'result'

vim +/result +443 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c

d9b45418a91773b7 Corentin Labbe 2020-09-18  361  
d9b45418a91773b7 Corentin Labbe 2020-09-18  362  	rctx->method = ss->variant->alg_hash[algt->ss_algo_id];
d9b45418a91773b7 Corentin Labbe 2020-09-18  363  
d9b45418a91773b7 Corentin Labbe 2020-09-18  364  	nr_sgs = dma_map_sg(ss->dev, areq->src, sg_nents(areq->src), DMA_TO_DEVICE);
d9b45418a91773b7 Corentin Labbe 2020-09-18  365  	if (nr_sgs <= 0 || nr_sgs > MAX_SG) {
d9b45418a91773b7 Corentin Labbe 2020-09-18  366  		dev_err(ss->dev, "Invalid sg number %d\n", nr_sgs);
d9b45418a91773b7 Corentin Labbe 2020-09-18  367  		err = -EINVAL;
d9b45418a91773b7 Corentin Labbe 2020-09-18  368  		goto theend;
d9b45418a91773b7 Corentin Labbe 2020-09-18  369  	}
d9b45418a91773b7 Corentin Labbe 2020-09-18  370  
d9b45418a91773b7 Corentin Labbe 2020-09-18  371  	addr_res = dma_map_single(ss->dev, result, digestsize, DMA_FROM_DEVICE);
d9b45418a91773b7 Corentin Labbe 2020-09-18  372  	if (dma_mapping_error(ss->dev, addr_res)) {
d9b45418a91773b7 Corentin Labbe 2020-09-18  373  		dev_err(ss->dev, "DMA map dest\n");
d9b45418a91773b7 Corentin Labbe 2020-09-18  374  		err = -EINVAL;
d9b45418a91773b7 Corentin Labbe 2020-09-18  375  		goto theend;
d9b45418a91773b7 Corentin Labbe 2020-09-18  376  	}
d9b45418a91773b7 Corentin Labbe 2020-09-18  377  
d9b45418a91773b7 Corentin Labbe 2020-09-18  378  	len = areq->nbytes;
d9b45418a91773b7 Corentin Labbe 2020-09-18  379  	for_each_sg(areq->src, sg, nr_sgs, i) {
d9b45418a91773b7 Corentin Labbe 2020-09-18  380  		rctx->t_src[i].addr = sg_dma_address(sg);
d9b45418a91773b7 Corentin Labbe 2020-09-18  381  		todo = min(len, sg_dma_len(sg));
d9b45418a91773b7 Corentin Labbe 2020-09-18  382  		rctx->t_src[i].len = todo / 4;
d9b45418a91773b7 Corentin Labbe 2020-09-18  383  		len -= todo;
d9b45418a91773b7 Corentin Labbe 2020-09-18  384  		rctx->t_dst[i].addr = addr_res;
d9b45418a91773b7 Corentin Labbe 2020-09-18  385  		rctx->t_dst[i].len = digestsize / 4;
d9b45418a91773b7 Corentin Labbe 2020-09-18  386  	}
d9b45418a91773b7 Corentin Labbe 2020-09-18  387  	if (len > 0) {
d9b45418a91773b7 Corentin Labbe 2020-09-18  388  		dev_err(ss->dev, "remaining len %d\n", len);
d9b45418a91773b7 Corentin Labbe 2020-09-18  389  		err = -EINVAL;
d9b45418a91773b7 Corentin Labbe 2020-09-18  390  		goto theend;
d9b45418a91773b7 Corentin Labbe 2020-09-18  391  	}
d9b45418a91773b7 Corentin Labbe 2020-09-18  392  
d9b45418a91773b7 Corentin Labbe 2020-09-18  393  	byte_count = areq->nbytes;
d9b45418a91773b7 Corentin Labbe 2020-09-18  394  	j = 0;
d9b45418a91773b7 Corentin Labbe 2020-09-18  395  	bf[j++] = cpu_to_le32(0x80);
d9b45418a91773b7 Corentin Labbe 2020-09-18  396  
d9b45418a91773b7 Corentin Labbe 2020-09-18  397  	fill = 64 - (byte_count % 64);
d9b45418a91773b7 Corentin Labbe 2020-09-18  398  	min_fill = 3 * sizeof(u32);
d9b45418a91773b7 Corentin Labbe 2020-09-18  399  
d9b45418a91773b7 Corentin Labbe 2020-09-18  400  	if (fill < min_fill)
d9b45418a91773b7 Corentin Labbe 2020-09-18  401  		fill += 64;
d9b45418a91773b7 Corentin Labbe 2020-09-18  402  
d9b45418a91773b7 Corentin Labbe 2020-09-18  403  	j += (fill - min_fill) / sizeof(u32);
d9b45418a91773b7 Corentin Labbe 2020-09-18  404  
d9b45418a91773b7 Corentin Labbe 2020-09-18  405  	switch (algt->ss_algo_id) {
d9b45418a91773b7 Corentin Labbe 2020-09-18  406  	case SS_ID_HASH_MD5:
d9b45418a91773b7 Corentin Labbe 2020-09-18  407  		lebits = (__le64 *)&bf[j];
d9b45418a91773b7 Corentin Labbe 2020-09-18  408  		*lebits = cpu_to_le64(byte_count << 3);
d9b45418a91773b7 Corentin Labbe 2020-09-18  409  		j += 2;
d9b45418a91773b7 Corentin Labbe 2020-09-18  410  		break;
d9b45418a91773b7 Corentin Labbe 2020-09-18  411  	case SS_ID_HASH_SHA1:
d9b45418a91773b7 Corentin Labbe 2020-09-18  412  	case SS_ID_HASH_SHA224:
d9b45418a91773b7 Corentin Labbe 2020-09-18  413  	case SS_ID_HASH_SHA256:
d9b45418a91773b7 Corentin Labbe 2020-09-18  414  		bebits = (__be64 *)&bf[j];
d9b45418a91773b7 Corentin Labbe 2020-09-18  415  		*bebits = cpu_to_be64(byte_count << 3);
d9b45418a91773b7 Corentin Labbe 2020-09-18  416  		j += 2;
d9b45418a91773b7 Corentin Labbe 2020-09-18  417  		break;
d9b45418a91773b7 Corentin Labbe 2020-09-18  418  	}
d9b45418a91773b7 Corentin Labbe 2020-09-18  419  
d9b45418a91773b7 Corentin Labbe 2020-09-18  420  	addr_pad = dma_map_single(ss->dev, pad, j * 4, DMA_TO_DEVICE);
d9b45418a91773b7 Corentin Labbe 2020-09-18  421  	rctx->t_src[i].addr = addr_pad;
d9b45418a91773b7 Corentin Labbe 2020-09-18  422  	rctx->t_src[i].len = j;
d9b45418a91773b7 Corentin Labbe 2020-09-18  423  	rctx->t_dst[i].addr = addr_res;
d9b45418a91773b7 Corentin Labbe 2020-09-18  424  	rctx->t_dst[i].len = digestsize / 4;
d9b45418a91773b7 Corentin Labbe 2020-09-18  425  	if (dma_mapping_error(ss->dev, addr_pad)) {
d9b45418a91773b7 Corentin Labbe 2020-09-18  426  		dev_err(ss->dev, "DMA error on padding SG\n");
d9b45418a91773b7 Corentin Labbe 2020-09-18  427  		err = -EINVAL;
d9b45418a91773b7 Corentin Labbe 2020-09-18  428  		goto theend;
                                                                ^^^^^^^^^^^^
result not freed on this path.

d9b45418a91773b7 Corentin Labbe 2020-09-18  429  	}
d9b45418a91773b7 Corentin Labbe 2020-09-18  430  
d9b45418a91773b7 Corentin Labbe 2020-09-18  431  	err = sun8i_ss_run_hash_task(ss, rctx, crypto_tfm_alg_name(areq->base.tfm));
d9b45418a91773b7 Corentin Labbe 2020-09-18  432  
d9b45418a91773b7 Corentin Labbe 2020-09-18  433  	dma_unmap_single(ss->dev, addr_pad, j * 4, DMA_TO_DEVICE);
d9b45418a91773b7 Corentin Labbe 2020-09-18  434  	dma_unmap_sg(ss->dev, areq->src, nr_sgs, DMA_TO_DEVICE);
d9b45418a91773b7 Corentin Labbe 2020-09-18  435  	dma_unmap_single(ss->dev, addr_res, digestsize, DMA_FROM_DEVICE);
d9b45418a91773b7 Corentin Labbe 2020-09-18  436  
d9b45418a91773b7 Corentin Labbe 2020-09-18  437  	kfree(pad);
d9b45418a91773b7 Corentin Labbe 2020-09-18  438  
d9b45418a91773b7 Corentin Labbe 2020-09-18  439  	memcpy(areq->result, result, algt->alg.hash.halg.digestsize);
d9b45418a91773b7 Corentin Labbe 2020-09-18  440  	kfree(result);
d9b45418a91773b7 Corentin Labbe 2020-09-18  441  theend:
d9b45418a91773b7 Corentin Labbe 2020-09-18  442  	crypto_finalize_hash_request(engine, breq, err);
d9b45418a91773b7 Corentin Labbe 2020-09-18 @443  	return 0;

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

[-- Attachment #3: Type: text/plain, Size: 149 bytes --]

_______________________________________________
kbuild mailing list -- kbuild@lists.01.org
To unsubscribe send an email to kbuild-leave@lists.01.org

             reply	other threads:[~2021-01-07 13:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-07 13:12 Dan Carpenter [this message]
2021-01-10 20:12 ` LABBE Corentin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210107131236.GB5105@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=clabbe@baylibre.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=kbuild-all@lists.01.org \
    --cc=kbuild@lists.01.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®