Block layer patches
[PULL 09/11] qcow2: fix snapshot data corruption with discard-no-unref=on
In reply to Kevin WolfFrom: Andrey Drobyshev <[email protected]>
Whenever option discard-no-unref=on is enabled, we bypass refcount machinery and unconditionally punch hole in the data on 'discard' and 'write -z -u' paths. However, when this same cluster is also referenced by an internal snapshot, such operations lead to problems. The active L2 table is copied before it is changed, so the snapshot metadata stays correct, but the host range under it is punched out and the snapshot reads zeroes there afterwards. qemu-img check finds nothing wrong.
Fix this by guarding the 'keep_reference' flag by the presence of the QCOW_OFLAG_COPIED bit. I.e. only proceed with unconditional data punching if we own this cluster exclusively.
Message-ID: <[email protected]>
--- block/qcow2-cluster.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
block/qcow2-cluster.c +4 -2
@@ -1953,6 +1953,7 @@ discard_in_l2_slice(BlockDriverState *bs, uint64_t offset, uint64_t nb_clusters,QCow2ClusterType cluster_type =qcow2_get_cluster_type (bs, old_l2_entry);bool keep_reference = (cluster_type !=QCOW2_CLUSTER_COMPRESSED ) && + (old_l2_entry &QCOW_OFLAG_COPIED ) && !full_discard && (s->discard_no_unref && type ==QCOW2_DISCARD_REQUEST );
@@ -2097,8 +2098,9 @@ zero_in_l2_slice(BlockDriverState *bs, uint64_t offset,QCow2ClusterType type =qcow2_get_cluster_type (bs, old_l2_entry);bool unmap = (type ==QCOW2_CLUSTER_COMPRESSED ) || ((flags &BDRV_REQ_MAY_UNMAP ) &&qcow2_cluster_is_allocated (type)); -bool keep_reference = - (s->discard_no_unref && type !=QCOW2_CLUSTER_COMPRESSED ); +bool keep_reference = s->discard_no_unref && + type !=QCOW2_CLUSTER_COMPRESSED && + (old_l2_entry &QCOW_OFLAG_COPIED );uint64_t new_l2_entry = old_l2_entry;uint64_t new_l2_bitmap = old_l2_bitmap;
Signature · 1 line
2.56.0
[PULL 02/11] block/vmdk: Avoid assertion if image file has no extents
In reply to Kevin WolfFrom: Peter Maydell <[email protected]>
On a malformed image file which has no extents in it, we will open the file but then fall over on an assertion in vmdk_co_get_info():
$ cat bad.vmdk
# Disk DescriptorFile
version=1
CID=fffffffe
parentCID=ffffffff
createType="vmfs" $ qemu-img info -f vmdk /tmp/zz9
qemu-img: ../../block/vmdk.c:3104: int vmdk_co_get_info(BlockDriverState *, BlockDriverInfo *): Assertion `s->num_extents' failed.
Aborted (core dumped)(This was noted in passing in the report of #4571.)
Message-ID: <[email protected]>
--- block/vmdk.c | 6 ++++++ 1 file changed, 6 insertions(+)
block/vmdk.c +6 -0
@@ -1301,6 +1301,12 @@ vmdk_parse_extents(const char *desc, BlockDriverState *bs, QDict *options, extent->type =g_strdup (type); } +if (s->num_extents ==0 ) { +error_setg (errp,"Invalid file: no extent lines present" ); + ret = -EINVAL ; + goto out; + } + ret =0 ; goto out;
Signature · 1 line
2.56.0
[PULL 04/11] block/vmdk: Use larger types for byte counts in vmdk_read_extent()
In reply to Kevin WolfFrom: Peter Maydell <[email protected]>
In vmdk_read_extent() we use 'int' for cluster_bytes and buf_bytes. However, cluster_bytes is extent->cluster_sectors * 512 and buf_bytes is cluster_bytes * 2. The maximum value for extent->cluster_sectors (enforced in vmdk_add_extent()) is 0x20_0000, and so the worst case for buf_bytes is 0x8000_0000, which overflows a signed int.
Make the variable types here int64_t, which matches the type used by bdrv_co_pread()'s bytes argument and by extent->cluster_sectors.
The worst case thing that a malicious VMDK image could do is cause us to try to g_malloc() 0xffffffff80000000, which will cause QEMU to abort(), so this is a self-denial-of-service only, and so a hardening bug rather than a security issue.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3843
Message-ID: <[email protected]>
--- block/vmdk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/vmdk.c +1 -1
@@ -1940,7 +1940,7 @@ vmdk_read_extent(VmdkExtent *extent, int64_t cluster_offset, int64_t offset_in_cluster, QEMUIOVector *qiov, int bytes) { int ret; -int cluster_bytes, buf_bytes; +int64_t cluster_bytes, buf_bytes;uint8_t *cluster_buf, *compressed_data;uint8_t *uncomp_buf;uint32_t data_len;
Signature · 1 line
2.56.0
[PULL 10/11] iotests/290: add 'discard' and 'write -z -u' case with a snapshot
In reply to Kevin WolfFrom: Andrey Drobyshev <[email protected]>
Before the previous commit, issuing 'discard' and 'write -z -u' operations with discard-no-unref=on option enabled led to data corruption. Add a test to cover this case.
Message-ID: <[email protected]>
--- tests/qemu-iotests/290 | 16 ++++++++++++++++ tests/qemu-iotests/290.out | 5 +++++ 2 files changed, 21 insertions(+)
tests/qemu-iotests/290 +16 -0
@@ -128,6 +128,22 @@ $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map echo "# Output of qemu-img map for the image with kept reference" $QEMU_IMG map --output=json "$NOUNREF_IMG" | _filter_qemu_img_map +echo +echo "### Discard with 'discard-no-unref' on a cluster shared with a snapshot" +echo + +_make_test_img 128k +$QEMU_IO -c 'write -q -P 0xaa 0 128k' "$TEST_IMG" | _filter_qemu_io +$QEMU_IMG snapshot -c snap "$TEST_IMG" +QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT \ +$QEMU_IO -c 'discard -q 0 64k' -c 'write -q -z -u 64k 64k' --image-opts \ + "driver=$IMGFMT,file.filename=$TEST_IMG,discard-no-unref=on" \ + | _filter_qemu_io +$QEMU_IO -c 'read -q -P 0 0 128k' "$TEST_IMG" | _filter_qemu_io +$QEMU_IMG snapshot -a snap "$TEST_IMG" +$QEMU_IO -c 'read -q -P 0xaa 0 128k' "$TEST_IMG" | _filter_qemu_io +_check_test_img + # success, all done echo "*** done" rm -f $seq.full
tests/qemu-iotests/290.out +5 -0
@@ -86,4 +86,9 @@ Images are identical. # Output of qemu-img map for the image with kept reference [{ "start": 0, "length": 65536, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET}, { "start": 65536, "length": 65536, "depth": 0, "present": true, "zero": true, "data": false, "compressed": false, "offset": OFFSET}] + +### Discard with 'discard-no-unref' on a cluster shared with a snapshot + +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=131072 +No errors were found on the image. *** done
Signature · 1 line
2.56.0
[PULL 01/11] iotests: add --quiet arg to hide env variable dump
In reply to Kevin WolfFrom: Daniel P. Berrangé <[email protected]>
Every test run dumps a long list of environment variable settings. While this is often useful, if you are trying to reproduce a bug while repeatedly running a single test it can be quite noisy. Add a --quiet flag to 'check' which allows the env variable dump to be hidden. With this is only prints out the tests being run and the overall status on completion.
Message-ID: <[email protected]>
--- tests/qemu-iotests/testrunner.py | 8 +++++--- tests/qemu-iotests/check | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-)
tests/qemu-iotests/testrunner.py +5 -3
@@ -376,7 +376,8 @@ def run_test(self, test: str, sys.stdout.flush() return res - def run_tests(self, tests: List[str], jobs: int = 1) -> bool: + def run_tests(self, tests: List[str], jobs: int = 1, + quiet: bool = False) -> bool: n_run = 0 failed = [] notrun = []
@@ -384,9 +385,10 @@ def run_tests(self, tests: List[str], jobs: int = 1) -> bool: if self.tap: print('TAP version 13') - self.env.print_env('# ') + if not quiet: + self.env.print_env('# ') print('1..%d' % len(tests)) - else: + elif not quiet: self.env.print_env() test_field_width = max(len(os.path.basename(t)) for t in tests) + 2
tests/qemu-iotests/check +3 -1
@@ -46,6 +46,8 @@ def make_argparser() -> argparse.ArgumentParser: description="Test run options", formatter_class=argparse.ArgumentDefaultsHelpFormatter) + p.add_argument('-q', '--quiet', action='store_true', + help='reduce output verbosity to only test results') p.add_argument('-n', '--dry-run', action='store_true', help='show me, do not run tests') p.add_argument('-j', dest='jobs', type=int, default=1,
@@ -230,6 +232,6 @@ if __name__ == '__main__': with TestRunner(env, tap=args.tap, color=args.color) as tr: paths = [os.path.join(env.source_iotests, t) for t in tests] - ok = tr.run_tests(paths, args.jobs) + ok = tr.run_tests(paths, args.jobs, args.quiet) if not ok: sys.exit(1)
Signature · 1 line
2.56.0
[PULL 08/11] iotests/290: add test case to check 'discard-no-unref' option behavior
In reply to Kevin WolfFrom: Andrey Drobyshev <[email protected]>
We basically fill 2 images with identical data and perform discard operations with and without 'discard-no-unref' enabled. Then we check that images still read identically, that their disk usage is the same (i.e. fallocate(FALLOC_FL_PUNCH_HOLE|FALLOC_FL_KEEP_SIZE) is called for both) and that with the option enabled cluster is still marked as allocated in "qemu-img map" output. We also check that the option doesn't work with qcow2 v2 images.
Message-ID: <[email protected]>
--- tests/qemu-iotests/290 | 38 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/290.out | 28 ++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+)
tests/qemu-iotests/290 +38 -0
@@ -29,6 +29,7 @@ status=1 # failure is the default! _cleanup() { _cleanup_test_img + _rm_test_img "$TEST_IMG.nounref" } trap "_cleanup; exit \$status" 0 1 2 3 15
@@ -40,6 +41,7 @@ _supported_fmt qcow2 _supported_proto file fuse _supported_os Linux _unsupported_imgopts 'compat=0.10' refcount_bits data_file compression_type +_require_disk_usage echo echo "### Test 'qemu-io -c discard' on a QCOW2 image without a backing file"
@@ -90,6 +92,42 @@ for qcow2_compat in 0.10 1.1; do $QEMU_IMG map "$TEST_IMG" | _filter_testdir done +echo +echo "### Test 'qemu-io -c discard' with 'discard-no-unref' option enabled" +echo + +echo "# Check that qcow2 v2 images don't support 'discard-no-unref' option" +NOUNREF_IMG="$TEST_IMG.nounref" +TEST_IMG="$NOUNREF_IMG" _make_test_img -o "compat=0.10" 128k +# This should immediately fail with an error +$QEMU_IO -c 'reopen -o discard-no-unref=on' "$NOUNREF_IMG" | _filter_qemu_io + +echo "# Create two compat=1.1 images and fill them with identical data" +_make_test_img -o "compat=1.1" 128k +TEST_IMG="$NOUNREF_IMG" _make_test_img -o "compat=1.1" 128k +$QEMU_IO -c 'write -P 0xaa 0 128k' "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c 'write -P 0xaa 0 128k' "$NOUNREF_IMG" | _filter_qemu_io + +echo "# Enable 'discard-no-unref' in one of them, discard 2nd cluster in both" +$QEMU_IO -c 'discard 64k 64k' "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c 'reopen -o discard-no-unref=on' \ + -c 'discard 64k 64k' "$NOUNREF_IMG" | _filter_qemu_io + +echo "# Compare disk usage of the 2 images" +# Don't check the exact disk usage values but rather that they're equal +usage1=$(disk_usage "$TEST_IMG") +usage2=$(disk_usage "$NOUNREF_IMG") +echo "disk_usage($TEST_IMG) - disk_usage($NOUNREF_IMG) = $((usage1 - usage2))" \ + | _filter_testdir | _filter_imgfmt + +echo "# Check that images are still identical" +$QEMU_IMG compare "$TEST_IMG" "$NOUNREF_IMG" + +echo "# Output of qemu-img map for the image with dropped reference" +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map +echo "# Output of qemu-img map for the image with kept reference" +$QEMU_IMG map --output=json "$NOUNREF_IMG" | _filter_qemu_img_map + # success, all done echo "*** done" rm -f $seq.full
tests/qemu-iotests/290.out +28 -0
@@ -58,4 +58,32 @@ read 131072/131072 bytes at offset 0 128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) # Output of qemu-img map Offset Length Mapped to File + +### Test 'qemu-io -c discard' with 'discard-no-unref' option enabled + +# Check that qcow2 v2 images don't support 'discard-no-unref' option +Formatting 'TEST_DIR/t.IMGFMT.nounref', fmt=IMGFMT size=131072 +qemu-io: discard-no-unref is only supported since qcow2 version 3 +# Create two compat=1.1 images and fill them with identical data +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=131072 +Formatting 'TEST_DIR/t.IMGFMT.nounref', fmt=IMGFMT size=131072 +wrote 131072/131072 bytes at offset 0 +128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 131072/131072 bytes at offset 0 +128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +# Enable 'discard-no-unref' in one of them, discard 2nd cluster in both +discard 65536/65536 bytes at offset 65536 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +discard 65536/65536 bytes at offset 65536 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +# Compare disk usage of the 2 images +disk_usage(TEST_DIR/t.IMGFMT) - disk_usage(TEST_DIR/t.IMGFMT.nounref) = 0 +# Check that images are still identical +Images are identical. +# Output of qemu-img map for the image with dropped reference +[{ "start": 0, "length": 65536, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET}, +{ "start": 65536, "length": 65536, "depth": 0, "present": true, "zero": true, "data": false, "compressed": false}] +# Output of qemu-img map for the image with kept reference +[{ "start": 0, "length": 65536, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET}, +{ "start": 65536, "length": 65536, "depth": 0, "present": true, "zero": true, "data": false, "compressed": false, "offset": OFFSET}] *** done
Signature · 1 line
2.56.0
[PULL 11/11] block/vhdx: Prevent out-of-bounds BAT accesses with malicious vhdx files
In reply to Kevin WolfFrom: Thomas Huth <[email protected]>
virtual_disk_size is read directly from a VHDX image's metadata region and never checked for sane sizes. The 64 TiB limit (VHDX_MAX_IMAGE_SIZE) is only enforced in vhdx_co_create(), so it limits images QEMU creates but never images QEMU opens.
Without the bound, vhdx_calc_bat_entries() computes the block count into a uint32_t, so a huge image size gets truncated and the BAT is undersized relative to total_sectors. vhdx_block_translate() then converts sector numbers into BAT indices with no bounds check, allowing out-of-bounds access on the BAT array from both the read and write paths.
To fix the problem, add a VHDX_MAX_IMAGE_SIZE check to vhdx_parse_metadata() so images opened for reading are subject to the same limit as images created by QEMU.
With this limit, the calculation in vhdx_calc_bat_entries() cannot get truncated anymore (block_size is at least 1 MiB):
VHDX_MAX_IMAGE_SIZE / block_size = 64 TiB / 1 MiB = 64 MiB
... and 64 MiB fit nicely into 32 bits.
To be really on the safe side, let's also add an assertion in vhdx_block_translate() to catch accesses that exceeds the allocated entry count.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4470
Reported-by: Mayank Jangid (OpenSec)
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4487
Reported-by: Ken Hsu, Royce Lu, and Bo Qu of Palo Alto Networks
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4638
Reported-by: Thai Duong (Calif.io)
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4733
Message-ID: <[email protected]>
--- block/vhdx.c | 6 ++++++ 1 file changed, 6 insertions(+)
block/vhdx.c +6 -0
@@ -815,6 +815,11 @@ vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s) } s->virtual_disk_size =le64_to_cpu (s->virtual_disk_size); +if (s->virtual_disk_size >VHDX_MAX_IMAGE_SIZE ) { + ret = -EFBIG ; + goto exit; + } + s->logical_sector_size =le32_to_cpu (s->logical_sector_size); s->physical_sector_size =le32_to_cpu (s->physical_sector_size);
@@ -1149,6 +1154,7 @@ static void vhdx_block_translate(BDRVVHDXState *s, int64_t sector_num, sinfo->bytes_avail = sinfo->sectors_avail << s->logical_sector_size_bits; +assert (sinfo->bat_idx < s->bat_entries); sinfo->file_offset = s->bat[sinfo->bat_idx] &VHDX_BAT_FILE_OFF_MASK ; sinfo->block_offset = block_offset << s->logical_sector_size_bits;
Signature · 1 line
2.56.0
[PULL 05/11] block/vmdk: Reject a zero cluster_sectors parameter
In reply to Kevin WolfFrom: Peter Maydell <[email protected]>
In vmdk_add_extent() we reject image files with an excessively large cluster_sectors parameter, but have no lower bound. In particular, if the cluster_sectors is 0 then we will set l1_entry_sectors also to 0, and later crash with a SIGFPE for division by zero.
Reject a zero cluster_sectors value, unless this is a flat extent (in which case cluster_sectors isn't relevant and the callsite always passes us zero).
The worst case here is a self-denial-of-service with a QEMU crash, so this is a hardening bug.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4017
Message-ID: <[email protected]>
--- block/vmdk.c | 5 +++++ 1 file changed, 5 insertions(+)
block/vmdk.c +5 -0
@@ -552,6 +552,11 @@ static int vmdk_add_extent(BlockDriverState *bs,BDRVVmdkState *s = bs->opaque;int64_t nb_sectors; +if (!flat && cluster_sectors ==0 ) { +error_setg (errp,"Invalid zero granularity, image may be corrupt" ); +return -EINVAL ; + } +if (cluster_sectors >0x200000 ) {/* 0x200000 * 512Bytes = 1GB for one cluster is unrealistic */ error_setg (errp,"Invalid granularity, image may be corrupt" );
Signature · 1 line
2.56.0
[PULL 03/11] block/vmdk: Avoid reading off the end of descriptor memory
In reply to Kevin WolfFrom: Peter Maydell <[email protected]>
In vmdk_parent_open() and vmdk_read_cid(), we read DESC_SIZE bytes from the image file into a malloc'd buffer, and then look through it for a keyword using strstr(). If found, we skip past the keyword and attempt to parse a value from the next part of the buffer. However, we failed to check whether the end of the keyword is right at the end of the buffer, and so a malicious image can cause us to read off the end when parsing the value part.
Check for this condition before attempting to parse the value.
The worst case here is that the image causes us to read some junk from the heap into the BlockDriverState backing_file and auto_backing_file fields; the image could control those anyway, and it's unlikely that this heap data could e.g. be leaked to the guest.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4571
Message-ID: <[email protected]>
--- block/vmdk.c | 8 ++++++++ 1 file changed, 8 insertions(+)
block/vmdk.c +8 -0
@@ -337,6 +337,10 @@ vmdk_read_cid(BlockDriverState *bs, int parent, uint32_t *pcid) goto out; } p_name += cid_str_size; +if (p_name >= desc +DESC_SIZE ) { + ret = -EINVAL ; + goto out; + }if (sscanf (p_name,"%" SCNx32, &cid) !=1 ) { ret = -EINVAL ; goto out;
@@ -508,6 +512,10 @@ static int GRAPH_RDLOCK vmdk_parent_open(BlockDriverState *bs)char *end_name; p_name +=sizeof ("parentFileNameHint" ) +1 ; +if (p_name >= desc +DESC_SIZE +1 ) { + ret = -EINVAL ; + goto out; + } end_name =strchr (p_name,'\"' );if (end_name ==NULL ) { ret = -EINVAL ;
Signature · 1 line
2.56.0
[PULL 07/11] block: add missing coroutine_fn annotations
In reply to Kevin WolfFrom: Marc-André Lureau <[email protected]>
The functions call coroutine functions or are called by coroutine.
Add an assert() in qcow2_do_close() code path which calls a no_coroutine_fn bdrv_graph_wrlock_drained().
Add an assert() in qcow2_update_options_commit() in the coroutine path.
Message-ID: <[email protected]>
--- include/block/blockjob_int.h | 2 +- block/crypto.c | 13 +++++++------ block/io.c | 8 +++++--- block/qcow2.c | 9 ++++++--- blockjob.c | 3 ++- 5 files changed, 21 insertions(+), 14 deletions(-)
include/block/blockjob_int.h +1 -1
@@ -150,7 +150,7 @@ void block_job_ratelimit_processed_bytes(BlockJob *job, uint64_t n);* Put the job to sleep (assuming that it wasn't canceled) to throttle it to the * right speed according to its rate limiting. */ -void block_job_ratelimit_sleep (BlockJob *job); +void coroutine_fn block_job_ratelimit_sleep(BlockJob *job);/** * block_job_error_action:
block/crypto.c +7 -6
@@ -56,12 +56,13 @@ static int block_crypto_probe_generic(QCryptoBlockFormat format, } -static int block_crypto_read_func (QCryptoBlock *block, -size_t offset, -uint8_t *buf, -size_t buflen, -void *opaque, -Error **errp) +static int coroutine_mixed_fn +block_crypto_read_func (QCryptoBlock *block, +size_t offset, +uint8_t *buf, +size_t buflen, +void *opaque, +Error **errp) {BlockDriverState *bs = opaque;BlockCrypto *crypto = bs->opaque;
block/io.c +5 -3
@@ -354,8 +354,9 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,assert (data.done); } -static void bdrv_do_drained_begin (BlockDriverState *bs,BdrvChild *parent, -bool poll) +static void coroutine_mixed_fn +bdrv_do_drained_begin (BlockDriverState *bs,BdrvChild *parent, +bool poll) {IO_OR_GS_CODE ();
@@ -405,7 +406,8 @@ bdrv_drained_begin(BlockDriverState *bs)* This function does not poll, nor must any of its recursively called * functions. */ -static void bdrv_do_drained_end (BlockDriverState *bs,BdrvChild *parent) +static void coroutine_mixed_fn +bdrv_do_drained_end (BlockDriverState *bs,BdrvChild *parent) {IO_OR_GS_CODE ();
block/qcow2.c +6 -3
@@ -1287,9 +1287,10 @@ fail: }/* s_locked specifies whether s->lock is held or not */ -static void qcow2_update_options_commit (BlockDriverState *bs, -Qcow2ReopenState *r, -bool s_locked) +static coroutine_mixed_fn void +qcow2_update_options_commit (BlockDriverState *bs, +Qcow2ReopenState *r, +bool s_locked) {BDRVQcow2State *s = bs->opaque;int i;
@@ -1299,6 +1300,7 @@ static void qcow2_update_options_commit(BlockDriverState *bs,* table caches */ if (s_locked) { +assert (qemu_in_coroutine ());cache_clean_timer_co_locked_del_and_wait (bs); }else {cache_clean_timer_del_and_wait (bs);
@@ -2919,6 +2921,7 @@ qcow2_do_close(BlockDriverState *bs, bool close_data_file)g_free (s->image_backing_format);if (close_data_file &&has_data_file (bs)) { +assert (!qemu_in_coroutine ());GLOBAL_STATE_CODE ();bdrv_graph_rdunlock_main_loop ();bdrv_graph_wrlock_drained ();
blockjob.c +2 -1
@@ -338,7 +338,8 @@ void block_job_ratelimit_processed_bytes(BlockJob *job, uint64_t n)ratelimit_calculate_delay (&job->limit, n); } -void block_job_ratelimit_sleep (BlockJob *job) +void coroutine_fn +block_job_ratelimit_sleep (BlockJob *job) {uint64_t delay_ns;
Signature · 1 line
2.56.0
[PULL 06/11] block/vmdk: Avoid overflowing multiplication in vmdk_open_vmdk4()
In reply to Kevin WolfFrom: Peter Maydell <[email protected]>
In vmdk_open_vmdk4() we set the uint32_t l1_entry_sectors with:
l1_entry_sectors = le32_to_cpu(header.num_gtes_per_gt)
* le64_to_cpu(header.granularity);
We have checked that num_gtes_per_gt is at most 512, but the header.granularity has not been checked at this point, and so the multiply can overflow the 32-bit variable. This overflow is harmless beacuse we're about to call vmdk_add_extent(), which will fail if the header.granularity (cluster_sectors) is more than 0x20_0000, but it's a potential trap for the future if code that relies on the l1_entry_sectors value gets added between where we set it and where we make that check.
Check for overlarge granularity at the point of multiplication so it's clear we can't overflow.
Cc: [email protected]
Reported-by: Tristan <https://gitlab.com/TristanInSec>
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4029
Message-ID: <[email protected]>
--- block/vmdk.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
block/vmdk.c +4 -1
@@ -1052,7 +1052,10 @@ vmdk_open_vmdk4(BlockDriverState *bs, BdrvChild *file, int flags,error_setg (errp,"L2 table size too big" );return -EINVAL ; } - +if (le64_to_cpu (header.granularity) >0x200000 ) { +error_setg (errp,"Invalid granularity, image may be corrupt" ); +return -EFBIG ; + } l1_entry_sectors =le32_to_cpu (header.num_gtes_per_gt) *le64_to_cpu (header.granularity);if (l1_entry_sectors ==0 ) {
Signature · 1 line
2.56.0
The following changes since commit 71f25c75417d31c214ba2cd26b273c114fc99987:
Merge tag 'pbouvier/pr/multi_target-20261106' of https://gitlab.com/p-b-o/qemu into staging (2026-11-06 12:28:21 -0800)
are available in the Git repository at:
https://repo.or.cz/qemu/kevin.git tags/for-upstream
for you to fetch changes up to 67198583a1ef3432c784f2802c5cda914bc14ca8:
block/vhdx: Prevent out-of-bounds BAT accesses with malicious vhdx files (2026-11-09 16:32:35 +0100)
----------------------------------------------------------------
Block layer patches
- qcow2: fix snapshot data corruption with discard-no-unref=on
- vmdk: Fix various bugs in handling malicious image files
- vhdx: Prevent out-of-bounds BAT accesses with malicious vhdx files
- iotests: add --quiet arg to hide env variable dump
----------------------------------------------------------------
Andrey Drobyshev (3):
iotests/290: add test case to check 'discard-no-unref' option behavior
qcow2: fix snapshot data corruption with discard-no-unref=on iotests/290: add 'discard' and 'write -z -u' case with a snapshot
Daniel P. Berrangé (1):
iotests: add --quiet arg to hide env variable dump
Marc-André Lureau (1):
block: add missing coroutine_fn annotations
Peter Maydell (5):
block/vmdk: Avoid assertion if image file has no extents block/vmdk: Avoid reading off the end of descriptor memory block/vmdk: Use larger types for byte counts in vmdk_read_extent() block/vmdk: Reject a zero cluster_sectors parameter block/vmdk: Avoid overflowing multiplication in vmdk_open_vmdk4()
Thomas Huth (1):
block/vhdx: Prevent out-of-bounds BAT accesses with malicious vhdx files
include/block/blockjob_int.h | 2 +- block/crypto.c | 13 +++++----- block/io.c | 8 +++--- block/qcow2-cluster.c | 6 +++-- block/qcow2.c | 9 ++++--- block/vhdx.c | 6 +++++ block/vmdk.c | 26 +++++++++++++++++-- blockjob.c | 3 ++- tests/qemu-iotests/testrunner.py | 8 +++--- tests/qemu-iotests/290 | 54 ++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/290.out | 33 ++++++++++++++++++++++++ tests/qemu-iotests/check | 4 ++- 12 files changed, 150 insertions(+), 22 deletions(-)
Richard Henderson
AppliedQuoted 12 lines · Kevin Wolf
The following changes since commit
71f25c75417d31c214ba2cd26b273c114fc99987:Merge tag 'pbouvier/pr/multi_target-20261106' ofhttps://gitlab.com/p-b-o/qemu into staging (2026-11-06 12:28:21 -0800)are available in the Git repository at:
https://repo.or.cz/qemu/kevin.git tags/for-upstream
for you to fetch changes up to
67198583a1ef3432c784f2802c5cda914bc14ca8:block/vhdx: Prevent out-of-bounds BAT accesses with malicious vhdx files (2026-11-09 16:32:35 +0100)
Quoted 7 lines
----------------------------------------------------------------
Block layer patches- qcow2: fix snapshot data corruption with discard-no-unref=on
- vmdk: Fix various bugs in handling malicious image files
- vhdx: Prevent out-of-bounds BAT accesses with malicious vhdx files
- iotests: add --quiet arg to hide env variable dump
Applied, thanks.
r~