Check backing_file chain's loop
Hi,
Now block layer does not check whether backing_file chain can be a circle, do you think it is necessary to do a check?
For example, 1.qcow2's backing_file is 2.qcow2 and 2.qcow2's backing_file is 1.qcow2, then any IO operation will be a fault.
If necessary, I will post a patch to fix.
[$] qemu-img create -f qcow2 1.qcow2
qemu-img: Image creation needs a size parameter
[$] qemu-img create -f qcow2 1.qcow2 8M
Formatting '1.qcow2', fmt=qcow2 size=8388608 encryption=off cluster_size=65536 lazy_refcounts=off [$] qemu-img create -f qcow2 2.qcow2 -o backing_file=1.qcow2
Formatting '2.qcow2', fmt=qcow2 size=8388608 backing_file='1.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off [$] qemu-img create -f qcow2 1.qcow2 -o backing_file=2.qcow2
Formatting '1.qcow2', fmt=qcow2 size=8388608 backing_file='2.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off [$] qemu-io -c "read -v 0 512" 1.qcow2
^CSegmentation fault (core dumped)
Thanks.
Quoted 9 lines · Dongxu Wang
Hi,
Now block layer does not check whether
backing_filechain can be a circle, do you think it is necessary to do a check?For example, 1.qcow2's
backing_fileis 2.qcow2 and 2.qcow2'sbacking_fileis 1.qcow2, then any IO operation will be a fault.If necessary, I will post a patch to fix.
Yes, it's worth patching.
Quoted 14 lines
[$] qemu-img create -f qcow2 1.qcow2
qemu-img: Image creation needs a size parameter
[$] qemu-img create -f qcow2 1.qcow2 8M
Formatting '1.qcow2', fmt=qcow2 size=8388608 encryption=off cluster_size=65536 lazy_refcounts=off
[$] qemu-img create -f qcow2 2.qcow2 -o backing_file=1.qcow2 Formatting '2.qcow2', fmt=qcow2 size=8388608 backing_file='1.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off
[$] qemu-img create -f qcow2 1.qcow2 -o backing_file=2.qcow2 Formatting '1.qcow2', fmt=qcow2 size=8388608 backing_file='2.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off
[$] qemu-io -c "read -v 0 512" 1.qcow2
^CSegmentation fault (core dumped)
Also make sure that 'qemu-img info 1.qcow2' and 'qemu-img info --backing-chain 1.qcow2' don't crash.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 28 lines · Eric Blake
Quoted 9 lines · Dongxu Wang
Hi,
Now block layer does not check whether
backing_filechain can be a circle, do you think it is necessary to do a check?For example, 1.qcow2's
backing_fileis 2.qcow2 and 2.qcow2'sbacking_fileis 1.qcow2, then any IO operation will be a fault.If necessary, I will post a patch to fix.
Yes, it's worth patching.
Quoted 14 lines
[$] qemu-img create -f qcow2 1.qcow2
qemu-img: Image creation needs a size parameter
[$] qemu-img create -f qcow2 1.qcow2 8M
Formatting '1.qcow2', fmt=qcow2 size=8388608 encryption=off cluster_size=65536 lazy_refcounts=off
[$] qemu-img create -f qcow2 2.qcow2 -o backing_file=1.qcow2 Formatting '2.qcow2', fmt=qcow2 size=8388608 backing_file='1.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off
[$] qemu-img create -f qcow2 1.qcow2 -o backing_file=2.qcow2 Formatting '1.qcow2', fmt=qcow2 size=8388608 backing_file='2.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off
[$] qemu-io -c "read -v 0 512" 1.qcow2
^CSegmentation fault (core dumped)
Quoted 2 lines
Also make sure that 'qemu-img info 1.qcow2' and 'qemu-img info --backing-chain 1.qcow2' don't crash.
qemu-img info --backing-chain detects cycles and returns an error, see the hash table in collect_image_info_list().
We should protect bdrv_open() too.
Stefan
Quoted 6 lines · Stefan Hajnoczi
Quoted 1 line
hain 1.qcow2' don't crash.
qemu-img info --backing-chain detects cycles and returns an error, see the hash table in
collect_image_info_list().We should protect
bdrv_open()too.
Okay, will send a patch.
Quoted 3 lines
Stefan