Linux EXT4 FS development
 help / color / mirror / Atom feed
From: "Petr Vaněk" <petr.vanek@e2b.dev>
To: "Theodore Ts'o" <tytso@mit.edu>,
	Andreas Dilger <adilger.kernel@dilger.ca>,
	Baokun Li <libaokun@linux.alibaba.com>, Jan Kara <jack@suse.cz>,
	Ojaswin Mujoo <ojaswin@linux.ibm.com>,
	"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
	Zhang Yi <yi.zhang@huawei.com>
Cc: "Petr Vaněk" <petr.vanek@e2b.dev>,
	stable@vger.kernel.org, linux-ext4@vger.kernel.org
Subject: [PATCH] ext4: recompute the inode checksum after restoring inline data
Date: Wed, 25 Nov 2026 15:38:39 +0100	[thread overview]
Message-ID: <20261125143841.928615-1-petr.vanek@e2b.dev> (raw)

ext4_restore_inline_data() recreates the system.data xattr with
ext4_create_inline_data(), which marks the inode dirty and so sets its
checksum, and only then copies the saved bytes into the raw inode with
ext4_write_inline_data().  Unless something dirties the inode again
before it is written out, the inode reaches the disk with a checksum
that does not match its contents.

Failed inline data conversions take this path, for example an mmap write
to a small inline file on a full filesystem:

  mkfs.ext4 -O inline_data /dev/vdb 64M
  mount /dev/vdb /mnt
  xfs_io -f -c "pwrite -S 0x61 0 42" /mnt/small
  xfs_io -f -c "falloc 0 64m" /mnt/fill                # ENOSPC, fs is full
  xfs_io -c "mmap -rw 0 42" -c "mwrite 0 1" /mnt/small # SIGBUS
  umount /mnt; mount /dev/vdb /mnt
  cat /mnt/small                                       # EBADMSG

The read after the remount fails with:

  [    1.203967] EXT4-fs error (device vdb): ext4_lookup:1635: inode #4097: comm cat: iget: checksum invalid

Mark the inode dirty again after ext4_write_inline_data(), so the
checksum written to disk covers the restored data.

The Fixes tag is based on code analysis: ext4_restore_inline_data() has
called ext4_create_inline_data() before ext4_write_inline_data() since
that commit.  The failure reproduces on v5.19 and later; older kernels
were not tested.

Fixes: 3c47d54170b6 ("ext4: let add_dir_entry handle inline data properly")
Cc: stable@vger.kernel.org
Signed-off-by: Petr Vaněk <petr.vanek@e2b.dev>
---
This patch was developed with the help of an AI coding assistant
(Claude Opus via OpenCode).  It analysed the bug, wrote the fix and the
changelog, and built the QEMU test setup; I reviewed the change and the
test results.

Tested with the reproducer above in QEMU (x86_64, KASAN and lockdep
enabled) on 7.4-rc5 with and without the patch; e2fsck is clean after
the patched run.  Not tested: xfstests, other architectures.

 fs/ext4/inline.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index acdc65ce47960..360c06441c8f1 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -1111,6 +1111,8 @@ static void ext4_restore_inline_data(handle_t *handle, struct inode *inode,
 	}
 	ext4_write_inline_data(inode, iloc, buf, 0, inline_size);
 	ext4_set_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
+	/* Update the inode checksum to cover the restored data. */
+	ext4_mark_inode_dirty(handle, inode);
 }
 
 struct buffer_head *ext4_inline_getblk(struct super_block *sb,
-- 
2.56.1


             reply	other threads:[~2026-11-25 14:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 14:38 Petr Vaněk [this message]
2026-11-25 14:46 ` [PATCH] ext4: recompute the inode checksum after restoring inline data sashiko-bot
2026-11-25 16:44 ` 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=20261125143841.928615-1-petr.vanek@e2b.dev \
    --to=petr.vanek@e2b.dev \
    --cc=adilger.kernel@dilger.ca \
    --cc=jack@suse.cz \
    --cc=libaokun@linux.alibaba.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=ojaswin@linux.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=stable@vger.kernel.org \
    --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