]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
ext4: fix warning in ext4_dio_write_end_io()
authorJan Kara <jack@suse.cz>
Thu, 30 Nov 2023 09:56:53 +0000 (10:56 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Oct 2024 13:12:02 +0000 (15:12 +0200)
commita97eacadb09632579ef57b0c49f6606ddf965490
tree0613dd0f29f7bb1f912f52e313c671c034a94f10
parent8fcd1021b2608924fe3a9df45d99888ebdd2a28d
ext4: fix warning in ext4_dio_write_end_io()

commit 619f75dae2cf117b1d07f27b046b9ffb071c4685 upstream.

The syzbot has reported that it can hit the warning in
ext4_dio_write_end_io() because i_size < i_disksize. Indeed the
reproducer creates a race between DIO IO completion and truncate
expanding the file and thus ext4_dio_write_end_io() sees an inconsistent
inode state where i_disksize is already updated but i_size is not
updated yet. Since we are careful when setting up DIO write and consider
it extending (and thus performing the IO synchronously with i_rwsem held
exclusively) whenever it goes past either of i_size or i_disksize, we
can use the same test during IO completion without risking entering
ext4_handle_inode_extension() without i_rwsem held. This way we make it
obvious both i_size and i_disksize are large enough when we report DIO
completion without relying on unreliable WARN_ON.

Reported-by: <syzbot+47479b71cdfc78f56d30@syzkaller.appspotmail.com>
Fixes: 91562895f803 ("ext4: properly sync file size update after O_SYNC direct IO")
Signed-off-by: Jan Kara <jack@suse.cz>
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Link: https://lore.kernel.org/r/20231130095653.22679-1-jack@suse.cz
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/ext4/file.c