* [PATCH] ext4: recompute the inode checksum after restoring inline data
@ 2026-11-25 14:38 Petr Vaněk
2026-11-25 14:46 ` sashiko-bot
2026-11-25 16:44 ` Jan Kara
0 siblings, 2 replies; 3+ messages in thread
From: Petr Vaněk @ 2026-11-25 14:38 UTC (permalink / raw)
To: Theodore Ts'o, Andreas Dilger, Baokun Li, Jan Kara,
Ojaswin Mujoo, Ritesh Harjani (IBM), Zhang Yi
Cc: Petr Vaněk, stable, linux-ext4
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] ext4: recompute the inode checksum after restoring inline data
2026-11-25 14:38 [PATCH] ext4: recompute the inode checksum after restoring inline data Petr Vaněk
@ 2026-11-25 14:46 ` sashiko-bot
2026-11-25 16:44 ` Jan Kara
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-25 14:46 UTC (permalink / raw)
To: Petr Vaněk; +Cc: linux-ext4, tytso
> 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
> [ ... ]
> 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>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125143841.928615-1-petr.vanek@e2b.dev?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] ext4: recompute the inode checksum after restoring inline data
2026-11-25 14:38 [PATCH] ext4: recompute the inode checksum after restoring inline data Petr Vaněk
2026-11-25 14:46 ` sashiko-bot
@ 2026-11-25 16:44 ` Jan Kara
1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2026-11-25 16:44 UTC (permalink / raw)
To: Petr Vaněk
Cc: Theodore Ts'o, Andreas Dilger, Baokun Li, Jan Kara,
Ojaswin Mujoo, Ritesh Harjani (IBM), Zhang Yi, stable, linux-ext4
On Wed 25-11-26 15:38:39, Petr Vaněk wrote:
> 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>
Yeah, looks easy enough. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> 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
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-25 16:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 14:38 [PATCH] ext4: recompute the inode checksum after restoring inline data Petr Vaněk
2026-11-25 14:46 ` sashiko-bot
2026-11-25 16:44 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox