Skip to content

Commit a4659be

Browse files
DanCh2020jankara
authored andcommitted
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: fb5de43 ("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>
1 parent f6fce9f commit a4659be

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

fs/ext2/file.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,15 @@ static ssize_t ext2_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
161161
endbyte = pos + status - 1;
162162
ret2 = filemap_write_and_wait_range(inode->i_mapping, pos,
163163
endbyte);
164-
if (!ret2)
164+
if (!ret2) {
165165
invalidate_mapping_pages(inode->i_mapping,
166166
pos >> PAGE_SHIFT,
167167
endbyte >> PAGE_SHIFT);
168-
if (ret > 0)
169-
generic_write_sync(iocb, ret);
168+
if (ret > 0)
169+
ret = generic_write_sync(iocb, ret);
170+
} else {
171+
ret = ret2;
172+
}
170173
}
171174

172175
out_unlock:

0 commit comments

Comments
 (0)