mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Enderborg <peter.enderborg@sony.com>
To: <linux-crypto@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S . Miller" <davem@davemloft.net>
Cc: Peter Enderborg <peter.enderborg@sony.com>
Subject: [PATCH] crypto: Mark tfm buffer as non leak.
Date: Thu, 3 Sep 2020 15:40:07 +0200	[thread overview]
Message-ID: <20200903134007.2769-1-peter.enderborg@sony.com> (raw)

When running kmemleak on this I got a lot of

unreferenced object 0xfffffff942d4ec00 (size 1024):
  comm "init", pid 1, jiffies 4294893619 (age 17475.864s)
  hex dump (first 32 bytes):
    38 1d cf bd 9e ff ff ff b8 37 8b bd 9e ff ff ff  8........7......
    78 38 8b bd 9e ff ff ff 10 00 00 00 00 00 00 00  x8..............
  backtrace:
    [<00000000c3c55a80>] __kmalloc+0x2cc/0x3b0
    [<00000000c599b091>] crypto_create_tfm+0x38/0xf0
    [<00000000d4516e51>] crypto_spawn_tfm2+0x58/0xa0
    [<000000001bab58aa>] cryptd_skcipher_init_tfm+0x1c/0x40
    [<0000000006748df3>] crypto_skcipher_init_tfm+0x158/0x1e0
    [<0000000017f3270c>] crypto_create_tfm+0x54/0xf0
    [<000000006af1de62>] crypto_alloc_tfm+0x88/0x198
    [<000000000d8e8c03>] crypto_alloc_skcipher+0x1c/0x28
    [<0000000085448a2a>] cryptd_alloc_skcipher+0x5c/0xb0
    [<000000003c48c083>] simd_skcipher_init+0x24/0x68
    [<0000000006748df3>] crypto_skcipher_init_tfm+0x158/0x1e0
    [<0000000017f3270c>] crypto_create_tfm+0x54/0xf0
    [<00000000d4516e51>] crypto_spawn_tfm2+0x58/0xa0
    [<00000000b5344705>] crypto_cts_init_tfm+0x1c/0x68
    [<0000000006748df3>] crypto_skcipher_init_tfm+0x158/0x1e0
    [<0000000017f3270c>] crypto_create_tfm+0x54/0xf0

This is caused by tfm = (struct crypto_tfm *)(mem + tfmsize);
that is keept instead of the allocated buffer in mem.
Reference counting is done on alg.

Signed-off-by: Peter Enderborg <peter.enderborg@sony.com>
---
 crypto/api.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/crypto/api.c b/crypto/api.c
index ed08cbd5b9d3..1a9cb6852a56 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -21,6 +21,7 @@
 #include <linux/string.h>
 #include <linux/completion.h>
 #include "internal.h"
+#include <linux/kmemleak.h>
 
 LIST_HEAD(crypto_alg_list);
 EXPORT_SYMBOL_GPL(crypto_alg_list);
@@ -460,7 +461,7 @@ void *crypto_create_tfm_node(struct crypto_alg *alg,
 
 	if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm)))
 		goto cra_init_failed;
-
+	kmemleak_not_leak(mem);
 	goto out;
 
 cra_init_failed:
-- 
2.17.1


             reply	other threads:[~2020-09-03 14:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-03 13:40 Peter Enderborg [this message]
2020-09-04  7:17 ` Herbert Xu

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=20200903134007.2769-1-peter.enderborg@sony.com \
    --to=peter.enderborg@sony.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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®