config: Protect jailer_path annotation

The jailer_path annotation can be used to execute arbitrary code on
the host. Add a jailer_path_list configuration entry providing a list
of regular expressions that can be used to filter annotations that
represent valid file names.

Fixes: #901

Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
This commit is contained in:
Christophe de Dinechin 2020-05-15 17:49:01 +02:00
parent 076690179d
commit 27b6620b23
6 changed files with 20 additions and 0 deletions

View File

@ -27,6 +27,10 @@ image = "@IMAGEPATH@"
# for this feature today. # for this feature today.
#jailer_path = "@FCJAILERPATH@" #jailer_path = "@FCJAILERPATH@"
# List of valid jailer path values for the hypervisor (default: empty)
# Each member of the list can be a regular expression
# jailer_path_list = [ "@FCJAILERPATH@.*" ]
# Optional space-separated list of options to pass to the guest kernel. # Optional space-separated list of options to pass to the guest kernel.
# For example, use `kernel_params = "vsyscall=emulate"` if you are having # For example, use `kernel_params = "vsyscall=emulate"` if you are having

View File

@ -535,6 +535,7 @@ func newFirecrackerHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
HypervisorPath: hypervisor, HypervisorPath: hypervisor,
HypervisorPathList: h.HypervisorPathList, HypervisorPathList: h.HypervisorPathList,
JailerPath: jailer, JailerPath: jailer,
JailerPathList: h.JailerPathList,
KernelPath: kernel, KernelPath: kernel,
InitrdPath: initrd, InitrdPath: initrd,
ImagePath: image, ImagePath: image,

View File

@ -284,6 +284,9 @@ type HypervisorConfig struct {
// JailerPath is the jailer executable host path. // JailerPath is the jailer executable host path.
JailerPath string JailerPath string
// JailerPathList is the list of jailer paths names allowed in annotations
JailerPathList []string
// BlockDeviceDriver specifies the driver to be used for block device // BlockDeviceDriver specifies the driver to be used for block device
// either VirtioSCSI or VirtioBlock with the default driver being defaultBlockDriver // either VirtioSCSI or VirtioBlock with the default driver being defaultBlockDriver
BlockDeviceDriver string BlockDeviceDriver string

View File

@ -215,6 +215,7 @@ func (s *Sandbox) dumpConfig(ss *persistapi.SandboxState) {
HypervisorPathList: sconfig.HypervisorConfig.HypervisorPathList, HypervisorPathList: sconfig.HypervisorConfig.HypervisorPathList,
HypervisorCtlPath: sconfig.HypervisorConfig.HypervisorCtlPath, HypervisorCtlPath: sconfig.HypervisorConfig.HypervisorCtlPath,
JailerPath: sconfig.HypervisorConfig.JailerPath, JailerPath: sconfig.HypervisorConfig.JailerPath,
JailerPathList: sconfig.HypervisorConfig.JailerPathList,
BlockDeviceDriver: sconfig.HypervisorConfig.BlockDeviceDriver, BlockDeviceDriver: sconfig.HypervisorConfig.BlockDeviceDriver,
HypervisorMachineType: sconfig.HypervisorConfig.HypervisorMachineType, HypervisorMachineType: sconfig.HypervisorConfig.HypervisorMachineType,
MemoryPath: sconfig.HypervisorConfig.MemoryPath, MemoryPath: sconfig.HypervisorConfig.MemoryPath,
@ -479,6 +480,7 @@ func loadSandboxConfig(id string) (*SandboxConfig, error) {
HypervisorPathList: hconf.HypervisorPathList, HypervisorPathList: hconf.HypervisorPathList,
HypervisorCtlPath: hconf.HypervisorCtlPath, HypervisorCtlPath: hconf.HypervisorCtlPath,
JailerPath: hconf.JailerPath, JailerPath: hconf.JailerPath,
JailerPathList: hconf.JailerPathList,
BlockDeviceDriver: hconf.BlockDeviceDriver, BlockDeviceDriver: hconf.BlockDeviceDriver,
HypervisorMachineType: hconf.HypervisorMachineType, HypervisorMachineType: hconf.HypervisorMachineType,
MemoryPath: hconf.MemoryPath, MemoryPath: hconf.MemoryPath,

View File

@ -69,6 +69,9 @@ type HypervisorConfig struct {
// JailerPath is the jailer executable host path. // JailerPath is the jailer executable host path.
JailerPath string JailerPath string
// JailerPathList is the list of jailer paths names allowed in annotations
JailerPathList []string
// BlockDeviceDriver specifies the driver to be used for block device // BlockDeviceDriver specifies the driver to be used for block device
// either VirtioSCSI or VirtioBlock with the default driver being defaultBlockDriver // either VirtioSCSI or VirtioBlock with the default driver being defaultBlockDriver
BlockDeviceDriver string BlockDeviceDriver string

View File

@ -398,6 +398,13 @@ func addHypervisorConfigOverrides(ocispec specs.Spec, config *vc.SandboxConfig,
config.HypervisorConfig.HypervisorPath = value config.HypervisorConfig.HypervisorPath = value
} }
if value, ok := ocispec.Annotations[vcAnnotations.JailerPath]; ok {
if !regexpContains(runtime.HypervisorConfig.JailerPathList, value) {
return fmt.Errorf("jailer %v required from annotation is not valid", value)
}
config.HypervisorConfig.JailerPath = value
}
if value, ok := ocispec.Annotations[vcAnnotations.KernelParams]; ok { if value, ok := ocispec.Annotations[vcAnnotations.KernelParams]; ok {
if value != "" { if value != "" {
params := vc.DeserializeParams(strings.Fields(value)) params := vc.DeserializeParams(strings.Fields(value))