]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
qemu-img: fix offset calculation in bench
authorDenis Rastyogin <gerben@altlinux.org>
Tue, 6 May 2025 14:13:37 +0000 (17:13 +0300)
committerKevin Wolf <kwolf@redhat.com>
Thu, 22 May 2025 14:54:05 +0000 (16:54 +0200)
This error was discovered by fuzzing qemu-img.

The current offset calculation leads to an EIO error
in block/block-backend.c: blk_check_byte_request():

 if (offset > len || len - offset < bytes) {
     return -EIO;
 }

This triggers the error message:
"qemu-img: Failed request: Input/output error".

Example of the issue:
 offset: 260076
 len: 260096
 bytes: 4096

This fix ensures that offset remains within a valid range.

Signed-off-by: Denis Rastyogin <gerben@altlinux.org>
Message-ID: <20250506141410.100119-1-gerben@altlinux.org>
[kwolf: Fixed up integer overflow]
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qemu-img.c

index 76ac5d3028b0ac9ca69cfa3aeb17476fce1f66c3..139eeb5039b5efe7abfa00082f1d38fd17b0955a 100644 (file)
@@ -4488,10 +4488,10 @@ static void bench_cb(void *opaque, int ret)
          */
         b->in_flight++;
         b->offset += b->step;
-        if (b->image_size == 0) {
+        if (b->image_size <= b->bufsize) {
             b->offset = 0;
         } else {
-            b->offset %= b->image_size;
+            b->offset %= b->image_size - b->bufsize;
         }
         if (b->write) {
             acb = blk_aio_pwritev(b->blk, offset, b->qiov, 0, bench_cb, b);