Skip to content

vmm: preserved FDs: prevent usage of same FD multiple times #28

Closed
phip1611 wants to merge 2 commits intocyberus-technology:gardenlinuxfrom
phip1611:poc-prevent-multiple-preserved-fds
Closed

vmm: preserved FDs: prevent usage of same FD multiple times #28
phip1611 wants to merge 2 commits intocyberus-technology:gardenlinuxfrom
phip1611:poc-prevent-multiple-preserved-fds

Conversation

@phip1611
Copy link
Member

@phip1611 phip1611 commented Oct 23, 2025

About

Part of https://github.com/cobaltcore-dev/cobaltcore/issues/292. Currently not a big issue, but technically it can be a severe problem. And it might be beneficial to have this to detect misconfiguration.

Technical description: See commit message.

Why I worked on this

I worked on this in my attempt to finish some upstream PRs. I noticed this is more complicated than anticipated. So I created this PoC for us and upstreaming is future work.

  • libvirt-tests passed
  • add libvirt-tests test case for this
  • libvirt-tests still passes

@phip1611 phip1611 self-assigned this Oct 23, 2025
@phip1611 phip1611 force-pushed the poc-prevent-multiple-preserved-fds branch from f9b7d8d to 8f88c6e Compare October 23, 2025 16:07
@phip1611 phip1611 force-pushed the poc-prevent-multiple-preserved-fds branch 2 times, most recently from e69055e to 109f6cd Compare October 27, 2025 14:06
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
Allowing the same file descriptor (FD) to be preserved more than once
can lead to severe issues. Consider the case where management software
adds two virtio-net devices at runtime, both backed by the same
externally provided FD.

When the first device is removed during runtime, the FD for the second
device becomes invalid [0].

To avoid misconfigurations, we now prevent multiple preservation
attempts of the same FD.

This however has some caveats: In the current model, external FDs are
added to the list of preserved FDs after the corresponding device has
been created successfully. Now assume the following:
- VM boots
  - VM config has no preserved FDs
  - We add a device to the VM that uses an external FD for its Tap dev
  - The device is successfully initialized
  - VM config is extended with the preserved FDs
- VM reboots
  - VM config already has preserved FDs
  - Same as above
  - CRASH

Therefore, we need to know for every preserved FD whether it is "cold",
i.e., only has been part of a former VmConfig without associated device,
or "hot", i.e., it is currently also actively in use. This allows state
transitions from cold->hot in which case we won't throw an error for a
reused FD. Otherwise, we throw errors.

This requires that on shutdown, all preserved FDs are marked as cold.

[0] cloud-hypervisor#7371

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
@phip1611 phip1611 force-pushed the poc-prevent-multiple-preserved-fds branch from 109f6cd to 792ff49 Compare October 27, 2025 14:18
@phip1611 phip1611 marked this pull request as draft November 12, 2025 17:31
@phip1611
Copy link
Member Author

phip1611 commented Nov 14, 2025

Doesn't really solve a problem that we have right now and we have more important work.

I think I will fix this upstream. Also see cloud-hypervisor#7475

@phip1611 phip1611 closed this Nov 14, 2025
@phip1611 phip1611 deleted the poc-prevent-multiple-preserved-fds branch November 25, 2025 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant