From: Eric Biggers <ebiggers@kernel.org>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: Re: [PATCH] crc-t10dif: Fix potential crypto notify dead-lock
Date: Thu, 4 Jun 2020 22:40:49 -0700 [thread overview]
Message-ID: <20200605054049.GT2667@sol.localdomain> (raw)
In-Reply-To: <20200604063324.GA28813@gondor.apana.org.au>
On Thu, Jun 04, 2020 at 04:33:24PM +1000, Herbert Xu wrote:
> +static void crc_t10dif_rehash(struct work_struct *work)
> +{
> + struct crypto_shash *new, *old;
> +
> mutex_lock(&crc_t10dif_mutex);
> old = rcu_dereference_protected(crct10dif_tfm,
> lockdep_is_held(&crc_t10dif_mutex));
> if (!old) {
> mutex_unlock(&crc_t10dif_mutex);
> - return 0;
> + return;
> }
> new = crypto_alloc_shash("crct10dif", 0, 0);
> if (IS_ERR(new)) {
> mutex_unlock(&crc_t10dif_mutex);
> - return 0;
> + return;
> }
> rcu_assign_pointer(crct10dif_tfm, new);
> mutex_unlock(&crc_t10dif_mutex);
>
> synchronize_rcu();
> crypto_free_shash(old);
> - return 0;
> + return;
> }
The last return statement is unnecessary.
> static int __init crc_t10dif_mod_init(void)
> {
> + struct crypto_shash *tfm;
> +
> + INIT_WORK(&crct10dif_rehash_work, crc_t10dif_rehash);
> crypto_register_notifier(&crc_t10dif_nb);
> - crct10dif_tfm = crypto_alloc_shash("crct10dif", 0, 0);
> - if (IS_ERR(crct10dif_tfm)) {
> + mutex_lock(&crc_t10dif_mutex);
> + tfm = crypto_alloc_shash("crct10dif", 0, 0);
> + if (IS_ERR(tfm)) {
> static_key_slow_inc(&crct10dif_fallback);
> - crct10dif_tfm = NULL;
> + tfm = NULL;
> }
> + RCU_INIT_POINTER(crct10dif_tfm, tfm);
> + mutex_unlock(&crc_t10dif_mutex);
> return 0;
> }
Wouldn't it make more sense to initialize crct10dif_tfm before registering the
notifier? Then the mutex wouldn't be needed.
- Eric
next prev parent reply other threads:[~2020-06-05 5:40 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-04 6:33 [PATCH] crc-t10dif: Fix potential crypto notify dead-lock Herbert Xu
2020-06-05 5:40 ` Eric Biggers [this message]
2020-06-05 6:49 ` Herbert Xu
2020-06-05 6:59 ` [v2 PATCH] " Herbert Xu
2020-06-05 18:22 ` Eric Biggers
2020-06-05 18:25 ` Herbert Xu
2020-06-05 18:48 ` Eric Biggers
2020-06-08 6:25 ` Herbert Xu
2020-06-05 18:45 ` Eric Biggers
2020-06-08 6:26 ` Herbert Xu
2020-06-09 1:28 ` Martin K. Petersen
2020-06-10 6:42 ` Eric Biggers
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=20200605054049.GT2667@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=ard.biesheuvel@linaro.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=martin.petersen@oracle.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;
as well as URLs for NNTP newsgroup(s).