]> git.ipfire.org Git - thirdparty/qemu.git/commit
block: fix crash on zero-length unaligned write and read
authorVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Thu, 6 Feb 2020 16:42:45 +0000 (19:42 +0300)
committerMichael Roth <mdroth@linux.vnet.ibm.com>
Mon, 22 Jun 2020 17:50:27 +0000 (12:50 -0500)
commit3dd28c8ecc2fe3907fe0b096b4b715c106989542
tree7aa0ee7ee081f76494c10d949b21d8d88709e100
parentee9f37f3e5377dfd91045afd2b6ec8e9c75cb191
block: fix crash on zero-length unaligned write and read

Commit 7a3f542fbd "block/io: refactor padding" occasionally dropped
aligning for zero-length request: bdrv_init_padding() blindly return
false if bytes == 0, like there is nothing to align.

This leads the following command to crash:

./qemu-io --image-opts -c 'write 1 0' \
  driver=blkdebug,align=512,image.driver=null-co,image.size=512

>> qemu-io: block/io.c:1955: bdrv_aligned_pwritev: Assertion
    `(offset & (align - 1)) == 0' failed.
>> Aborted (core dumped)

Prior to 7a3f542fbd we does aligning of such zero requests. Instead of
recovering this behavior let's just do nothing on such requests as it
is useless.

Note that driver may have special meaning of zero-length reqeusts, like
qcow2_co_pwritev_compressed_part, so we can't skip any zero-length
operation. But for unaligned ones, we can't pass it to driver anyway.

This commit also fixes crash in iotest 80 running with -nocache:

./check -nocache -qcow2 80

which crashes on same assertion due to trying to read empty extra data
in qcow2_do_read_snapshots().

Cc: qemu-stable@nongnu.org # v4.2
Fixes: 7a3f542fbd
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: 20200206164245.17781-1-vsementsov@virtuozzo.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
(cherry picked from commit ac9d00bf7b47acae6b0e42910d9ed55fef3af5b8)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
block/io.c