Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
config: Protect vhost_user_store_path against annotation attacks
Browse files Browse the repository at this point in the history
This path could be used to overwrite data on the host.

Fixes: #3004

Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
  • Loading branch information
c3d committed Nov 10, 2020
1 parent fba4619 commit 2f0360b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cli/config/configuration-qemu-virtiofs.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ vhost_user_store_path = "@DEFVHOSTUSERSTOREPATH@"
# Enabling this will result in the VM device having iommu_platform=on set
#enable_iommu_platform = true

# List of valid annotations values for the virtiofs daemon (default: empty)
# vhost_user_store_path_list = [ "/empty/space", "/multiverse/quantum-foam" ]

# Enable file based guest memory support. The default is an empty string which
# will disable this feature. In the case of virtio-fs, this is enabled
# automatically and '/dev/shm' is used as the backing folder.
Expand Down
6 changes: 4 additions & 2 deletions cli/config/configuration-qemu.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ vhost_user_store_path = "@DEFVHOSTUSERSTOREPATH@"
# Enabling this will result in the VM device having iommu_platform=on set
#enable_iommu_platform = true

# List of valid annotations values for the virtiofs daemon (default: empty)
# vhost_user_store_path_list = [ "/empty/space", "/multiverse/quantum-foam" ]

# Enable file based guest memory support. The default is an empty string which
# will disable this feature. In the case of virtio-fs, this is enabled
# automatically and '/dev/shm' is used as the backing folder.
Expand Down Expand Up @@ -491,7 +494,6 @@ experimental=@DEFAULTEXPFEATURES@
# If enabled, containers are allowed to join the pid namespace of the agent
# when the env variable KATA_AGENT_PIDNS is set for a container.
# Use this with caution and only when required, as this option allows the container
# to access the agent process. It is recommended to enable this option
# to access the agent process. It is recommended to enable this option
# only in debug scenarios and with containers with lowered priveleges.
#enable_agent_pidns = true

1 change: 1 addition & 0 deletions pkg/katautils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
DisableVhostNet: h.DisableVhostNet,
EnableVhostUserStore: h.EnableVhostUserStore,
VhostUserStorePath: h.vhostUserStorePath(),
VhostUserStorePathList: h.VhostUserStorePathList,
GuestHookPath: h.guestHookPath(),
}, nil
}
Expand Down
3 changes: 3 additions & 0 deletions virtcontainers/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ type HypervisorConfig struct {
// related folders, sockets and device nodes should be.
VhostUserStorePath string

// VhostUserStorePathList is the list of valid values for vhost-user paths
VhostUserStorePathList []string

// GuestHookPath is the path within the VM that will be used for 'drop-in' hooks
GuestHookPath string

Expand Down
2 changes: 2 additions & 0 deletions virtcontainers/persist.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func (s *Sandbox) dumpConfig(ss *persistapi.SandboxState) {
DisableVhostNet: sconfig.HypervisorConfig.DisableVhostNet,
EnableVhostUserStore: sconfig.HypervisorConfig.EnableVhostUserStore,
VhostUserStorePath: sconfig.HypervisorConfig.VhostUserStorePath,
VhostUserStorePathList: sconfig.HypervisorConfig.VhostUserStorePathList,
GuestHookPath: sconfig.HypervisorConfig.GuestHookPath,
VMid: sconfig.HypervisorConfig.VMid,
}
Expand Down Expand Up @@ -555,6 +556,7 @@ func loadSandboxConfig(id string) (*SandboxConfig, error) {
DisableVhostNet: hconf.DisableVhostNet,
EnableVhostUserStore: hconf.EnableVhostUserStore,
VhostUserStorePath: hconf.VhostUserStorePath,
VhostUserStorePathList: hconf.VhostUserStorePathList,
GuestHookPath: hconf.GuestHookPath,
VMid: hconf.VMid,
}
Expand Down
3 changes: 3 additions & 0 deletions virtcontainers/persist/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ type HypervisorConfig struct {
// related folders, sockets and device nodes should be.
VhostUserStorePath string

// VhostUserStorePathList is the list of valid values for vhost-user paths
VhostUserStorePathList []string

// GuestHookPath is the path within the VM that will be used for 'drop-in' hooks
GuestHookPath string

Expand Down
7 changes: 7 additions & 0 deletions virtcontainers/pkg/oci/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,13 @@ func addHypervisorConfigOverrides(ocispec specs.Spec, config *vc.SandboxConfig,
config.HypervisorConfig.DisableVhostNet = disableVhostNet
}

if value, ok := ocispec.Annotations[vcAnnotations.VhostUserStorePath]; ok {
if !regexpContains(runtime.HypervisorConfig.VhostUserStorePathList, value) {
return fmt.Errorf("vhost store path %v required from annotation is not valid", value)
}
config.HypervisorConfig.VhostUserStorePath = value
}

if value, ok := ocispec.Annotations[vcAnnotations.GuestHookPath]; ok {
if value != "" {
config.HypervisorConfig.GuestHookPath = value
Expand Down

0 comments on commit 2f0360b

Please sign in to comment.