[PATCH-for-5.2] hw/virtio/vhost-backend: Fix Coverity CID 1432871

Philippe Mathieu-Daudé posted 1 patch 3 years, 6 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20201102203609.2228309-1-philmd@redhat.com
There is a newer version of this series
hw/virtio/vhost-backend.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH-for-5.2] hw/virtio/vhost-backend: Fix Coverity CID 1432871
Posted by Philippe Mathieu-Daudé 3 years, 6 months ago
Fix uninitialized value issues reported by Coverity:

  Field 'msg.reserved' is uninitialized when calling write().

Reported-by: Coverity (CID 1432864: UNINIT)
Fixes: c471ad0e9bd ("vhost_net: device IOTLB support")
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/virtio/vhost-backend.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
index 88c8ecc9e03..222bbcc62de 100644
--- a/hw/virtio/vhost-backend.c
+++ b/hw/virtio/vhost-backend.c
@@ -257,7 +257,7 @@ static int vhost_kernel_send_device_iotlb_msg(struct vhost_dev *dev,
                                               struct vhost_iotlb_msg *imsg)
 {
     if (dev->backend_cap & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2)) {
-        struct vhost_msg_v2 msg;
+        struct vhost_msg_v2 msg = {};
 
         msg.type = VHOST_IOTLB_MSG_V2;
         msg.iotlb = *imsg;
@@ -267,7 +267,7 @@ static int vhost_kernel_send_device_iotlb_msg(struct vhost_dev *dev,
             return -EFAULT;
         }
     } else {
-        struct vhost_msg msg;
+        struct vhost_msg msg = {};
 
         msg.type = VHOST_IOTLB_MSG;
         msg.iotlb = *imsg;
-- 
2.26.2

Re: [PATCH-for-5.2] hw/virtio/vhost-backend: Fix Coverity CID 1432871
Posted by Peter Maydell 3 years, 6 months ago
On Mon, 2 Nov 2020 at 20:36, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>
> Fix uninitialized value issues reported by Coverity:
>
>   Field 'msg.reserved' is uninitialized when calling write().
>
> Reported-by: Coverity (CID 1432864: UNINIT)
> Fixes: c471ad0e9bd ("vhost_net: device IOTLB support")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  hw/virtio/vhost-backend.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
> index 88c8ecc9e03..222bbcc62de 100644
> --- a/hw/virtio/vhost-backend.c
> +++ b/hw/virtio/vhost-backend.c
> @@ -257,7 +257,7 @@ static int vhost_kernel_send_device_iotlb_msg(struct vhost_dev *dev,
>                                                struct vhost_iotlb_msg *imsg)
>  {
>      if (dev->backend_cap & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2)) {
> -        struct vhost_msg_v2 msg;
> +        struct vhost_msg_v2 msg = {};
>
>          msg.type = VHOST_IOTLB_MSG_V2;
>          msg.iotlb = *imsg;
> @@ -267,7 +267,7 @@ static int vhost_kernel_send_device_iotlb_msg(struct vhost_dev *dev,
>              return -EFAULT;
>          }
>      } else {
> -        struct vhost_msg msg;
> +        struct vhost_msg msg = {};
>
>          msg.type = VHOST_IOTLB_MSG;
>          msg.iotlb = *imsg;

Coverity didn't mind about the struct vhost_msg because
it doesn't have a 'reserved' field like vhost_msg_v2; but it
doesn't hurt to initialize it and it makes the two parts of
the function consistent, which is good.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM