]> xenbits.xensource.com Git - osstest/seabios.git/commitdiff
virtio-blk: Fix integer overflow for large max IO sizes
authorLukas Stockner via SeaBIOS <seabios@seabios.org>
Tue, 6 Jun 2023 13:29:52 +0000 (15:29 +0200)
committerKevin O'Connor <kevin@koconnor.net>
Tue, 13 Jun 2023 15:11:25 +0000 (11:11 -0400)
When the maximum IO size supported by the virtio-blk backend is large
enough (>= 32MiB for 512B sectors), the computed blk_num_max will
overflow. In particular, if it's a multiple of 32MiB, blk_num_max
will end up as zero, causing IO requests to fail.

This is triggered by e.g. the SPDK virtio-blk vhost-user backend.

To fix it, just limit blk_num_max to 65535 before converting to u16.

Signed-off-by: Lukas Stockner <lstockner@genesiscloud.com>
src/hw/virtio-blk.c

index e087fe4fb0e391b2d1fa3a7bee8ce4748211fa07..137a2c3c75579beae69611e248002d48f947fdac 100644 (file)
@@ -92,7 +92,7 @@ virtio_blk_op(struct disk_op_s *op, int write)
     u16 blk_num_max;
 
     if (vdrive->drive.blksize != 0 && max_io_size != 0)
-        blk_num_max = (u16)(max_io_size / vdrive->drive.blksize);
+        blk_num_max = (u16) min(max_io_size / vdrive->drive.blksize, 0xffff);
     else
         /* default blk_num_max if hardware doesnot advise a proper value */
         blk_num_max = 64;