Commit 1dace8c8 authored by Jeff Dike's avatar Jeff Dike Committed by Michael S. Tsirkin
Browse files

vhost: fix error path in vhost_net_set_backend



An error could cause vhost_net_set_backend to exit without unlocking
vq->mutex. Fix this.

Signed-off-by: default avatarJeff Dike <jdike@linux.intel.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent 39286fa4
Loading
Loading
Loading
Loading
+5 −3
Original line number Original line Diff line number Diff line
@@ -508,12 +508,12 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd)
	/* Verify that ring has been setup correctly. */
	/* Verify that ring has been setup correctly. */
	if (!vhost_vq_access_ok(vq)) {
	if (!vhost_vq_access_ok(vq)) {
		r = -EFAULT;
		r = -EFAULT;
		goto err;
		goto err_vq;
	}
	}
	sock = get_socket(fd);
	sock = get_socket(fd);
	if (IS_ERR(sock)) {
	if (IS_ERR(sock)) {
		r = PTR_ERR(sock);
		r = PTR_ERR(sock);
		goto err;
		goto err_vq;
	}
	}


	/* start polling new socket */
	/* start polling new socket */
@@ -524,12 +524,14 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd)
	vhost_net_disable_vq(n, vq);
	vhost_net_disable_vq(n, vq);
	rcu_assign_pointer(vq->private_data, sock);
	rcu_assign_pointer(vq->private_data, sock);
	vhost_net_enable_vq(n, vq);
	vhost_net_enable_vq(n, vq);
	mutex_unlock(&vq->mutex);
done:
done:
	if (oldsock) {
	if (oldsock) {
		vhost_net_flush_vq(n, index);
		vhost_net_flush_vq(n, index);
		fput(oldsock->file);
		fput(oldsock->file);
	}
	}

err_vq:
	mutex_unlock(&vq->mutex);
err:
err:
	mutex_unlock(&n->dev.mutex);
	mutex_unlock(&n->dev.mutex);
	return r;
	return r;