Skip to content

Commit 081edde

Browse files
committed
Merge tag 'zonefs-6.2-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/dlemoal/zonefs
Pull zonefs fix from Damien Le Moal: - A single patch to fix sync write operations to detect and handle errors due to external zone corruptions resulting in writes at invalid location, from me. * tag 'zonefs-6.2-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/dlemoal/zonefs: zonefs: Detect append writes at invalid locations
2 parents 7287904 + a608da3 commit 081edde

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

fs/zonefs/super.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,10 @@ static int zonefs_io_error_cb(struct blk_zone *zone, unsigned int idx,
442442
data_size = zonefs_check_zone_condition(inode, zone,
443443
false, false);
444444
}
445+
} else if (sbi->s_mount_opts & ZONEFS_MNTOPT_ERRORS_RO &&
446+
data_size > isize) {
447+
/* Do not expose garbage data */
448+
data_size = isize;
445449
}
446450

447451
/*
@@ -805,6 +809,24 @@ static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from)
805809

806810
ret = submit_bio_wait(bio);
807811

812+
/*
813+
* If the file zone was written underneath the file system, the zone
814+
* write pointer may not be where we expect it to be, but the zone
815+
* append write can still succeed. So check manually that we wrote where
816+
* we intended to, that is, at zi->i_wpoffset.
817+
*/
818+
if (!ret) {
819+
sector_t wpsector =
820+
zi->i_zsector + (zi->i_wpoffset >> SECTOR_SHIFT);
821+
822+
if (bio->bi_iter.bi_sector != wpsector) {
823+
zonefs_warn(inode->i_sb,
824+
"Corrupted write pointer %llu for zone at %llu\n",
825+
wpsector, zi->i_zsector);
826+
ret = -EIO;
827+
}
828+
}
829+
808830
zonefs_file_write_dio_end_io(iocb, size, ret, 0);
809831
trace_zonefs_file_dio_append(inode, size, ret);
810832

0 commit comments

Comments
 (0)