Remove precondition on result of IOCTL_VM_SOCKETS_GET_LOCAL_CID #2588
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation:
When using the
IOCTL_VM_SOCKETS_GET_LOCAL_CID
call to get the local Context ID for a VSOCK socket, weprecondition
that the resulting Context ID is notVMADDR_CID_ANY
. This probably was an assumption too far and we've seen an issue1 where this led to a crash in the tests.Digging a little more on this and it looks like we've been too strict:
VMADDR_CID_ANY
2.VMADDR_CID_ANY
3.VMADDR_CID_LOCAL
4.VMADDR_CID_ANY
in the error path5.All that to say... we probably shouldn't make any precondition on the result of
IOCTL_VM_SOCKETS_GET_LOCAL_CID
since it appears to tightly coupled to the VSOCK transport, and I don't think we can confidently say anything about what the value should be.Additionally, while investigating this I found that the tests actually crash when we don't have
/dev/vsock
available, which was an oversight:These tests should be skipped by virtue of
try XCTSkipUnless(System.supportsVsock)
, which checks that we can create a socket withAF_VSOCK
. However, on Linux, this is not enough of a guard and we should probably also check for the presence of/dev/vsock
.Modifications:
precondition
that checks that the local CID as returned by theioctl()
is notVMADDR_CID_ANY
./dev/vsock
, instead let this fail, which will propagate up to through theChannel.getOption
path.hasVsockSupport
guard that conditionally runs the test to include checking for the presence of/dev/vsock
when on Linux.Result:
The tests no longer crash when
/dev/vsock
is not available on Linux. Note that we don't currently exercise these tests in CI because the CI runner doesn't have a new enough Linux kernel, but I've included some logs below from some manual runs.Linux, with
/dev/vsock
(still runs and passes)Linux, without
/dev/vsock
(skips, no longer crashes)macOS (skips, as before)
Related issues
VsockAddressTest.testGetLocalCID
crashes in jammy with Swift 5.9.1 #2585.Footnotes
VsockAddressTest.testGetLocalCID
crashes in jammy with Swift 5.9.1 #2585 ↩https://opensource.apple.com/source/xnu/xnu-7195.50.7.100.1/tests/vsock.c.auto.html ↩
https://github.com/torvalds/linux/blob/d2f51b3516dade79269ff45eae2a7668ae711b25/net/vmw_vsock/hyperv_transport.c#L437-L440 ↩
https://github.com/torvalds/linux/blob/d2f51b3516dade79269ff45eae2a7668ae711b25/net/vmw_vsock/vsock_loopback.c#L24-L27 ↩
https://github.com/torvalds/linux/blob/d2f51b3516dade79269ff45eae2a7668ae711b25/net/vmw_vsock/virtio_transport.c#L79-L95 ↩
https://github.com/torvalds/linux/blob/d2f51b3516dade79269ff45eae2a7668ae711b25/drivers/misc/vmw_vmci/vmci_guest.c#L88-L100 ↩