Skip to content

Commit

Permalink
vhost_net: correct error handling in vhost_net_set_backend()
Browse files Browse the repository at this point in the history
Currently, when vhost_init_used() fails the sock refcnt and ubufs were
leaked. Correct this by calling vhost_init_used() before assign ubufs and
restore the oldsock when it fails.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jason Wang authored and David S. Miller committed Jan 29, 2013
1 parent af668b3 commit 692a998
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions drivers/vhost/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,15 +827,16 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd)
r = PTR_ERR(ubufs);
goto err_ubufs;
}
oldubufs = vq->ubufs;
vq->ubufs = ubufs;

vhost_net_disable_vq(n, vq);
rcu_assign_pointer(vq->private_data, sock);
vhost_net_enable_vq(n, vq);

r = vhost_init_used(vq);
if (r)
goto err_vq;
goto err_used;
vhost_net_enable_vq(n, vq);

oldubufs = vq->ubufs;
vq->ubufs = ubufs;

n->tx_packets = 0;
n->tx_zcopy_err = 0;
Expand All @@ -859,6 +860,11 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd)
mutex_unlock(&n->dev.mutex);
return 0;

err_used:
rcu_assign_pointer(vq->private_data, oldsock);
vhost_net_enable_vq(n, vq);
if (ubufs)
vhost_ubuf_put_and_wait(ubufs);
err_ubufs:
fput(sock->file);
err_vq:
Expand Down

0 comments on commit 692a998

Please sign in to comment.