block/copy-before-write: wait for conflicts when read locking to avoid assertion failure
PATCH 1/1 block/copy-before-write: wait for conflicts when read locking to avoid assertion failure
There is no protection against two callers of cbw_snapshot_read_lock() calling reqlist_init_req() with overlapping ranges, and reqlist_init_req() asserts that there are no conflicting requests.
In particular, two cbw_co_snapshot_block_status() callers can race, with the second calling reqlist_init_req() before the first one finishes and removes its conflicting request, leading to an assertion failure.
Reproducer script [0] and backtrace [1] are attached below.
[0]:
Quoted 13 lines
#!/bin/bash -e
dd if=/dev/urandom of=/tmp/disk.raw bs=1M count=1024
./qemu-img create/tmp/fleecing.raw-f raw 1G
(
./qemu-system-x86_64 --qmp stdio \
--blockdev raw,node-name=node0,file.driver=file,file.filename=/tmp/disk.raw \
--blockdev raw,node-name=node1,file.driver=file,file.filename=/tmp/fleecing.raw \
<<EOF
{"execute": "qmp_capabilities"}
{"execute": "blockdev-add", "arguments": { "driver": "copy-before-write", "file": "node0", "target": "node1", "node-name": "node3" } } {"execute": "blockdev-add", "arguments": { "driver": "snapshot-access", "file": "node3", "node-name": "snap0" } } {"execute": "nbd-server-start", "arguments": {"addr": { "type": "unix", "data": { "path": "/tmp/nbd.socket" } } } } {"execute": "block-export-add", "arguments": {"id": "exp0", "node-name": "snap0", "type": "nbd", "name": "exp0"}}
Quoted 8 lines
EOF
) &
sleep 5
while true; do
./qemu-nbd -d/dev/nbd0
./qemu-nbd -c/dev/nbd0nbd:unix:/tmp/nbd.socket:exportname=exp0 -f raw -r nbdinfo --map 'nbd+unix:///exp0?socket=/tmp/nbd.socket'
done
[1]:
Quoted 5 lines
#5 0x000071e5f0088eb2 in __GI___assert_fail (...) at ./assert/assert.c:101 #6 0x0000615285438017 in reqlist_init_req (...) at ../block/reqlist.c:23 #7 0x00006152853e2d98 in cbw_snapshot_read_lock (...) at ../block/copy-before-write.c:237 #8 0x00006152853e3068 in cbw_co_snapshot_block_status (...) at ../block/copy-before-write.c:304 #9 0x00006152853f4d22 in bdrv_co_snapshot_block_status (...) at ../block/io.c:3726
Quoted 10 lines
#10
0x000061528543a63einsnapshot_access_co_block_status(...) at../block/snapshot-access.c:48#110x00006152853f1a0ainbdrv_co_do_block_status(...) at../block/io.c:2474#120x00006152853f2016inbdrv_co_common_block_status_above(...) at../block/io.c:2652#130x00006152853f22cfinbdrv_co_block_status_above(...) at../block/io.c:2732#140x00006152853d9a86inblk_co_block_status_above(...) at../block/block-backend.c:1473#150x000061528538da6cinblockstatus_to_extents(...) at../nbd/server.c:2374#160x000061528538deb1innbd_co_send_block_status(...) at../nbd/server.c:2481#170x000061528538f424innbd_handle_request(...) at../nbd/server.c:2978
#180x000061528538f906innbd_trip(...) at../nbd/server.c:3121
#190x00006152855a7cafincoroutine_trampoline(...) at../util/coroutine-ucontext.c:175
--- block/copy-before-write.c | 1 + 1 file changed, 1 insertion(+)
block/copy-before-write.c +1 -0
@@ -234,6 +234,7 @@ cbw_snapshot_read_lock(BlockDriverState *bs, int64_t offset, int64_t bytes, *req = (BlockReq ) {.offset =-1 , .bytes =-1 }; *file = s->target; }else { +reqlist_wait_all (&s->frozen_read_reqs, offset, bytes, &s->lock);reqlist_init_req (&s->frozen_read_reqs, req, offset, bytes); *file = bs->file; }
Signature · 1 line
2.39.2
Quoted 10 lines · Fiona Ebner
There is no protection against two callers of
cbw_snapshot_read_lock()callingreqlist_init_req()with overlapping ranges, andreqlist_init_req()asserts that there are no conflicting requests.In particular, two
cbw_co_snapshot_block_status()callers can race, with the second callingreqlist_init_req()before the first one finishes and removes its conflicting request, leading to an assertion failure.Reproducer script [0] and backtrace [1] are attached below.
Understand. But seems in case of CBW read-lock, nothing bad in intersecting read requests?
reqlist is shared with backup, where we care to avoid intersecting requests in the list. What about just move the assertion to block_copy_task_create() ? And add comment somewhere that we support intersecting reads in frozen_read_reqs.
Quoted 60 lines
[0]:
Quoted 13 lines
#!/bin/bash -e
dd if=/dev/urandom of=/tmp/disk.raw bs=1M count=1024
./qemu-img create/tmp/fleecing.raw-f raw 1G
(
./qemu-system-x86_64 --qmp stdio \
--blockdev raw,node-name=node0,file.driver=file,file.filename=/tmp/disk.raw \
--blockdev raw,node-name=node1,file.driver=file,file.filename=/tmp/fleecing.raw \
<<EOF
{"execute": "qmp_capabilities"}
{"execute": "blockdev-add", "arguments": { "driver": "copy-before-write", "file": "node0", "target": "node1", "node-name": "node3" } } {"execute": "blockdev-add", "arguments": { "driver": "snapshot-access", "file": "node3", "node-name": "snap0" } } {"execute": "nbd-server-start", "arguments": {"addr": { "type": "unix", "data": { "path": "/tmp/nbd.socket" } } } } {"execute": "block-export-add", "arguments": {"id": "exp0", "node-name": "snap0", "type": "nbd", "name": "exp0"}}Quoted 8 lines
EOF
) &
sleep 5
while true; do
./qemu-nbd -d/dev/nbd0
./qemu-nbd -c/dev/nbd0nbd:unix:/tmp/nbd.socket:exportname=exp0 -f raw -r nbdinfo --map 'nbd+unix:///exp0?socket=/tmp/nbd.socket'
done[1]:
Quoted 5 lines
#5 0x000071e5f0088eb2 in __GI___assert_fail (...) at ./assert/assert.c:101 #6 0x0000615285438017 in reqlist_init_req (...) at ../block/reqlist.c:23 #7 0x00006152853e2d98 in cbw_snapshot_read_lock (...) at ../block/copy-before-write.c:237 #8 0x00006152853e3068 in cbw_co_snapshot_block_status (...) at ../block/copy-before-write.c:304 #9 0x00006152853f4d22 in bdrv_co_snapshot_block_status (...) at ../block/io.c:3726Quoted 10 lines
#10
0x000061528543a63einsnapshot_access_co_block_status(...) at../block/snapshot-access.c:48#110x00006152853f1a0ainbdrv_co_do_block_status(...) at../block/io.c:2474#120x00006152853f2016inbdrv_co_common_block_status_above(...) at../block/io.c:2652#130x00006152853f22cfinbdrv_co_block_status_above(...) at../block/io.c:2732#140x00006152853d9a86inblk_co_block_status_above(...) at../block/block-backend.c:1473#150x000061528538da6cinblockstatus_to_extents(...) at../nbd/server.c:2374#160x000061528538deb1innbd_co_send_block_status(...) at../nbd/server.c:2481#170x000061528538f424innbd_handle_request(...) at../nbd/server.c:2978
#180x000061528538f906innbd_trip(...) at../nbd/server.c:3121
#190x00006152855a7cafincoroutine_trampoline(...) at../util/coroutine-ucontext.c:175Signed-off-by Fiona Ebner <[email protected]>--- block/copy-before-write.c | 1 + 1 file changed, 1 insertion(+)block/copy-before-write.c +1
-0@@ -234,6 +234,7 @@ cbw_snapshot_read_lock(BlockDriverState *bs, int64_t offset, int64_t bytes, *req = (BlockReq ) {.offset =-1 , .bytes =-1 }; *file = s->target; }else { +reqlist_wait_all (&s->frozen_read_reqs, offset, bytes, &s->lock);reqlist_init_req (&s->frozen_read_reqs, req, offset, bytes); *file = bs->file; }
Signature · 2 lines
Best regards, Vladimir