From: Eric Biggers <ebiggers@kernel.org>
To: Baokun Li <libaokun@linux.alibaba.com>
Cc: axboe@kernel.dk, linux-block@vger.kernel.org,
linux-fscrypt@vger.kernel.org, hch@lst.de,
dm-devel@lists.linux.dev, mpatocka@redhat.com,
sweettea-kernel@dorminy.me, satyat@google.com,
stable@vger.kernel.org
Subject: Re: [PATCH v2 2/2] blk-crypto: fix missing smp_load_acquire() for tfms_inited[]
Date: Thu, 15 Oct 2026 18:32:00 +0000 [thread overview]
Message-ID: <20261015183200.GC2170687@google.com> (raw)
In-Reply-To: <006e3804-7e5e-4b8d-a299-3a47b8b643b3@linux.alibaba.com>
On Fri, Oct 16, 2026 at 01:36:17AM +0800, Baokun Li wrote:
> That's what I was about to do for v3, but while looking for other
> callers that inherit a key without calling start_using_key()
> themselves, I found that dm-inlinecrypt has the same shape, so fixing
> fscrypt alone wouldn't cover it -- only the constructor calls
> start_using_key(), and the task submitting I/O reaches the key through
> md->map:
>
> dmsetup (ctr) I/O task
> ---------------------------------- -------------------------------
> blk_crypto_start_using_key()
> fallback_start_using_mode()
> init profile, keyslots, tfms[]
> smp_store_release(tfms_inited[m])
> rcu_assign_pointer(md->map, t)
> srcu_dereference(md->map)
> -> ti->private -> &ctx->key
> inlinecrypt_map() -> bio_prep()
> tfms_inited[m] addr-dep, ok
> profile/keyslots/tfms[] not
>
> dm's own grace periods would cover this, but all three are conditional:
>
> drivers/md/dm.c:2533 if (old_map) dm_sync_table(md);
> drivers/md/dm.c:3015,3039 if (map) synchronize_srcu(&md->io_barrier);
> drivers/md/dm-ioctl.c:1651 add_disk() only when type == DM_TYPE_NONE
>
> so e.g. this sequence has no happens-before:
>
> DM_DEV_CREATE
> DM_TABLE_LOAD (linear) add_disk(), md->type set, not resumed
> -> a task opens the device here
> DM_TABLE_CLEAR
> DM_TABLE_LOAD (inlinecrypt) ctr sets tfms_inited[]; no add_disk()
> DM_DEV_SUSPEND (resume) old_map == NULL, all three skipped
> -> the already-open task does I/O
>
> This needs a weakly ordered machine and a deliberate ioctl order, so
> it's not urgent. Which would you prefer?
>
> 1. Leave it for now and fix only fscrypt_find_mode_key().
>
> 2. A separate smp_rmb() in inlinecrypt_map(), paired with the
> rcu_assign_pointer(md->map) in __bind(). Keeps the cost on
> dm-inlinecrypt only, but means a second site to get right.
>
> 3. Keep the barrier in blk_crypto_fallback_bio_prep() after all,
> documented as ordering the loads after the check rather than the
> flag itself. One site covers both callers and any future one,
> at the cost of blk-crypto no longer relying on the caller for
> this part.
So the device-mapper core doesn't order target_type::ctr before
target_type::map? Nearly every dm target's map function relies on the
constructor having run first. If this is an issue, it isn't specific to
dm-inlinecrypt and it will need to be fixed in the device-mapper core.
- Eric
next prev parent reply other threads:[~2026-10-15 18:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 7:18 [PATCH v2 1/2] blk-crypto: fix NULL deref and UAF in __blk_crypto_evict_key() Baokun Li
2026-10-14 7:18 ` [PATCH v2 2/2] blk-crypto: fix missing smp_load_acquire() for tfms_inited[] Baokun Li
2026-10-14 16:11 ` Eric Biggers
2026-10-15 17:36 ` Baokun Li
2026-10-15 18:32 ` Eric Biggers [this message]
2026-10-14 15:51 ` [PATCH v2 1/2] blk-crypto: fix NULL deref and UAF in __blk_crypto_evict_key() Eric Biggers
2026-10-15 13:44 ` Baokun Li
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=20261015183200.GC2170687@google.com \
--to=ebiggers@kernel.org \
--cc=axboe@kernel.dk \
--cc=dm-devel@lists.linux.dev \
--cc=hch@lst.de \
--cc=libaokun@linux.alibaba.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-fscrypt@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=satyat@google.com \
--cc=stable@vger.kernel.org \
--cc=sweettea-kernel@dorminy.me \
/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