From: "Denis V. Lunev" <den@openvz.org>
To: andrey.zhadchenko@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 3/3] dm-qcow2: fix SEEK_HOLE/SEEK_DATA using an image freed by a merge
Date: Tue, 3 Nov 2026 09:37:08 +0100 [thread overview]
Message-ID: <20261103083708.131379-4-den@openvz.org> (raw)
In-Reply-To: <20261103083708.131379-1-den@openvz.org>
From: Denis V. Lunev <den@openvz.org>
qcow2_llseek_hole() starts at tgt->top and follows qcow2->lower,
parsing the metadata of each image, without an inflight ref. dm core
holds only the table SRCU around the call, which does not keep a
target message out. merge_backward complete unlinks the merged image,
waits in qcow2_inflight_ref_switch() for the qios holding refs and
destroys the image, so a seek already walking it goes on with a freed
struct qcow2, its md pages and its file. A SEEK_DATA scan of a large
sparse image keeps the walk running long enough to hit it.
Hold an inflight ref for the whole walk and take the top image from
qcow2_ref_inc() under it.
Fixes: 412d5a4f7bf1 ("dm/dm-qcow2: add llseek_hole")
https://virtuozzo.atlassian.net/browse/VSTOR-153050
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
drivers/md/dm-qcow2-map.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 8ab7cb472560..358a71f75cb4 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -4841,18 +4841,25 @@ static int qcow2_llseek_hole_qio(struct qio *qio, int whence, loff_t *result)
loff_t qcow2_llseek_hole(struct dm_target *ti, loff_t offset, int whence)
{
- struct qcow2 *qcow2 = to_qcow2_target(ti)->top;
+ struct qcow2_target *tgt = to_qcow2_target(ti);
loff_t result = -EINVAL;
+ struct qcow2 *qcow2;
struct qio *qio;
+ u8 ref_index;
int ret;
+ /* Keep merge_backward complete from freeing images under the walk */
+ qcow2 = qcow2_ref_inc(tgt, &ref_index);
qio = alloc_seek_qio(qcow2, NULL, qcow2->hdr.size);
- if (!qio)
+ if (!qio) {
+ qcow2_ref_dec(tgt, ref_index);
return -ENOMEM;
+ }
seek_qio_set_sector(qio, to_sector(offset));
ret = qcow2_llseek_hole_qio(qio, whence, &result);
+ qcow2_ref_dec(tgt, ref_index);
/* In case of error remap ENXIO as it have special meaning for llseek */
if (ret < 0)
return (ret == -ENXIO) ? -EINVAL : ret;
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-11-03 8:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 8:37 [Devel] [PATCH hci-8.1 0/3] dm-qcow2: fix merges not stopping the users of the images they change Denis V. Lunev
2026-11-03 8:37 ` [Devel] [PATCH hci-8.1 1/3] dm-qcow2: fix a failed refcount table relocation leaking md pages Denis V. Lunev
2026-11-03 8:45 ` no-reply
2026-11-03 8:37 ` [Devel] [PATCH hci-8.1 2/3] dm-qcow2: fix backward merge of an inner image racing its reads Denis V. Lunev
2026-11-03 8:44 ` no-reply
2026-11-03 8:37 ` Denis V. Lunev [this message]
2026-11-03 8:47 ` [Devel] [PATCH hci-8.1 3/3] dm-qcow2: fix SEEK_HOLE/SEEK_DATA using an image freed by a merge no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261103083708.131379-4-den@openvz.org \
--to=den@openvz.org \
--cc=andrey.zhadchenko@virtuozzo.com \
--cc=devel@openvz.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox