All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: Corentin LABBE <clabbe.montjoie@gmail.com>
Cc: linux-crypto@vger.kernel.org
Subject: Re: Crash when using ahash_request_ctx
Date: Sun, 1 Jun 2014 18:52:24 +0200	[thread overview]
Message-ID: <201406011852.24151.marex@denx.de> (raw)
In-Reply-To: <5385B3E5.3090108@gmail.com>

On Wednesday, May 28, 2014 at 12:01:09 PM, Corentin LABBE wrote:
> Hello
> 
> I have a problem when using a simple md5 tfm.
> When I use the data that ahash_request_ctx() give me, it will cause random
> crash when removing the module later. I do not understand it, because
> .cra_ctxsize seems to be rightly used.
> 
> The very simplified POC code will follow, it register a fake md5
> implementation. If I remove the op->mode = 0, I can modprobe/rmmod for
> ever without problem. With it, rmmod will segfault in 2 or 3 tries, so it
> is this write that is the source of the problem.
> 
> I have try to debug, but I cannot find where __ctx (the pointer returned by
> ahash_request_ctx) is allocated.
> 
> Does I am right when saying: ahash_request_ctx() return the pointer to a
> structure of size equal to cra_ctxsize allocated for each request ?

crypto_tfm_ctx() returns per-transformation instance (tfm) private data
ahash_request_ctx() returns per-request private data

You need to configure the request context size via crypto_ahash_set_reqsize() in 
the implementations' .cra_init() callback .

[...]

static int my_cra_init(struct crypto_tfm *tfm)
{
 crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
                          sizeof(struct my_per_request_private_data));
 return 0;
}

> static struct ahash_alg sunxi_md5_alg = {
> 	.init = fake_init,
> 	.update = fake_update,
> 	.final = fake_final,
> 	.finup = fake_finup,
> 	.digest = fake_digest,
> 	.halg = {
> 		.digestsize = MD5_DIGEST_SIZE,
> 		.base = {
> 			.cra_name = "md5",
> 			.cra_driver_name = "md5-sunxi-ss",
> 			.cra_priority = 300,
> 			.cra_alignmask = 3,
> 			.cra_flags = CRYPTO_ALG_TYPE_AHASH | CRYPTO_ALG_ASYNC,
> 			.cra_blocksize = MD5_HMAC_BLOCK_SIZE,
> 			.cra_ctxsize = sizeof(struct sunxi_req_ctx),
> 			.cra_module = THIS_MODULE,
> 			.cra_type = &crypto_ahash_type

 .cra_init = my_cra_init,

> 		}
> 	}
> };
> 
> static int sunxi_ss_md5_init(void)
> {
> 	int err = 0;
> 	err = crypto_register_ahash(&sunxi_md5_alg);
> 	if (err)
> 		pr_err("crypto_register_alg error for MD5\n");
> 	else
> 		pr_info("Registred MD5\n");
> 	return err;
> }
> 
> static void __exit sunxi_ss_md5_exit(void)
> {
> 	crypto_unregister_ahash(&sunxi_md5_alg);
> }
> 
> module_init(sunxi_ss_md5_init);
> module_exit(sunxi_ss_md5_exit);

module_platform_driver() here please, fix it up so this is a platform driver.

      reply	other threads:[~2014-06-01 17:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-28 10:01 Crash when using ahash_request_ctx Corentin LABBE
2014-06-01 16:52 ` Marek Vasut [this message]

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=201406011852.24151.marex@denx.de \
    --to=marex@denx.de \
    --cc=clabbe.montjoie@gmail.com \
    --cc=linux-crypto@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 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.