From: Disha Goel <disgoel@linux.ibm.com>
To: Ojaswin Mujoo <ojaswin@linux.ibm.com>,
linux-ext4@vger.kernel.org, "Theodore Ts'o" <tytso@mit.edu>
Cc: Ritesh Harjani <ritesh.list@gmail.com>,
Zhang Yi <yi.zhang@huawei.com>,
linux-kernel@vger.kernel.org,
Baokun Li <libaokun@linux.alibaba.com>, Jan Kara <jack@suse.cz>
Subject: Re: [PATCH] ext4: turn off DAX on new files when encryption is set
Date: Mon, 27 Jul 2026 17:29:45 +0530 [thread overview]
Message-ID: <77364e40-f193-4a35-b26f-5c4252315650@linux.ibm.com> (raw)
In-Reply-To: <20260723085648.1500357-1-ojaswin@linux.ibm.com>
On 23/07/26 2:26 pm, Ojaswin Mujoo wrote:
> Currently, when setting the S_ENCRYPTED flag on a new regular inode in
> a -o dax=always mounted FS, we seem to be erroneously retaining the S_DAX
> flag. This is because the newly created inode ends up with the following:
>
> __ext4_new_inode()
> ext4_set_inode_flags(init=true) // sets S_DAX
> fscrypt_set_context()
> ext4_set_context()
> ext4_set_inode_flags(init=false) // sets S_ENCRYPTED but
> doesn't clears S_DAX
> ext4_set_aops
> inode->i_mapping->a_ops = &ext4_dax_aops;
>
> Due to the S_DAX flag, the excrypted inode gets ext4_dax_aops and it
> silently ends up bypassing encryption completely. This is reflected in
> multiple xfstests failures like generic/548. To fix this, ensure we disable
> S_DAX correctly when S_ENCRYPTED is being set on a newly created inode. It
> is safe to change DAX state there because ext4_set_aops() later can
> correctly detect S_DAX unset and assign the correct aops.
>
> The fix was actually the intended behavior however it seemed to have
> silently changed in 043546e46dc7.
>
> Fixes: 043546e46dc7 ("fs/ext4: Only change S_DAX on inode load")
> Reported-by: Disha Goel <disgoel@linux.ibm.com>
> Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
> ---
Thanks for the fix patch Ojaswin. This fixes the issue I reported.
Tested on a -o dax=always ext4 filesystem on ppc64le with the following
xfstests configuration:
FSTYP=ext4
MOUNT_OPTIONS="-o block_validity,dax"
MKFS_OPTIONS="-b 65536"
All failing encryption tests in the generic group now pass.
Tested-by: Disha Goel <disgoel@linux.ibm.com>
> fs/ext4/crypto.c | 15 +++++++++++----
> fs/ext4/inode.c | 10 ++++++----
> 2 files changed, 17 insertions(+), 8 deletions(-)
>
> diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c
> index f41f320f4437..2d409114e02e 100644
> --- a/fs/ext4/crypto.c
> +++ b/fs/ext4/crypto.c
> @@ -134,6 +134,7 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,
> {
> handle_t *handle = fs_data;
> int res, res2, credits, retries = 0;
> + bool init = S_ISREG(inode->i_mode);
>
> /*
> * Encrypting the root directory is not allowed because e2fsck expects
> @@ -179,10 +180,16 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,
> ext4_clear_inode_state(inode,
> EXT4_STATE_MAY_INLINE_DATA);
> /*
> - * Update inode->i_flags - S_ENCRYPTED will be enabled,
> - * S_DAX may be disabled
> + * Update inode->i_flags, S_ENCRYPTED will be enabled.
> + * If this is a regular inode, then we must be coming
> + * via __ext4_new_inode() as only new inodes can be
> + * encrypted, so we must set the init flag so
> + * S_DAX can be disabled. This is a bit fragile but
> + * seems like the easiest way to make sure we don't let
> + * the DAX flag linger when encryption is enabled as
> + * that result in writes silently bypassing encryption.
> */
> - ext4_set_inode_flags(inode, false);
> + ext4_set_inode_flags(inode, init);
> }
> return res;
> }
> @@ -209,7 +216,7 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,
> * Update inode->i_flags - S_ENCRYPTED will be enabled,
> * S_DAX may be disabled
> */
> - ext4_set_inode_flags(inode, false);
> + ext4_set_inode_flags(inode, init);
> res = ext4_mark_inode_dirty(handle, inode);
> if (res)
> EXT4_ERROR_INODE(inode, "Failed to mark inode dirty");
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index ce99807c5f5b..a57179655353 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -5113,8 +5113,6 @@ void ext4_set_inode_flags(struct inode *inode, bool init)
> unsigned int flags = EXT4_I(inode)->i_flags;
> unsigned int new_fl = 0;
>
> - WARN_ON_ONCE(IS_DAX(inode) && init);
> -
> if (flags & EXT4_SYNC_FL)
> new_fl |= S_SYNC;
> if (flags & EXT4_APPEND_FL)
> @@ -5129,8 +5127,12 @@ void ext4_set_inode_flags(struct inode *inode, bool init)
> /* Because of the way inode_set_flags() works we must preserve S_DAX
> * here if already set. */
> new_fl |= (inode->i_flags & S_DAX);
> - if (init && ext4_should_enable_dax(inode))
> - new_fl |= S_DAX;
> + if (init) {
> + if (ext4_should_enable_dax(inode))
> + new_fl |= S_DAX;
> + else
> + new_fl &= ~S_DAX;
> + }
>
> if (flags & EXT4_ENCRYPT_FL)
> new_fl |= S_ENCRYPTED;
--
Regards,
Disha
next prev parent reply other threads:[~2026-07-27 12:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 8:56 Ojaswin Mujoo
2026-07-27 11:59 ` Disha Goel [this message]
2026-07-27 19:01 ` Eric Biggers
2026-07-27 19:06 ` Jan Kara
2026-07-27 19:43 ` Eric Biggers
2026-07-27 20:13 ` Eric Biggers
2026-07-28 13:29 ` Jan Kara
2026-07-28 19:34 ` Ojaswin Mujoo
2026-07-30 8:35 ` Disha Goel
2026-07-28 19:17 ` Ojaswin Mujoo
2026-07-28 19:34 ` Jan Kara
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=77364e40-f193-4a35-b26f-5c4252315650@linux.ibm.com \
--to=disgoel@linux.ibm.com \
--cc=jack@suse.cz \
--cc=libaokun@linux.alibaba.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojaswin@linux.ibm.com \
--cc=ritesh.list@gmail.com \
--cc=tytso@mit.edu \
--cc=yi.zhang@huawei.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
all inboxes | Powered by JetHome®