[Devel] [PATCH hci-8.2] dm-qcow2: fix a short image read resubmitted at the wrong sector
Denis V. Lunev
den at openvz.org
Thu Nov 19 17:29:56 MSK 2026
From: Denis V. Lunev <den at openvz.org>
data_rw_complete() resubmits the rest of a short image transfer through
qio_advance(), which moves the buffer by ret bytes but bi_sector only by
ret >> 9. When ret is not a multiple of 512, the resubmit rereads from
below where the transfer stopped into the buffer past it.
A read-only image whose file ends inside a sector and a page or more
short of the read gets such a read. On ext4 or xfs the O_DIRECT
resubmit fails with -EINVAL. On a file system that takes unaligned
O_DIRECT reads, such as NFS or FUSE, the same tail bytes are read again
and again into the buffer, and the read completes with wrong data and
no error.
A short read that ends at EOF of a read-only image cannot make
progress, as the file does not grow: zero-fill it when less than a page
is missing, as before, and fail it with -EIO otherwise. Fail any other
short transfer that is not a multiple of 512 bytes, including a write,
which would rewrite good bytes at the rounded-down offset, instead of
resubmitting it.
https://virtuozzo.atlassian.net/browse/VSTOR-156059
Fixes: 222b6f1291c1 ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Denis V. Lunev <den at openvz.org>
---
Applies on top of the series "dm-qcow2: fix a read livelock at EOF of a
read-only image" v2.
drivers/md/dm-qcow2-map.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index cf66b9a98085..c0aaff8815ad 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -3013,11 +3013,14 @@ static void data_rw_complete(struct qio *qio)
if (unlikely(qio->ret != qio->bi_iter.bi_size)) {
if (!write && qio->ret > 0 && !qcow2_file_is_writable(qcow2) &&
- to_bytes(qio->bi_iter.bi_sector) + qio->ret == qcow2->file_size &&
- qio->bi_iter.bi_size - qio->ret < PAGE_SIZE) {
+ to_bytes(qio->bi_iter.bi_sector) + qio->ret == qcow2->file_size) {
/* Read near EOF, same as md_page_read_complete() */
- zero_fill_qio(qio, qio->ret, qio->bi_iter.bi_size - qio->ret);
- } else if (!write && qio->ret == 0) {
+ if (qio->bi_iter.bi_size - qio->ret < PAGE_SIZE)
+ zero_fill_qio(qio, qio->ret, qio->bi_iter.bi_size - qio->ret);
+ else
+ bi_status = BLK_STS_IOERR;
+ } else if ((!write && qio->ret == 0) ||
+ (qio->ret > 0 && (qio->ret & (SECTOR_SIZE - 1)))) {
bi_status = BLK_STS_IOERR;
} else if (qio->ret >= 0) {
WARN_ON_ONCE(qio->ret == 0);
--
2.55.0
More information about the Devel
mailing list