[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openbsd-tech
Subject:    fix vmd's vioscsi block count calculation
From:       Dave Voutila <dv () sisu ! io>
Date:       2023-10-31 1:18:51
Message-ID: 87jzr3374o.fsf () mars ! sisu ! io
[Download RAW message or body]

Remove faulty and overly fancy math for computing number of 2048 byte
blocks are in the provided iso image. Miscalculating the number of
blocks can cause a driver to try reading past the end of the file
thinking the disc is larger than reality.

If you wonder how ">> 2" was ever valid, this was missed in a conversion
a while back when some previous code was setting vioscsi->sz to
multiples of 512 bytes.

ok?
-dv

diff /usr/src
commit - 24fdc731bb2dae453b197818a355f3aac441ec6f
path + /usr/src
blob - e4795cfb7e7a2c7119d7001d1924c965c2657cc9
file + usr.sbin/vmd/virtio.c
--- usr.sbin/vmd/virtio.c
+++ usr.sbin/vmd/virtio.c
@@ -719,7 +719,7 @@ virtio_init(struct vmd_vm *vm, int child_cdrom,
 		}
 		vioscsi->locked = 0;
 		vioscsi->lba = 0;
-		vioscsi->n_blocks = vioscsi->sz >> 2; /* num of 2048 blocks in file */
+		vioscsi->n_blocks = vioscsi->sz / VIOSCSI_BLOCK_SIZE_CDROM;
 		vioscsi->max_xfer = VIOSCSI_BLOCK_SIZE_CDROM;
 		vioscsi->pci_id = id;
 		vioscsi->vm_id = vcp->vcp_id;

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic