[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 28/61] contrib/vhost-user-blk: fix overflowing expression
From: |
Michael S. Tsirkin |
Subject: |
[PULL v2 28/61] contrib/vhost-user-blk: fix overflowing expression |
Date: |
Tue, 23 Jul 2024 06:57:42 -0400 |
From: Stefano Garzarella <sgarzare@redhat.com>
Coverity reported:
>>> CID 1549454: Integer handling issues (OVERFLOW_BEFORE_WIDEN)
>>> Potentially overflowing expression
"le32_to_cpu(desc->num_sectors) << 9" with type "uint32_t"
(32 bits, unsigned) is evaluated using 32-bit arithmetic, and
then used in a context that expects an expression of type
"uint64_t" (64 bits, unsigned).
199 le32_to_cpu(desc->num_sectors) << 9 };
Coverity noticed this issue after commit ab04420c3 ("contrib/vhost-user-*:
use QEMU bswap helper functions"), but it was pre-existing and introduced
from the beginning by commit caa1ee4313 ("vhost-user-blk: add
discard/write zeroes features support").
Explicitly cast the 32-bit value before the shift to fix this issue.
Fixes: Coverity CID 1549454
Fixes: 5ab04420c3 ("contrib/vhost-user-*: use QEMU bswap helper functions")
Fixes: caa1ee4313 ("vhost-user-blk: add discard/write zeroes features support")
Cc: changpeng.liu@intel.com
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Message-Id: <20240712153857.207440-1-sgarzare@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
contrib/vhost-user-blk/vhost-user-blk.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/contrib/vhost-user-blk/vhost-user-blk.c
b/contrib/vhost-user-blk/vhost-user-blk.c
index 9492146855..6cc18a1c04 100644
--- a/contrib/vhost-user-blk/vhost-user-blk.c
+++ b/contrib/vhost-user-blk/vhost-user-blk.c
@@ -196,7 +196,7 @@ vub_discard_write_zeroes(VubReq *req, struct iovec *iov,
uint32_t iovcnt,
VubDev *vdev_blk = req->vdev_blk;
desc = buf;
uint64_t range[2] = { le64_to_cpu(desc->sector) << 9,
- le32_to_cpu(desc->num_sectors) << 9 };
+ (uint64_t)le32_to_cpu(desc->num_sectors) << 9 };
if (type == VIRTIO_BLK_T_DISCARD) {
if (ioctl(vdev_blk->blk_fd, BLKDISCARD, range) == 0) {
g_free(buf);
--
MST
- [PULL v2 18/61] intel_iommu: fix FRCD construction macro, (continued)
- [PULL v2 18/61] intel_iommu: fix FRCD construction macro, Michael S. Tsirkin, 2024/07/23
- [PULL v2 19/61] intel_iommu: move VTD_FRCD_PV and VTD_FRCD_PP declarations, Michael S. Tsirkin, 2024/07/23
- [PULL v2 20/61] intel_iommu: fix type of the mask field in VTDIOTLBPageInvInfo, Michael S. Tsirkin, 2024/07/23
- [PULL v2 23/61] virtio: virtqueue_pop - VIRTIO_F_IN_ORDER support, Michael S. Tsirkin, 2024/07/23
- [PULL v2 21/61] intel_iommu: make type match, Michael S. Tsirkin, 2024/07/23
- [PULL v2 22/61] virtio: Add bool to VirtQueueElement, Michael S. Tsirkin, 2024/07/23
- [PULL v2 24/61] virtio: virtqueue_ordered_fill - VIRTIO_F_IN_ORDER support, Michael S. Tsirkin, 2024/07/23
- [PULL v2 25/61] virtio: virtqueue_ordered_flush - VIRTIO_F_IN_ORDER support, Michael S. Tsirkin, 2024/07/23
- [PULL v2 26/61] vhost,vhost-user: Add VIRTIO_F_IN_ORDER to vhost feature bits, Michael S. Tsirkin, 2024/07/23
- [PULL v2 27/61] virtio: Add VIRTIO_F_IN_ORDER property definition, Michael S. Tsirkin, 2024/07/23
- [PULL v2 28/61] contrib/vhost-user-blk: fix overflowing expression,
Michael S. Tsirkin <=
- [PULL v2 29/61] hw/pci: Fix SR-IOV VF number calculation, Michael S. Tsirkin, 2024/07/23
- [PULL v2 30/61] pcie_sriov: Ensure PF and VF are mutually exclusive, Michael S. Tsirkin, 2024/07/23
- [PULL v2 31/61] pcie_sriov: Check PCI Express for SR-IOV PF, Michael S. Tsirkin, 2024/07/23
- [PULL v2 33/61] virtio-pci: Implement SR-IOV PF, Michael S. Tsirkin, 2024/07/23
- [PULL v2 32/61] pcie_sriov: Allow user to create SR-IOV device, Michael S. Tsirkin, 2024/07/23
- [PULL v2 34/61] virtio-net: Implement SR-IOV VF, Michael S. Tsirkin, 2024/07/23
- [PULL v2 35/61] docs: Document composable SR-IOV device, Michael S. Tsirkin, 2024/07/23
- [PULL v2 36/61] smbios: make memory device size configurable per Machine, Michael S. Tsirkin, 2024/07/23