Skip to content

interfaces/builtin: add vsock interface for VM guest services - #16963

Merged
bboozzoo merged 1 commit into
canonical:masterfrom
bugraaydogar:baydogar-vsock-support
Jul 10, 2026
Merged

interfaces/builtin: add vsock interface for VM guest services#16963
bboozzoo merged 1 commit into
canonical:masterfrom
bugraaydogar:baydogar-vsock-support

Conversation

@bugraaydogar

Copy link
Copy Markdown
Contributor

A customer would like to use open-vm-tools heavily relies on the vsock interface for communication between hypervisor and guest. They were using custom-device interface to access dev files like /dev/vsock and /dev/vmci.

However, they also realized that they are getting denial due to missing vsock support. The custom-device interface does not allow adding network vsock. This PR aims to solve this problem.

Denied Messages:

Log: apparmor="DENIED" operation="create" class="net" profile="snap.vmware-tools-probe.probe" pid=34906 comm="python3" family="vsock" sock_type="stream" protocol=0 requested="create" denied="create"
Log: apparmor="DENIED" operation="create" class="net" profile="snap.vmware-tools-probe.probe" pid=34906 comm="python3" family="vsock" sock_type="dgram" protocol=0 requested="create" denied="create"

Internal reference: LP#2147028

@codecov

codecov Bot commented Apr 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.86%. Comparing base (4febe0c) to head (1278bc0).
⚠️ Report is 11 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #16963   +/-   ##
=======================================
  Coverage   78.86%   78.86%           
=======================================
  Files        1395     1397    +2     
  Lines      195858   195802   -56     
  Branches     2466     2466           
=======================================
- Hits       154469   154426   -43     
+ Misses      32121    32103   -18     
- Partials     9268     9273    +5     
Flag Coverage Δ
unittests 78.86% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Apr 22, 2026

Copy link
Copy Markdown

Fri Jul 10 10:39:59 UTC 2026
The following results are from: https://github.com/canonical/snapd/actions/runs/28924844960

Failures:

Preparing:

  • openstack:opensuse-tumbleweed-64:
  • openstack:opensuse-tumbleweed-64:
  • openstack:opensuse-tumbleweed-64:
  • openstack:opensuse-tumbleweed-64:
  • openstack:opensuse-tumbleweed-64:
  • openstack:opensuse-tumbleweed-64:
  • openstack:opensuse-tumbleweed-selinux-64:
  • openstack:opensuse-tumbleweed-selinux-64:
  • openstack:opensuse-tumbleweed-selinux-64:
  • openstack:opensuse-tumbleweed-selinux-64:
  • openstack:opensuse-tumbleweed-selinux-64:
  • openstack:opensuse-tumbleweed-selinux-64:

Executing:

  • openstack:debian-sid-64:tests/main/snap-cli-no-managers

Restoring:

  • openstack:opensuse-tumbleweed-64:
  • openstack:opensuse-tumbleweed-64:
  • openstack:opensuse-tumbleweed-64:
  • openstack:opensuse-tumbleweed-64:
  • openstack:opensuse-tumbleweed-64:
  • openstack:opensuse-tumbleweed-64:
  • openstack:opensuse-tumbleweed-selinux-64:
  • openstack:opensuse-tumbleweed-selinux-64:
  • openstack:opensuse-tumbleweed-selinux-64:
  • openstack:opensuse-tumbleweed-selinux-64:
  • openstack:opensuse-tumbleweed-selinux-64:
  • openstack:opensuse-tumbleweed-selinux-64:

Skipped tests from snapd-testing-skip

If you wish to have any of the below tests run in your PR, in your PR description, add 'unskip:' followed by a copy-and-pasted list of the below tests you wish to run (unskip plus test list must be valid yaml)

  • garden:ubuntu-25.10-64:tests/main/apparmor-prompting-support
  • openstack-arm:ubuntu-24.04-arm-64:tests/main/i18n
  • openstack-arm:ubuntu-core-24-arm-64:tests/main/i18n
  • openstack:debian-sid-64:tests/main/interfaces-network-status-classic
  • openstack:debian-sid-64:tests/main/interfaces-xdg-portal-permission-store
  • openstack:ubuntu-24.04-64:tests/main/i18n
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-flag-restart
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-integration-tests
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-prompt-restoration
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-smoke
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-snapd-startup
  • openstack:ubuntu-25.10-64:tests/main/apparmor-prompting-support
  • openstack:ubuntu-25.10-64:tests/main/interfaces-requests-activates-handlers
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-flag-restart
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-prompt-restoration
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-snapd-startup
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-support
  • openstack:ubuntu-26.04-64:tests/main/i18n
  • openstack:ubuntu-26.04-64:tests/main/interfaces-requests-activates-handlers

zyga
zyga previously requested changes Apr 23, 2026
Comment thread interfaces/builtin/network_bind.go Outdated

# Allow binding on vsock sockets (AF_VSOCK) for VM/container guest services.
# AF_VSOCK socket creation is permitted by the default seccomp template.
network vsock,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a definite nack as it would allow nearly any snap talk to any snap and to the hypervisor without any oversight.

This needs to be a different interface and we may need to have filtering on which CID you can actually talk to.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i created a separate vsock interface.

@bugraaydogar
bugraaydogar force-pushed the baydogar-vsock-support branch from c3a76de to a684831 Compare April 27, 2026 15:33
@bugraaydogar bugraaydogar changed the title i/b/network_bind: allow vsock sockets for VM guest services interfaces/builtin: add vsock interface for VM guest services Apr 27, 2026
@bboozzoo
bboozzoo requested a review from zyga April 29, 2026 06:56
@bboozzoo
bboozzoo dismissed zyga’s stale review April 29, 2026 06:56

Proposed as a new interface now.

Comment thread interfaces/builtin/vsock.go Outdated
# VM guests and the host or hypervisor (AF_VSOCK).
network vsock,
/dev/vsock rw,
/dev/vmci rw,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm this one is vmware specific, why include it here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the customer is trying to snap open-vm-tools and have observed the access denials. There is no other interface that allows access to vsock and vmci so i thought that would be a meaningful interface to add vmci as well. Otherwise, they would need to use custom-device interface for /dev/vmci

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should perhaps

  • add devices used by other virtualization stacks for similar purposes here, such as /dev/vhost-vsock or
  • change the interface name to make it vmware specific.

@pedronis any suggestion?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Through vsock you can only obtain the CID, whereas vhost-vsock exposes a bit more. I think it fits better within the scope of *-support interfaces, e.g. we expose it in microstack-support already.

@jslarraz jslarraz May 6, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, vhost-vsock is more the counterpart of /dev/vmci, isn't it?. In that sense I think we should either

  • add both ( /dev/vmci and /dev/vhost-vsock )
  • add none of them (and grant access to /dev/vmc via custom-device)
  • rename the interface to make it clear it is vmware specific

@jslarraz jslarraz Jun 29, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what I've seen, /dev/vmci is used by both, guest and host. The main difference is that this device node is backed by different kernel modules on these two scenarios. On "guest mode", it seems that vmci is used as the transport layer for vsock traffic (among other things).

Whilst vmci is needed for the transport layer, I don't know if vsock communication could possibly work without explicit access to the device node, /dev/vmci. On the other hand, /dev/vmci is possibly still needed by open-vm-tools to provide some functionality not carried over vsock.

If we can check that access to /dev/vmci is not required for vsock communication on vmware systems, I would vote for keeping this access out of the interface and use custom-device for it. If this ends up being a hard requirement, I think it will make sense to include it here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to sum up:

TBH, what if we consider this:

  • splitting up vsock access to e.g. vsock-guest interface - allow /dev/vsock, allow AF_VSOCK, IMO does not need to be superprivielged
  • the vhost-vsock is already part of microstack, but we can add another targeted interface if needed, not part of this PR anyway
  • move vmci into e.g. vmware-vmci, make it superprivileged, allow AF_VSOCK, allow /dev/vmci rw access

@zyga @jslarraz thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I mostly agree

splitting up vsock access to e.g. vsock-guest interface - allow /dev/vsock, allow AF_VSOCK, IMO does not need to be superprivielged

I would still make it privileged (maybe not super-privileged) as I don't think there are many snap that need it for legitimate reasons nowadays.

the vhost-vsock is already part of microstack, but we can add another targeted interface if needed, not part of this PR anyway

+1

move vmci into e.g. vmware-vmci, make it superprivileged, allow AF_VSOCK, allow /dev/vmci rw access

I wander whether access to /dev/vmci will endup being a one-off just for open-vm-tools. I wonder whether vsock interface + access to /dev/vmci via custom-device could be preferable over a dedicated interface for now. That's mainly a design decision, I have no strong opinion on this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bugraaydogar would this work for you? making the interface privileged, renaming to e.g. vsock-guest and limiting it to allow acecss to /dev/vsock + AF_VSOCK sockets & acecpt/bind/listen etc. and then custom-device for the snap in question to allow /dev/vmci

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bboozzoo thanks for the input. I updated as requested. Please let me know if you have any further finding.

Comment thread interfaces/builtin/vsock.go Outdated
const vsockBaseDeclarationPlugs = `
vsock:
allow-installation: false
deny-auto-connection: true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite agree with @zyga's initial review. If anything, it's not much different from network access, which we auto connect by default. In fact, VM ports could already be exposed and just by adding the network plug snap would already be able to connect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bboozzoo could you please add a security reviewer so that we could get a final input from the security professional?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've already requested a review from @jslarraz

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jslarraz
Sorry for the ping. Could you please review the PR? I'm trying to push these changes for the upcoming snapd 2.76 release as requested by the customer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this interface super-privileged makes sense to me because:

  • In contrast to network, this interface is really niche, I don't expect many snaps requiring legitimate access to it.
  • It increases the attack surface granting access to a kernel module, which possibly is not as widely tested as others

@bboozzoo
bboozzoo requested a review from jslarraz April 29, 2026 07:13
@bboozzoo bboozzoo added the Needs security review Can only be merged once security gave a :+1: label Apr 29, 2026

@jslarraz jslarraz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments

Comment thread interfaces/builtin/vsock.go Outdated
Comment thread interfaces/builtin/vsock.go Outdated
const vsockBaseDeclarationPlugs = `
vsock:
allow-installation: false
deny-auto-connection: true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this interface super-privileged makes sense to me because:

  • In contrast to network, this interface is really niche, I don't expect many snaps requiring legitimate access to it.
  • It increases the attack surface granting access to a kernel module, which possibly is not as widely tested as others

Comment thread interfaces/builtin/vsock.go Outdated
# VM guests and the host or hypervisor (AF_VSOCK).
network vsock,
/dev/vsock rw,
/dev/vmci rw,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should perhaps

  • add devices used by other virtualization stacks for similar purposes here, such as /dev/vhost-vsock or
  • change the interface name to make it vmware specific.

@pedronis any suggestion?

# Description: Allow access to vsock sockets for VM/container host communication.
# socket AF_VSOCK is already permitted by the default seccomp template.
bind
listen

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expected only bind to be needed on the guest side, and listen and accept only be required by the host piece. Did you run into issues without these other syscalls?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really like network and works in both directions, both guest and host can expose services for each other.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that sense, the relevant side could plug network-bind independently if needed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for info @bboozzoo. Then, I think it is also fine if we keep them here

@bugraaydogar
bugraaydogar force-pushed the baydogar-vsock-support branch from a684831 to 390fea4 Compare May 6, 2026 10:37
@zyga

zyga commented May 27, 2026

Copy link
Copy Markdown
Contributor

@bugraaydogar @jslarraz @bboozzoo I would like to perhaps limit the CIDs we can talk to. Specifically talking to the hypervisor is probably a special case that we could deny.

As for keeping it for remaining use cases, I think it's okay if it is super-privileged. This effectively lets you talk to any VM on the host and between any snap on the loopback interface. It is true that network allows that but not because we wanted to, but because we didn't have anything better to filter with.

I wonder if we need the device access. IIRC there's some ioctl that's kind of obsolete now (to know one's address).

@ndyer
ndyer requested a review from pedronis June 10, 2026 14:43
@ndyer ndyer assigned ndyer and bboozzoo and unassigned ndyer Jun 25, 2026
@ndyer ndyer added this to the 2.77 milestone Jun 25, 2026
@bugraaydogar

bugraaydogar commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@zyga Let me clarify the use case since I think we might be looking at this from different angles.

The primary customer use case is Ubuntu Core running as a guest inside a hypervisor. Snaps inside the guest use vsock to communicate up to the hypervisor for guest utilities. That being said, i don't think we should be blocking any other use case. It is going to be a super-privileged interface and developers must already know and understand the overall threats within their solutions. I'm not favor of increasing the complexity of the interface however, the decision is on the security team and they are already fine with the existing implementation unless they changed their ideas.

@zyga

zyga commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

I don't have any reservations for a privileged interface.

@bugraaydogar
bugraaydogar force-pushed the baydogar-vsock-support branch from 390fea4 to 12b665e Compare July 6, 2026 17:52

@bboozzoo bboozzoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bboozzoo
bboozzoo requested a review from jslarraz July 7, 2026 13:36
@bboozzoo

bboozzoo commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

@zyga @jslarraz can you take another look?

@bboozzoo

bboozzoo commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@bugraaydogar:

[7](https://github.com/canonical/snapd/actions/runs/28811925783/job/85441861486?pr=16963#step:11:158)
>> [Spread] Checking all interfaces have a spread test
Missing high-level test for interface 'vsock-guest'. Please add to:
* tests/lib/snaps/test-snapd-policy-app-consumer/meta/snap.yaml
* tests/main/interfaces-many-snap-provided/test-snapd-policy-app-provider-core/meta/snap.yaml (if needed)
* tests/main/interfaces-many-snap-provided/test-snapd-policy-app-provider-classic/meta/snap.yaml (if needed)

@bugraaydogar
bugraaydogar force-pushed the baydogar-vsock-support branch from 12b665e to 91d5f23 Compare July 8, 2026 06:30
@bugraaydogar
bugraaydogar force-pushed the baydogar-vsock-support branch from 91d5f23 to 1278bc0 Compare July 8, 2026 07:17

@pedronis pedronis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a re-review by @zyga

@jslarraz jslarraz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jslarraz jslarraz removed the Needs security review Can only be merged once security gave a :+1: label Jul 9, 2026
@bboozzoo bboozzoo added the Auto rerun spread Auto reruns spread up to 4 times in non-draft PRs w/ >=1 approval and <20 fails in any fund. system label Jul 10, 2026

@zyga zyga left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one comment.

const vsockGuestConnectedPlugSecComp = `
# Description: Allow access to vsock sockets for VM guest to host communication.
# socket AF_VSOCK is already permitted by the default seccomp template.
bind

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need ioctl IOCTL_VM_SOCKETS_GET_LOCAL_CID? I would think so.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, we only deny TIOCSTI & TIOCLINUX ioctl calls. See => https://github.com/canonical/snapd/blob/master/interfaces/seccomp/template.go#L228

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it should be working already, we allow all ioctls but the ones that allow nasty things

@bboozzoo
bboozzoo merged commit c28a8ac into canonical:master Jul 10, 2026
471 of 496 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto rerun spread Auto reruns spread up to 4 times in non-draft PRs w/ >=1 approval and <20 fails in any fund. system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants