Page MenuHomeFreeBSD

bhyve/virtio-scsi: check LUN address validity
Needs ReviewPublic

Authored by rosenfeld_grumpf.hope-2000.org on Oct 30 2025, 7:38 AM.
Tags
None
Referenced Files
F139100417: D53470.id165404.diff
Sun, Dec 7, 7:42 PM
F139066906: D53470.id165401.diff
Sun, Dec 7, 7:57 AM
Unknown Object (File)
Fri, Dec 5, 3:10 AM
Unknown Object (File)
Tue, Dec 2, 2:26 PM
Unknown Object (File)
Sun, Nov 30, 10:09 PM
Unknown Object (File)
Fri, Nov 28, 10:25 AM
Unknown Object (File)
Thu, Nov 27, 11:48 AM
Unknown Object (File)
Tue, Nov 25, 12:05 AM

Details

Reviewers
jhb
corvink
markj
Group Reviewers
bhyve
Summary

Instead of blindly trusting the guest OS driver that it sends us well-
formed LUN addresses, check the LUN address for validity and fail the
request if it is invalid. While here, constify the members of the virtio
requests which aren't device-writable anyway.

Diff Detail

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

Event Timeline

Rebase, revert unintentional white space change.

usr.sbin/bhyve/pci_virtio_scsi.c
412
434–436

Should we really just assert here? It's a guest give value isn't it? So, we should omit the check on release builds. I know bhyve doesn't opt out assert on release builds. However, we shouldn't add new asserts which are required for release builds too.

Improve the comments describing the LUN address parsing.

usr.sbin/bhyve/pci_virtio_scsi.c
412

No, they must be zero, thats why we return false if any one of them isn't.

434–436

Every code path using pci_vtscsi_get_lun() (and pci_vtscsi_get_target() in a later change) is supposed to use pci_vtscsi_check_lun() to check LUN validity before even getting there and return an appropriate error to the guest.

Having these asserts in pci_vtscsi_get_lun() is thus a matter of defensive programming. These checks cost next to nothing, and they blow up only if there's a coding error, which is precisely what assertions are for.