Linux FSCRYPT development
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Baokun Li <libaokun@linux.alibaba.com>
Cc: linux-fscrypt@vger.kernel.org, tytso@mit.edu, jaegeuk@kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v4] fscrypt: Fix missing barrier in fscrypt_find_mode_key()
Date: Sat, 24 Oct 2026 11:04:28 -0700	[thread overview]
Message-ID: <20261024180428.GB2553@quark> (raw)
In-Reply-To: <20261024104350.2257313-1-libaokun@linux.alibaba.com>

On Sat, Oct 24, 2026 at 06:43:50PM +0800, Baokun Li wrote:
> fscrypt_find_mode_key() walks an RCU list and hands out a per-mode
> key without an acquire:
> 
>   setup task
>   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   setup_per_mode_enc_key()
>    ├─ fscrypt_prepare_key()
>    │  └─ fscrypt_prepare_inline_crypt_key()
>    │     └─ blk_crypto_start_using_key()
>    │        └─ blk_crypto_fallback_start_using_mode()
>    │           ├─ init profile, keyslots, tfms[]
>    │           └─ smp_store_release(tfms_inited[mode])  # init order
>    └─ list_add_tail_rcu(&new_node->link, ...)  # release -> finder
> 
>   finding task (later submits the I/O itself)
>   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   fscrypt_find_mode_key()
>    ├─ list_for_each_entry_rcu(node, ...)
>    └─ return &node->key                 # no acquire, chain breaks
>   ...
>   blk_crypto_fallback_bio_prep()        # WRITE path
>    ├─ tfms_inited[mode]                 # addr-dep, reads true
>    ├─ blk_crypto_fallback_profile       # no dependency
>    ├─ blk_crypto_keyslots               # no dependency
>    └─ slotp->tfms[mode]                 # no dependency
> 
> RCU publishes the node and the key reachable from it, so
> tfms_inited[mode] reads true through the address dependency.  The
> independent fallback globals are not covered by it and can be read as
> uninitialized.
> 
> On a weakly ordered machine, a WRITE bio can crash in
> blk_crypto_get_keyslot() or crypto_sync_skcipher_setkey().
> 
> Other tasks reach the key through fscrypt_inode_info's
> cmpxchg_release()/smp_load_acquire(), which is already ordered after
> the list walk; only the finding task's own later I/O was not.
> 
> Fix this by upgrading the control dependency to an acquire with
> smp_acquire__after_ctrl_dep() once a matching entry has been found.
> 
> Fixes: dd015b566d50 ("fscrypt: Fix key setup in edge case with multiple data unit sizes")
> Cc: stable@vger.kernel.org
> Suggested-by: Eric Biggers <ebiggers@kernel.org>
> Link: https://lore.kernel.org/r/20261014161153.GC322435@quark
> Signed-off-by: Baokun Li <libaokun@linux.alibaba.com>
> ---
> Changes since v3:
>  * Update commit message and comments as suggested by Eric.

Applied to https://git.kernel.org/pub/scm/fs/fscrypt/linux.git/log/?h=for-next

Thanks!

- Eric

      reply	other threads:[~2026-10-24 18:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-24 10:43 [PATCH v4] fscrypt: Fix missing barrier in fscrypt_find_mode_key() Baokun Li
2026-10-24 18:04 ` Eric Biggers [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=20261024180428.GB2553@quark \
    --to=ebiggers@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=libaokun@linux.alibaba.com \
    --cc=linux-fscrypt@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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