Skip to content

Commit a608da3

Browse files
author
Damien Le Moal
committed
zonefs: Detect append writes at invalid locations
Using REQ_OP_ZONE_APPEND operations for synchronous writes to sequential files succeeds regardless of the zone write pointer position, as long as the target zone is not full. This means that if an external (buggy) application writes to the zone of a sequential file underneath the file system, subsequent file write() operation will succeed but the file size will not be correct and the file will contain invalid data written by another application. Modify zonefs_file_dio_append() to check the written sector of an append write (returned in bio->bi_iter.bi_sector) and return -EIO if there is a mismatch with the file zone wp offset field. This change triggers a call to zonefs_io_error() and a zone check. Modify zonefs_io_error_cb() to not expose the unexpected data after the current inode size when the errors=remount-ro mode is used. Other error modes are correctly handled already. Fixes: 02ef12a ("zonefs: use REQ_OP_ZONE_APPEND for sync DIO") Cc: [email protected] Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]>
1 parent 5dc4c99 commit a608da3

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)