> 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
> [ ... ]
> 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 <[email protected]>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=1


Reply via email to