diff options
| author | Yaohan Li <shunsheng1218@gmail.com> | 2026-11-17 22:53:14 +0800 |
|---|---|---|
| committer | Michael S. Tsirkin <mst@redhat.com> | 2026-11-30 10:39:43 -0500 |
| commit | 803b45f83129f5140c84b4fa5d8614f4a36ce6b3 (patch) | |
| tree | be88c8e62882eb65f98e4d93155dd5004043ca33 /tools/lib/python | |
| parent | c74d1bd01a6a624ab2f5796926059852b713c929 (diff) | |
vhost: synchronize worker freeing on vhost-net teardown
vhost_workers_free() only waits for RCU readers when sync is true. Both
vhost-net teardown paths pass false, relying on the assumption recorded
when the sync parameter was introduced (5efd97e6f0c7) that "net and scsi
stop their virtqueues before the workers are freed".
That assumption does not hold when a tap queue is detached while the
socket is still attached. __tun_detach() runs tun_queue_purge() on the
detaching thread, so skb_queue_purge() releases the zerocopy skbs and
vhost_zerocopy_complete() -> vhost_poll_queue() runs there rather than on
the vhost worker. The vhost_dev_flush() calls in vhost_net_flush() and
vhost_dev_stop() only wait for the vhost workers, so the queueing can
still be in flight when vhost_dev_cleanup() frees the worker, and
vhost_worker_queue() then dereferences freed memory.
Pass sync=true from vhost_net_release() and vhost_net_reset_owner() so a
grace period and a flush are observed before the workers are released,
matching the vsock RESET_OWNER path. Both are slow paths, and the extra
grace period buys back the races described above.
Testing: QEMU/KVM guest with KASAN and CONFIG_VHOST_NET, zerocopy enabled
via vhost_net.experimental_zcopytx=1. A second thread detaches one of
the tap queues and frees the queued skb, and vhost_worker_queue() is
delayed with a fault-injection module so that the close() or the
VHOST_RESET_OWNER ioctl completes in between. The delay only widens an
existing window; the detach, the purge and the teardown are all
unmodified upstream behaviour.
Both teardown paths reproduce the use-after-free on this base, and both
are clean with this change while the injection is still taken. The same
injection reproduced on the earlier base where the analysis was done.
Signed-off-by: Yaohan Li <shunsheng1218@gmail.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-ID: <20261117145314.1092372-1-shunsheng1218@gmail.com>
Diffstat (limited to 'tools/lib/python')
0 files changed, 0 insertions, 0 deletions
