diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2022-05-16 16:42:13 +0800 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2022-05-25 09:10:38 +0200 |
commit | 6ca70982c646cc32e458150ee7f2530a24369b8c (patch) | |
tree | c215daa1a04bf439c7b0c9611fc26456f95ec42c | |
parent | 6cdd53a49aa7413e53c14ece27d826f0b628b18a (diff) | |
download | linux-stable-6ca70982c646cc32e458150ee7f2530a24369b8c.tar.gz linux-stable-6ca70982c646cc32e458150ee7f2530a24369b8c.tar.bz2 linux-stable-6ca70982c646cc32e458150ee7f2530a24369b8c.zip |
Fix double fget() in vhost_net_set_backend()
commit fb4554c2232e44d595920f4d5c66cf8f7d13f9bc upstream.
Descriptor table is a shared resource; two fget() on the same descriptor
may return different struct file references. get_tap_ptr_ring() is
called after we'd found (and pinned) the socket we'll be using and it
tries to find the private tun/tap data structures associated with it.
Redoing the lookup by the same file descriptor we'd used to get the
socket is racy - we need to same struct file.
Thanks to Jason for spotting a braino in the original variant of patch -
I'd missed the use of fd == -1 for disabling backend, and in that case
we can end up with sock == NULL and sock != oldsock.
Cc: stable@kernel.org
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/vhost/net.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 0c7bbc92b22a..5ea7b0a94fe3 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -1209,13 +1209,9 @@ err: return ERR_PTR(r); } -static struct ptr_ring *get_tap_ptr_ring(int fd) +static struct ptr_ring *get_tap_ptr_ring(struct file *file) { struct ptr_ring *ring; - struct file *file = fget(fd); - - if (!file) - return NULL; ring = tun_get_tx_ring(file); if (!IS_ERR(ring)) goto out; @@ -1224,7 +1220,6 @@ static struct ptr_ring *get_tap_ptr_ring(int fd) goto out; ring = NULL; out: - fput(file); return ring; } @@ -1311,8 +1306,12 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd) r = vhost_net_enable_vq(n, vq); if (r) goto err_used; - if (index == VHOST_NET_VQ_RX) - nvq->rx_ring = get_tap_ptr_ring(fd); + if (index == VHOST_NET_VQ_RX) { + if (sock) + nvq->rx_ring = get_tap_ptr_ring(sock->file); + else + nvq->rx_ring = NULL; + } oldubufs = nvq->ubufs; nvq->ubufs = ubufs; |