Page MenuHomeFreeBSD

bhyve: Validate VirtIO queue guest addresses
ClosedPublic

Authored by hayzam_gmail.com on Tue, Sep 22, 2:53 PM.
Tags
None
Referenced Files
F174275518: D59904.diff
Thu, Oct 1, 10:50 PM
F174269608: D59904.id188195.diff
Thu, Oct 1, 9:40 PM
F174269535: D59904.id188212.diff
Thu, Oct 1, 9:39 PM
Unknown Object (File)
Wed, Sep 30, 2:17 PM
Unknown Object (File)
Wed, Sep 30, 2:09 PM
Unknown Object (File)
Wed, Sep 30, 12:58 PM
Unknown Object (File)
Wed, Sep 30, 12:34 PM
Unknown Object (File)
Tue, Sep 29, 7:16 PM
Subscribers

Details

Summary

paddr_guest2host() returns NULL when a range does not fit within guest
RAM. An unmappable queue address previously left the queue marked
allocated with ring pointers computed from the failed mapping. Check
the legacy virtqueue ring mapping before updating the queue state, and
ignore an unmappable PFN write after printing a diagnostic. This leaves
an unallocated queue unallocated and preserves an existing queue's PFN,
ring pointers, flags, and indices.

Also check the indirect descriptor table mapping before dereferencing
it, returning an error if the table is unmappable, and ignore guest
queue notifications for unallocated queues.

Sponsored by: The FreeBSD Foundation

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 77186
Build 74069: arc lint + arc unit

Event Timeline

usr.sbin/bhyve/pci_virtio_net.c
250

This check is racy though: what happens if the queue is disabled right after this check? Is the race acceptable for some reason?

I wonder if we instead want to notify the driver whenever a queue is disabled. The device model can then do whatever's needed in order to synchronize its I/O paths. In particular, it'd be nice to drop that racy vq_ring_ready() check from vq_has_descs().

Address review feedback, drop the virtio-net RX hunk.

This check is racy though: what happens if the queue is disabled right after this check? Is the race acceptable for some reason? I wonder if we instead want to notify the driver whenever a queue is disabled. The device model can then do whatever's needed in order to synchronize its I/O paths. In particular, it'd be nice to drop that racy vq_ring_ready() check from vq_has_descs().

Agreed, I've dropped the virtio-net RX hunk. For virtio-net, the remaining notify guard is serialized with PFN writes under vs_mtx. I'll try to pursue the queue-disable notification and backend synchronization in a separate patch.

usr.sbin/bhyve/virtio.c
196

Why do we disable the queue in this case? Why not ignore the write (and print an error message)?

This patch says it is validating guest-controlled addresses, but it's also introducing new functionality here, I believe. I'd rather handle that in a separate patch.

hayzam_gmail.com added inline comments.
usr.sbin/bhyve/virtio.c
196

Agreed. Invalid PFN writes now log an error and leave the queue unchanged. I’ve also removed zero-PFN queue-disable handling; that belongs in a separate patch.

hayzam_gmail.com edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Wed, Sep 30, 2:14 PM
This revision was automatically updated to reflect the committed changes.