From: Nathan Huckleberry <nhuck@google.com>
To: Eric Biggers <ebiggers@kernel.org>
Cc: linux-block@vger.kernel.org, Jens Axboe <axboe@kernel.dk>,
linux-fscrypt@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 2/3] blk-crypto: make blk_crypto_evict_key() more robust
Date: Fri, 3 Mar 2023 12:30:42 -0800 [thread overview]
Message-ID: <CAJkfWY6BGT-++LjcAs=JELOn_54-TRquJfjz0bx-yw30g0mt-A@mail.gmail.com> (raw)
In-Reply-To: <ZAJPcMibOQ9DARmp@gmail.com>
You're right. Nevermind.
Reviewed-by: Nathan Huckleberry <nhuck@google.com>
On Fri, Mar 3, 2023 at 11:50 AM Eric Biggers <ebiggers@kernel.org> wrote:
>
> On Fri, Mar 03, 2023 at 11:45:00AM -0800, Nathan Huckleberry wrote:
> > > int __blk_crypto_evict_key(struct blk_crypto_profile *profile,
> > > const struct blk_crypto_key *key)
> > > @@ -389,22 +377,22 @@ int __blk_crypto_evict_key(struct blk_crypto_profile *profile,
> > >
> > > blk_crypto_hw_enter(profile);
> > > slot = blk_crypto_find_keyslot(profile, key);
> > > - if (!slot)
> > > - goto out_unlock;
> > > -
> > > - if (WARN_ON_ONCE(atomic_read(&slot->slot_refs) != 0)) {
> > > - err = -EBUSY;
> > > - goto out_unlock;
> > > + if (slot) {
> > > + if (WARN_ON_ONCE(atomic_read(&slot->slot_refs) != 0)) {
> > > + /* BUG: key is still in use by I/O */
> > > + err = -EBUSY;
> > > + } else {
> > > + err = profile->ll_ops.keyslot_evict(
> > > + profile, key,
> > > + blk_crypto_keyslot_index(slot));
> > > + }
> > > + /*
> > > + * Callers may free the key even on error, so unlink the key
> > > + * from the hash table and clear slot->key even on error.
> > > + */
> > > + hlist_del(&slot->hash_node);
> > > + slot->key = NULL;
> > > }
> >
> > The !slot case still needs to be handled. If profile->num_slots != 0
> > and !slot, we'll get an invalid index from blk_crypto_keyslot_index.
> >
> > With that change,
> > Reviewed-by: Nathan Huckleberry <nhuck@google.com>
> >
> > Thanks,
> > Huck
> >
> > > - err = profile->ll_ops.keyslot_evict(profile, key,
> > > - blk_crypto_keyslot_index(slot));
> > > - if (err)
> > > - goto out_unlock;
> > > -
> > > - hlist_del(&slot->hash_node);
> > > - slot->key = NULL;
> > > - err = 0;
> > > -out_unlock:
> > > blk_crypto_hw_exit(profile);
> > > return err;
> > > }
>
> I'm not sure what you're referring to. The !slot case is handled correctly, and
> it's the same as before.
>
> - Eric
next prev parent reply other threads:[~2023-03-03 20:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-03 7:19 [PATCH 0/3] Fix blk-crypto keyslot race condition Eric Biggers
2023-03-03 7:19 ` [PATCH 1/3] blk-mq: release crypto keyslot before reporting I/O complete Eric Biggers
2023-03-03 19:29 ` Nathan Huckleberry
2023-03-08 18:21 ` Eric Biggers
2023-03-03 7:19 ` [PATCH 2/3] blk-crypto: make blk_crypto_evict_key() more robust Eric Biggers
2023-03-03 19:45 ` Nathan Huckleberry
2023-03-03 19:50 ` Eric Biggers
2023-03-03 20:30 ` Nathan Huckleberry [this message]
2023-03-03 7:19 ` [PATCH 3/3] blk-crypto: remove blk_crypto_insert_cloned_request() 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='CAJkfWY6BGT-++LjcAs=JELOn_54-TRquJfjz0bx-yw30g0mt-A@mail.gmail.com' \
--to=nhuck@google.com \
--cc=axboe@kernel.dk \
--cc=ebiggers@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fscrypt@vger.kernel.org \
--cc=stable@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;
as well as URLs for NNTP newsgroup(s).