vhost/vsock: fix uninitialized vhost_vsock->guest_cid
authorStefan Hajnoczi <stefanha@redhat.com>
Thu, 9 Nov 2017 13:29:10 +0000 (13:29 +0000)
committerMichael S. Tsirkin <mst@redhat.com>
Tue, 14 Nov 2017 21:57:40 +0000 (23:57 +0200)
The vhost_vsock->guest_cid field is uninitialized when /dev/vhost-vsock
is opened until the VHOST_VSOCK_SET_GUEST_CID ioctl is called.

kvmalloc(..., GFP_KERNEL | __GFP_RETRY_MAYFAIL) does not zero memory.
All other vhost_vsock fields are initialized explicitly so just
initialize this field too.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/vhost/vsock.c

index c9de9c41aa9769863e8164ec90478292f52532ba..5a5e981bd8e4a2a8fb34393fa6a05978d59e7e6c 100644 (file)
@@ -518,6 +518,8 @@ static int vhost_vsock_dev_open(struct inode *inode, struct file *file)
                goto out;
        }
 
+       vsock->guest_cid = 0; /* no CID assigned yet */
+
        atomic_set(&vsock->queued_replies, 0);
 
        vqs[VSOCK_VQ_TX] = &vsock->vqs[VSOCK_VQ_TX];