mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-22 01:08:13 -04:00
ext2: fix ignored return value of generic_write_sync()
Fix ext2_dio_write_iter() to propagate the error returned by
generic_write_sync() instead of silently discarding it, which could
cause write(2) to return success to userspace on O_SYNC/O_DSYNC files
even when the sync failed.
The correct pattern, already used in ext2_dax_write_iter() in the same
file and in ext4, xfs, f2fs among others, is:
if (ret > 0)
ret = generic_write_sync(iocb, ret);
Found by Linux Verification Center (linuxtesting.org) with SVACE.
[JK: Reflect also filemap_write_and_wait() return value]
Fixes: fb5de4358e ("ext2: Move direct-io to use iomap")
Signed-off-by: Danila Chernetsov <listdansp@mail.ru>
Link: https://patch.msgid.link/20260530122311.136803-1-listdansp@mail.ru
Signed-off-by: Jan Kara <jack@suse.cz>
This commit is contained in:
committed by
Jan Kara
parent
f6fce9f17d
commit
a4659be0bc
@@ -161,12 +161,15 @@ static ssize_t ext2_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
||||
endbyte = pos + status - 1;
|
||||
ret2 = filemap_write_and_wait_range(inode->i_mapping, pos,
|
||||
endbyte);
|
||||
if (!ret2)
|
||||
if (!ret2) {
|
||||
invalidate_mapping_pages(inode->i_mapping,
|
||||
pos >> PAGE_SHIFT,
|
||||
endbyte >> PAGE_SHIFT);
|
||||
if (ret > 0)
|
||||
generic_write_sync(iocb, ret);
|
||||
if (ret > 0)
|
||||
ret = generic_write_sync(iocb, ret);
|
||||
} else {
|
||||
ret = ret2;
|
||||
}
|
||||
}
|
||||
|
||||
out_unlock:
|
||||
|
||||
Reference in New Issue
Block a user