Commit ed8d1152 authored by Zhang Yi's avatar Zhang Yi
Browse files

ext4: writeback partial blocks before zeroing out range

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I9DN5Z


CVE: NA

--------------------------------

If we zero partial blocks, iomap_zero_iter() will skip zeroing out the
IOMAP_UNWRITTEN srcmap, it works fine in xfs because this type means the
block is pure unwritten and doesn't contain any delayed data. But it
doesn't work in ext4, because IOMAP_UNWRITTEN may contain delayed data
in ext4. For now it's hard to unify the meaning of this flag, so just
fix it by writeback partial blocks before zeroing out.

Signed-off-by: default avatarZhang Yi <yi.zhang@huawei.com>
parent 57219682
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -4627,6 +4627,15 @@ static long ext4_zero_range(struct file *file, loff_t offset,
		if (ret)
			goto out_mutex;

		ret = filemap_write_and_wait_range(mapping,
				round_down(offset, 1 << blkbits), offset);
		if (ret)
			goto out_mutex;

		ret = filemap_write_and_wait_range(mapping, offset + len,
				round_up((offset + len), 1 << blkbits));
		if (ret)
			goto out_mutex;
	}

	/* Zero range excluding the unaligned edges */