Skip to content

Commit 554c577

Browse files
author
Andreas Gruenbacher
committed
gfs2: Prevent endless loops in gfs2_file_buffered_write
Currently, instead of performing a short write, iomap_file_buffered_write will fail when part of its iov iterator cannot be read. In contrast, gfs2_file_buffered_write will loop around if it can read part of the iov iterator, so we can end up in an endless loop. This should be fixed in iomap_file_buffered_write (and also generic_perform_write), but this comes a bit late in the 5.16 development cycle, so work around it in the filesystem by trimming the iov iterator to the known-good size for now. Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent a7ac203 commit 554c577

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

fs/gfs2/file.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,7 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb,
10131013
struct gfs2_sbd *sdp = GFS2_SB(inode);
10141014
struct gfs2_holder *statfs_gh = NULL;
10151015
size_t prev_count = 0, window_size = 0;
1016+
size_t orig_count = iov_iter_count(from);
10161017
size_t read = 0;
10171018
ssize_t ret;
10181019

@@ -1057,13 +1058,15 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb,
10571058
if (inode == sdp->sd_rindex)
10581059
gfs2_glock_dq_uninit(statfs_gh);
10591060

1061+
from->count = orig_count - read;
10601062
if (should_fault_in_pages(ret, from, &prev_count, &window_size)) {
10611063
size_t leftover;
10621064

10631065
gfs2_holder_allow_demote(gh);
10641066
leftover = fault_in_iov_iter_readable(from, window_size);
10651067
gfs2_holder_disallow_demote(gh);
10661068
if (leftover != window_size) {
1069+
from->count = min(from->count, window_size - leftover);
10671070
if (!gfs2_holder_queued(gh)) {
10681071
if (read)
10691072
goto out_uninit;

0 commit comments

Comments
 (0)