Block layer patches
Subsystems (2)
The following changes since commit 97c88c61d45dee6e1f9bc160a338048189846d28:
Merge tag 'docs-security-devices-pull-request' of https://gitlab.com/berrange/qemu into staging (2026-11-16 15:48:48 -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 4f5c09c6228f317eab3144ecc27e8b13b3526128:
block: notify only the replaced child in bdrv_replace_child_bs() (2026-11-17 11:46:13 +0100)
----------------------------------------------------------------
Block layer patches
- vhdx, bochs: Image validation fixes
- Fix the size change notification in bdrv_replace_child_bs()
- iotests: Minor fixes to deal more correctly with exotic environments
----------------------------------------------------------------
Daniel P. Berrangé (1):
iotests: better heuristics to find I/O tests build/source dirs
Denis V. Lunev (3):
block: read the old child length after draining in bdrv_replace_child_bs()
block: add bdrv_child_notify_resize() to notify a single parent
block: notify only the replaced child in bdrv_replace_child_bs()
John Snow (1):
iotests: fix false positive on running-outside-venv warning
Thomas Huth (2):
block/vhdx-log: Improve sanity checks to avoid OOB accesses with bad images block/vhdx: Add alignment checks for region tables
malike (1):
block/bochs: validate bitmap size and compute extent_blocks after validation
include/block/block_int-io.h | 8 ++++++- block.c | 7 +++--- block/bochs.c | 9 +++++++- block/io.c | 14 +++++++++--- block/vhdx-log.c | 6 ++++- block/vhdx.c | 10 +++++++++ tests/qemu-iotests/testenv.py | 8 +++---- meson.build | 1 + tests/qemu-iotests/check | 52 +++++++++++++++++++++++++++++++------------ 9 files changed, 88 insertions(+), 27 deletions(-)
[PULL 6/8] block: read the old child length after draining in bdrv_replace_child_bs()
From: "Denis V. Lunev" <[email protected]>
bdrv_drained_begin() runs nested event loops, and old_bs can be resized from there by something other than the BlockBackend being switched: an export truncating it, or a block job completing. old_len read before the drain is then stale, and comparing it with new_len sends a notification the parent does not need or skips one it does.
Read it once both nodes are drained, so that the read, the comparison and the notification see the same sizes. A resize which completes in the drain notifies the parents of old_bs, @child included, on its own.
Message-ID: <[email protected]>
--- block.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
block.c +3 -2
@@ -5566,11 +5566,12 @@ int bdrv_replace_child_bs(BdrvChild *child, BlockDriverState *new_bs,GLOBAL_STATE_CODE (); - old_len =bdrv_getlength (old_bs); -bdrv_ref (old_bs);bdrv_drained_begin (old_bs);bdrv_drained_begin (new_bs); + + old_len =bdrv_getlength (old_bs); +bdrv_graph_wrlock ();bdrv_replace_child_tran (child, new_bs, tran);
Signature · 1 line
2.56.1
[PULL 7/8] block: add bdrv_child_notify_resize() to notify a single parent
In reply to Kevin WolfFrom: "Denis V. Lunev" <[email protected]>
bdrv_co_parent_cb_resize() calls the resize hook of every parent of a node. bdrv_replace_child_bs() needs to call it for one BdrvChild, and from outside a coroutine.
Move the call into bdrv_co_child_notify_resize(), make the loop use it, and add a co_wrapper for callers outside a coroutine.
No functional change.
Message-ID: <[email protected]>
--- include/block/block_int-io.h | 9 +++++++++ block/io.c | 14 +++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-)
include/block/block_int-io.h +9 -0
@@ -197,6 +197,15 @@ void bdrv_bsc_fill(BlockDriverState *bs, int64_t offset, int64_t bytes); void coroutine_fn GRAPH_RDLOCKbdrv_co_parent_cb_resize (BlockDriverState *bs); +/* +* Notify the parent behind @c that the size of its child changed. +*/ +void coroutine_fn GRAPH_RDLOCK +bdrv_co_child_notify_resize (BdrvChild *c); + +void co_wrapper_bdrv_rdlock +bdrv_child_notify_resize (BdrvChild *c); + void co_wrapper_bdrv_rdlockbdrv_parent_cb_resize (BlockDriverState *bs);
block/io.c +11 -3
@@ -3636,6 +3636,16 @@ int coroutine_fn bdrv_co_copy_range(BdrvChild *src, int64_t src_offset, bytes, read_flags, write_flags); } +void coroutine_fn bdrv_co_child_notify_resize(BdrvChild *c) +{ +IO_CODE (); +assert_bdrv_graph_readable (); + +if (c->klass->resize) { + c->klass->resize (c); + } +} + void coroutine_fn bdrv_co_parent_cb_resize(BlockDriverState *bs) {BdrvChild *c;
@@ -3644,9 +3654,7 @@ void coroutine_fn bdrv_co_parent_cb_resize(BlockDriverState *bs)assert_bdrv_graph_readable (); QLIST_FOREACH(c, &bs->parents, next_parent) { -if (c->klass->resize) { - c->klass->resize (c); - } +bdrv_co_child_notify_resize (c); } }
Signature · 1 line
2.56.1
[PULL 8/8] block: notify only the replaced child in bdrv_replace_child_bs()
In reply to Kevin WolfFrom: "Denis V. Lunev" <[email protected]>
bdrv_replace_child_bs() compares the sizes of the old and the new node to decide whether @child has to be told, and then notifies every parent of new_bs. The other parents already had that node and its size, so they get a resize event for nothing: a scsi-hd sharing the new node reports CAPACITY DATA HAS CHANGED to its guest although the capacity is the same.
Notify @child alone. bdrv_parent_cb_resize() has no user left, so drop it.
Message-ID: <[email protected]>
--- include/block/block_int-io.h | 3 --- block.c | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-)
include/block/block_int-io.h +0 -3
@@ -206,7 +206,4 @@ bdrv_co_child_notify_resize(BdrvChild *c); void co_wrapper_bdrv_rdlockbdrv_child_notify_resize (BdrvChild *c); -void co_wrapper_bdrv_rdlock -bdrv_parent_cb_resize (BlockDriverState *bs); -#endif /* BLOCK_INT_IO_H */
block.c +1 -1
@@ -5590,7 +5590,7 @@ int bdrv_replace_child_bs(BdrvChild *child, BlockDriverState *new_bs,int64_t new_len =bdrv_getlength (new_bs);if (new_len >=0 && new_len != old_len) { -bdrv_parent_cb_resize (new_bs); +bdrv_child_notify_resize (child); } }
Signature · 1 line
2.56.1
[PULL 4/8] iotests: fix false positive on running-outside-venv warning
In reply to Kevin WolfFrom: John Snow <[email protected]>
Currently, iotests checks to see if you are running with the "correct" python interpreter by checking string equivalence between your current python and the configure-time venv python.
Depending on exactly *how* you launch or configure your python, however, this warning may produce false positives because it treats "python" as different from "python3" as different from e.g. "python3.12", even though they are all actually the same exact interpreter.
This patch fixes this by comparing only the parent directories; we will now be happy with any interpreter so long as it is located within build/pyvenv/bin/.
Note that we cannot fix this by resolving symlinks, as python venv binaries are often (but not always) just symlinks to /usr/bin/<etc>, and full resolution would produce even more false negatives.
Message-ID: <[email protected]>
--- tests/qemu-iotests/testenv.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tests/qemu-iotests/testenv.py +4 -4
@@ -86,7 +86,7 @@ def prepare_subprocess(self, args: List[str]) -> Dict[str, str]: with open(args[0], encoding="utf-8") as f: try: if f.readline().rstrip() == '#!/usr/bin/env python3': - args.insert(0, self.python) + args.insert(0, str(self.python)) except UnicodeDecodeError: # binary test? for future. pass
@@ -141,14 +141,14 @@ def init_binaries(self) -> None: PYTHON (for bash tests) QEMU_PROG, QEMU_IMG_PROG, QEMU_IO_PROG, QEMU_NBD_PROG, QSD_PROG """ - self.python = str(Path(sys.executable).absolute()) + self.python = Path(sys.executable).absolute() # QEMU configure-time venv python executable venv_python = Path( os.path.join(self.build_root, "pyvenv", "bin", "python3") ).absolute() - if self.python != str(venv_python): + if str(self.python.parent) != str(venv_python.parent): runpath = os.path.join(self.build_root, "run") cmd = ' '.join(shlex.quote(x) for x in sys.argv) print(
@@ -163,7 +163,7 @@ def init_binaries(self) -> None: f"\t{runpath} {cmd}\n", file=sys.stderr ) - self.python = str(venv_python) + self.python = venv_python def root(*names: str) -> str: return os.path.join(self.build_root, *names)
Signature · 1 line
2.56.1
[PULL 5/8] block/vhdx: Add alignment checks for region tables
In reply to Kevin WolfFrom: Thomas Huth <[email protected]>
According to the VHDX specification:
"The FileOffset and Length fields specify the 64-bit byte offset and 32-bit
byte length of the object within the file. The values must be a multiple of 1 MB, and FileOffset must be at least 1 MB."
Thus let's add a sanity check to avoid that bad things could happen later.
Message-ID: <[email protected]>
--- block/vhdx.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
block/vhdx.c +10 -0
@@ -566,6 +566,16 @@ vhdx_open_region_tables(BlockDriverState *bs, BDRVVHDXState *s)vhdx_region_entry_le_import (&rt_entry); +/* +* According to the VHDX spec, offset and length must be multiple +* of 1 MiB and offset must be at least 1 MiB. +*/ +if (!QEMU_IS_ALIGNED (rt_entry.file_offset, MiB) || + !QEMU_IS_ALIGNED (rt_entry.length, MiB) || !rt_entry.file_offset) { + ret = -EINVAL ; + goto fail; + } +/* check for region overlap between these entries, and any * other memory regions in the file */ ret =vhdx_region_check (s, rt_entry.file_offset, rt_entry.length);
Signature · 1 line
2.56.1
[PULL 1/8] block/bochs: validate bitmap size and compute extent_blocks after validation
In reply to Kevin WolfFrom: malike <[email protected]>
bochs_open() computes bitmap_blocks using the formula
"1 + (le32_to_cpu(bochs.bitmap) - 1) / 512". le32_to_cpu() returns uint32_t, so when bochs.bitmap is zero the subtraction wraps to UINT32_MAX (0xFFFFFFFF) in unsigned arithmetic, yielding bitmap_blocks = 8388608 instead of 1.
The bitmap field is read directly from the on-disk image header and was never validated. The overflowed bitmap_blocks propagates into seek_to_sector()'s bitmap_offset calculation, causing reads to target wrong offsets and return I/O errors or incorrect data.
Add an explicit zero check for bochs.bitmap before the formula.
Also move the extent_blocks calculation to after the existing extent_size validation. The same "1 + (x - 1) / 512" pattern applies to extent, but extent==0 is already caught by the "extent_size < BDRV_SECTOR_SIZE" check; the calculation is moved after that check for clarity and robustness, and uses the already-validated s->extent_size instead of re-reading the header field.
Message-ID: <[email protected]>
--- block/bochs.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
block/bochs.c +8 -1
@@ -167,8 +167,13 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, s->data_offset =le32_to_cpu (bochs.header) + (s->catalog_size *4 ); +if (le32_to_cpu (bochs.bitmap) ==0 ) { +error_setg (errp,"Bitmap size must not be zero" ); + ret = -EINVAL ; + goto fail; + } + s->bitmap_blocks =1 + (le32_to_cpu (bochs.bitmap) -1 ) /512 ; - s->extent_blocks =1 + (le32_to_cpu (bochs.extent) -1 ) /512 ; s->extent_size =le32_to_cpu (bochs.extent);if (s->extent_size <BDRV_SECTOR_SIZE ) {
@@ -188,6 +193,8 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } + s->extent_blocks =1 + (s->extent_size -1 ) /512 ; +if (s->catalog_size <DIV_ROUND_UP (bs->total_sectors, s->extent_size /BDRV_SECTOR_SIZE )) {
Signature · 1 line
2.56.1
[PULL 2/8] iotests: better heuristics to find I/O tests build/source dirs
In reply to Kevin WolfFrom: Daniel P. Berrangé <[email protected]>
Currently the I/O tests cannot be run if executing directly from the source directory, even when wrapped by the 'run' script, due to inadequate heuristics to guess the directories.
If using the 'run' script, meson can tell us exactly where the top level build and source directories are, so we don't need to guess. Just read MESON_BUILD_ROOT and MESON_SOURCE_ROOT env variables if present.
If not using the 'run' script, we can do a bit better at guessing the path from the 'check' filename. Always resolve from sys.argv[0], even when it is not a symlink, instead of falling back to 'cwd()' which doesn't work since we stopped having in-tree builds. If invoked directly from the source tree, guess that the build root is the default 'build' name which often works.
With this change the following all work:
1. From root of build dir, with run script
cd build
./run tests/qemu-iotests/check 5
2. From root of build dir, without run script
cd build
tests/qemu-iotests/check 5
3. From I/O tests subdir of build dir, with run script
cd build/tests/qemu-iotests
../../run ./check 5
4. From I/O tests subdir of build dir, without run script
cd build/tests/qemu-iotests
./check 5
5. From root of source dir, with run script
./build/run tests/qemu-iotests/check 5
6. From root of source dir, without run script
tests/qemu-iotests/check 5
7. From I/O tests subdir of source dir, with run script
cd tests/qemu-iotests
../../build/run ./check 5
8. From I/O tests subdir of source dir, without run script
cd tests/qemu-iotests
./check 5
Before this commit, items 5-8 would always fail. Items 6 and 8 will not work if using a build directory with a name other than the default 'build'. For those scenarios use one of the other 6 possible variants.
Message-ID: <[email protected]>
--- meson.build | 1 + tests/qemu-iotests/check | 52 +++++++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 14 deletions(-)
meson.build +1 -0
@@ -3502,6 +3502,7 @@ genh += config_host_h devenv = environment() devenv.set('MESON_BUILD_ROOT', meson.project_build_root()) +devenv.set('MESON_SOURCE_ROOT', meson.project_source_root()) devenv.set('VIRTUAL_ENV', meson.project_build_root() / 'pyvenv') devenv.prepend('PATH', meson.project_build_root() / 'pyvenv'/ 'bin') devenv.prepend('PYTHONPATH', meson.current_source_dir() / 'tests' / 'functional')
tests/qemu-iotests/check +38 -14
67 lines not on this page · raw message
Signature · 1 line
2.56.1
[PULL 3/8] block/vhdx-log: Improve sanity checks to avoid OOB accesses with bad images
In reply to Kevin WolfFrom: Thomas Huth <[email protected]>
The multiplication "hdr->descriptor_count * sizeof(VHDXLogDescriptor)" in vhdx_log_hdr_is_valid() can overflow on 32-bit systems, so this function could mark bad images as valid when the truncated result is smaller than hdr->entry_length. Switch to a division on the right hand side instead to avoid the overflow problems.
The second problem is in vhdx_log_read_desc(): desc_sectors is a 32-bit value, thus the multiplication "desc_sectors * VHDX_LOG_SECTOR_SIZE" is also done with 32 bit arithmetics, and the result is used as "size_t" parameter for qemu_try_blockalign(), i.e. the parameter here is also only 32 bits on 32-bit systems. Let's add a sanity check here to avoid the overflow problem that could lead to trouble later.
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3860
Message-ID: <[email protected]>
--- block/vhdx-log.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
block/vhdx-log.c +5 -1
@@ -246,7 +246,7 @@ static bool vhdx_log_hdr_is_valid(VHDXLogEntries *log, VHDXLogEntryHeader *hdr, goto exit; } -if (hdr->descriptor_count *sizeof (VHDXLogDescriptor) > hdr->entry_length) { +if (hdr->descriptor_count > hdr->entry_length /sizeof (VHDXLogDescriptor)) { goto exit; }
@@ -360,6 +360,10 @@ vhdx_log_read_desc(BlockDriverState *bs, BDRVVHDXState *s, VHDXLogEntries *log, } desc_sectors =vhdx_compute_desc_sectors (hdr.descriptor_count); +if (desc_sectors >UINT32_MAX /VHDX_LOG_SECTOR_SIZE ) { + ret = -EINVAL ; + goto exit; + } desc_entries =qemu_try_blockalign (bs->file->bs, desc_sectors *VHDX_LOG_SECTOR_SIZE );if (desc_entries ==NULL ) {
Signature · 1 line
2.56.1
Re: [PULL 2/8] iotests: better heuristics to find I/O tests build/source dirs
In reply to Kevin WolfQuoted 64 lines · Kevin Wolf
From: Daniel P. Berrangé<[email protected]>
Currently the I/O tests cannot be run if executing directly from the source directory, even when wrapped by the 'run' script, due to inadequate heuristics to guess the directories.
If using the 'run' script, meson can tell us exactly where the top level build and source directories are, so we don't need to guess. Just read
MESON_BUILD_ROOTandMESON_SOURCE_ROOTenv variables if present.If not using the 'run' script, we can do a bit better at guessing the path from the 'check' filename. Always resolve from sys.argv[0], even when it is not a symlink, instead of falling back to '
cwd()' which doesn't work since we stopped having in-tree builds. If invoked directly from the source tree, guess that the build root is the default 'build' name which often works.With this change the following all work:
1. From root of build dir, with run script
cd build
./run tests/qemu-iotests/check 52. From root of build dir, without run script
cd build
tests/qemu-iotests/check 53. From I/O tests subdir of build dir, with run script
cd build/tests/qemu-iotests ../../run ./check 54. From I/O tests subdir of build dir, without run script
cd build/tests/qemu-iotests ./check 55. From root of source dir, with run script
./build/run tests/qemu-iotests/check 5
6. From root of source dir, without run script
tests/qemu-iotests/check 5
7. From I/O tests subdir of source dir, with run script
cd tests/qemu-iotests ../../build/run ./check 58. From I/O tests subdir of source dir, without run script
cd tests/qemu-iotests ./check 5Before this commit, items 5-8 would always fail. Items 6 and 8 will not work if using a build directory with a name other than the default 'build'. For those scenarios use one of the other 6 possible variants.
Quoted 8 lines
Signed-off-by Daniel P. Berrangé<[email protected]>Message-ID:<[email protected]>
Reviewed-by Kevin Wolf<[email protected]>Signed-off-by Kevin Wolf<[email protected]>--- meson.build | 1 + tests/qemu-iotests/check | 52 +++++++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 14 deletions(-)
Fails all of the block tests. E.g.
https://gitlab.com/qemu-project/qemu/-/jobs/18118947590#L135
Review
Quoted 6 lines
=== pylint ===
(quoted diff) +5
-0+************* Module check +check:44:12: W0719: Raising too general exception: Exception (broad-exception-raised) +check:44:28: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation) +check:61:12: W0719: Raising too general exception: Exception (broad-exception-raised) +check:61:28: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
r~
Re: [PULL 2/8] iotests: better heuristics to find I/O tests build/source dirs
Am 17.11.2026 um 21:06 hat Richard Henderson geschrieben:
Quoted 76 lines · Kevin Wolf
Quoted 64 lines
From: Daniel P. Berrangé<[email protected]>
Currently the I/O tests cannot be run if executing directly from the source directory, even when wrapped by the 'run' script, due to inadequate heuristics to guess the directories.
If using the 'run' script, meson can tell us exactly where the top level build and source directories are, so we don't need to guess. Just read
MESON_BUILD_ROOTandMESON_SOURCE_ROOTenv variables if present.If not using the 'run' script, we can do a bit better at guessing the path from the 'check' filename. Always resolve from sys.argv[0], even when it is not a symlink, instead of falling back to '
cwd()' which doesn't work since we stopped having in-tree builds. If invoked directly from the source tree, guess that the build root is the default 'build' name which often works.With this change the following all work:
1. From root of build dir, with run script
cd build
./run tests/qemu-iotests/check 52. From root of build dir, without run script
cd build
tests/qemu-iotests/check 53. From I/O tests subdir of build dir, with run script
cd build/tests/qemu-iotests ../../run ./check 54. From I/O tests subdir of build dir, without run script
cd build/tests/qemu-iotests ./check 55. From root of source dir, with run script
./build/run tests/qemu-iotests/check 5
6. From root of source dir, without run script
tests/qemu-iotests/check 5
7. From I/O tests subdir of source dir, with run script
cd tests/qemu-iotests ../../build/run ./check 58. From I/O tests subdir of source dir, without run script
cd tests/qemu-iotests ./check 5Before this commit, items 5-8 would always fail. Items 6 and 8 will not work if using a build directory with a name other than the default 'build'. For those scenarios use one of the other 6 possible variants.
Quoted 8 lines
Signed-off-by Daniel P. Berrangé<[email protected]>Message-ID:<[email protected]>
Reviewed-by Kevin Wolf<[email protected]>Signed-off-by Kevin Wolf<[email protected]>--- meson.build | 1 + tests/qemu-iotests/check | 52 +++++++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 14 deletions(-)Fails all of the block tests. E.g.
Quoted 8 lines
https://gitlab.com/qemu-project/qemu/-/jobs/18118947590#L135
Review
Quoted 6 lines
=== pylint ===
(quoted diff) +5
-0+************* Module check +check:44:12: W0719: Raising too general exception: Exception (broad-exception-raised) +check:44:28: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation) +check:61:12: W0719: Raising too general exception: Exception (broad-exception-raised) +check:61:28: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
I dropped the patch from the pull request for now and sent a v2.
Kevin