mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arbab Haider <arbabhaider649@gmail.com>
To: tytso@mit.edu
Cc: adilger.kernel@dilger.ca, libaokun@linux.alibaba.com,
	jack@suse.cz, ojaswin@linux.ibm.com, ritesh.list@gmail.com,
	yi.zhang@huawei.com, yebin10@huawei.com,
	linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v4 4/5] ext4: re-check inline data under filemap_invalidate_lock in swap_inode_boot_loader
Date: Thu, 26 Nov 2026 12:07:48 +0500	[thread overview]
Message-ID: <20261126070748.272109-6-arbabhaider649@gmail.com> (raw)
In-Reply-To: <20261126070748.272109-2-arbabhaider649@gmail.com>

swap_inode_boot_loader() checks ext4_has_inline_data(inode) while holding
only i_rwsem (via lock_two_nondirectories()), before acquiring
filemap_invalidate_lock(inode->i_mapping).

A concurrent ext4_page_mkwrite() -> ext4_convert_inline_data_nolock()
(which holds filemap_invalidate_lock_shared, not i_rwsem) transiently
clears EXT4_INODE_INLINE_DATA before ext4_map_blocks().  If
swap_inode_boot_loader() observes !ext4_has_inline_data(inode), waits on
filemap_invalidate_lock(), and ext4_convert_inline_data_nolock() then
rolls back via ext4_restore_inline_data() on -ENOSPC,
swap_inode_boot_loader() proceeds to swap_inode_data() on the still-inline
inode.  Because EXT4_INLINE_DATA_FL is not in EXT4_FL_SHOULD_SWAP, this
swaps raw inline data in ei->i_data with EXT4_BOOT_LOADER_INO's extent
header and corrupts both inodes on disk.

Re-check ext4_has_inline_data(inode) after acquiring
filemap_invalidate_lock(inode->i_mapping).

Signed-off-by: Arbab Haider <arbabhaider649@gmail.com>
---
 fs/ext4/ioctl.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 83630cd40..e0c53d62d 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -419,6 +419,10 @@ static long swap_inode_boot_loader(struct super_block *sb,
 	}
 
 	filemap_invalidate_lock(inode->i_mapping);
+	if (ext4_has_inline_data(inode)) {
+		err = -EINVAL;
+		goto err_out;
+	}
 	err = filemap_write_and_wait(inode->i_mapping);
 	if (err)
 		goto err_out;
-- 
2.53.0


  parent reply	other threads:[~2026-11-26  7:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  7:07 [PATCH v4 0/5] ext4: fix inline data conversion races Arbab Haider
2026-11-26  7:07 ` [PATCH v4 1/5] ext4: stub the nonatomic buffer lookup in inode KUnit tests Arbab Haider
2026-11-26  7:07 ` [PATCH v4 2/5] ext4: fix delayed-allocation inline data conversion races Arbab Haider
2026-11-26  7:07 ` [PATCH v4 3/5] ext4: keep EXT4_STATE_MAY_INLINE_DATA set during inline conversion Arbab Haider
2026-11-26  7:07 ` Arbab Haider [this message]
2026-11-26  7:07 ` [PATCH v4 5/5] ext4: serialize inode migration against concurrent inline data conversion Arbab Haider

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=20261126070748.272109-6-arbabhaider649@gmail.com \
    --to=arbabhaider649@gmail.com \
    --cc=adilger.kernel@dilger.ca \
    --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=yebin10@huawei.com \
    --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®