linux/drivers/vhost
Nikolay Kuratov dd54bcf86c vhost/net: Protect ubufs with rcu read lock in vhost_net_ubuf_put()
When operating on struct vhost_net_ubuf_ref, the following execution
sequence is theoretically possible:
CPU0 is finalizing DMA operation                   CPU1 is doing VHOST_NET_SET_BACKEND
                             // ubufs->refcount == 2
vhost_net_ubuf_put()                               vhost_net_ubuf_put_wait_and_free(oldubufs)
                                                     vhost_net_ubuf_put_and_wait()
                                                       vhost_net_ubuf_put()
                                                         int r = atomic_sub_return(1, &ubufs->refcount);
                                                         // r = 1
int r = atomic_sub_return(1, &ubufs->refcount);
// r = 0
                                                      wait_event(ubufs->wait, !atomic_read(&ubufs->refcount));
                                                      // no wait occurs here because condition is already true
                                                    kfree(ubufs);
if (unlikely(!r))
  wake_up(&ubufs->wait);  // use-after-free

This leads to use-after-free on ubufs access. This happens because CPU1
skips waiting for wake_up() when refcount is already zero.

To prevent that use a read-side RCU critical section in vhost_net_ubuf_put(),
as suggested by Hillf Danton. For this lock to take effect, free ubufs with
kfree_rcu().

Cc: stable@vger.kernel.org
Fixes: 0ad8b480d6 ("vhost: fix ref cnt checking deadlock")
Reported-by: Andrey Ryabinin <arbn@yandex-team.com>
Suggested-by: Hillf Danton <hdanton@sina.com>
Signed-off-by: Nikolay Kuratov <kniv@yandex-team.ru>
Message-Id: <20250805130917.727332-1-kniv@yandex-team.ru>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2025-08-26 03:38:10 -04:00
..
iotlb.c
Kconfig vhost: Reintroduce kthread API and add mode selection 2025-08-01 09:11:09 -04:00
Makefile
net.c vhost/net: Protect ubufs with rcu read lock in vhost_net_ubuf_put() 2025-08-26 03:38:10 -04:00
scsi.c vhost-scsi: Fix check for inline_sg_cnt exceeding preallocated limit 2025-08-01 09:11:08 -04:00
test.c
test.h
vdpa.c irqbypass: Require producers to pass in Linux IRQ number during registration 2025-06-20 13:52:41 -07:00
vhost.c vhost: initialize vq->nheads properly 2025-08-05 05:57:40 -04:00
vhost.h virtio, vhost: features, fixes 2025-08-01 14:17:48 -07:00
vringh.c vhost: vringh: Remove unused functions 2025-08-01 09:11:08 -04:00
vsock.c vsock/virtio: Rename virtio_vsock_skb_rx_put() 2025-08-01 09:11:09 -04:00