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

Commit 94076a6

Browse files
c3dfidencio
authored andcommitted
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: #3004 Signed-off-by: Christophe de Dinechin <[email protected]>
1 parent 14ef4df commit 94076a6

File tree

6 files changed

+20
-0
lines changed

6 files changed

+20
-0
lines changed

cli/config/configuration-fc.toml.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ image = "@IMAGEPATH@"
2727
# for this feature today.
2828
#jailer_path = "@FCJAILERPATH@"
2929

30+
# List of valid jailer path values for the hypervisor (default: empty)
31+
# Each member of the list can be a regular expression
32+
# jailer_path_list = [ "@FCJAILERPATH@.*" ]
33+
3034

3135
# Optional space-separated list of options to pass to the guest kernel.
3236
# For example, use `kernel_params = "vsyscall=emulate"` if you are having

pkg/katautils/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ func newFirecrackerHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
543543
HypervisorPath: hypervisor,
544544
HypervisorPathList: h.HypervisorPathList,
545545
JailerPath: jailer,
546+
JailerPathList: h.JailerPathList,
546547
KernelPath: kernel,
547548
InitrdPath: initrd,
548549
ImagePath: image,

virtcontainers/hypervisor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ type HypervisorConfig struct {
284284
// JailerPath is the jailer executable host path.
285285
JailerPath string
286286

287+
// JailerPathList is the list of jailer paths names allowed in annotations
288+
JailerPathList []string
289+
287290
// BlockDeviceDriver specifies the driver to be used for block device
288291
// either VirtioSCSI or VirtioBlock with the default driver being defaultBlockDriver
289292
BlockDeviceDriver string

virtcontainers/persist.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ func (s *Sandbox) dumpConfig(ss *persistapi.SandboxState) {
225225
HypervisorPathList: sconfig.HypervisorConfig.HypervisorPathList,
226226
HypervisorCtlPath: sconfig.HypervisorConfig.HypervisorCtlPath,
227227
JailerPath: sconfig.HypervisorConfig.JailerPath,
228+
JailerPathList: sconfig.HypervisorConfig.JailerPathList,
228229
BlockDeviceDriver: sconfig.HypervisorConfig.BlockDeviceDriver,
229230
HypervisorMachineType: sconfig.HypervisorConfig.HypervisorMachineType,
230231
MemoryPath: sconfig.HypervisorConfig.MemoryPath,
@@ -516,6 +517,7 @@ func loadSandboxConfig(id string) (*SandboxConfig, error) {
516517
HypervisorPathList: hconf.HypervisorPathList,
517518
HypervisorCtlPath: hconf.HypervisorCtlPath,
518519
JailerPath: hconf.JailerPath,
520+
JailerPathList: hconf.JailerPathList,
519521
BlockDeviceDriver: hconf.BlockDeviceDriver,
520522
HypervisorMachineType: hconf.HypervisorMachineType,
521523
MemoryPath: hconf.MemoryPath,

virtcontainers/persist/api/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ type HypervisorConfig struct {
6666
// JailerPath is the jailer executable host path.
6767
JailerPath string
6868

69+
// JailerPathList is the list of jailer paths names allowed in annotations
70+
JailerPathList []string
71+
6972
// BlockDeviceDriver specifies the driver to be used for block device
7073
// either VirtioSCSI or VirtioBlock with the default driver being defaultBlockDriver
7174
BlockDeviceDriver string

virtcontainers/pkg/oci/utils.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,13 @@ func addHypervisorConfigOverrides(ocispec specs.Spec, config *vc.SandboxConfig,
404404
config.HypervisorConfig.HypervisorPath = value
405405
}
406406

407+
if value, ok := ocispec.Annotations[vcAnnotations.JailerPath]; ok {
408+
if !regexpContains(runtime.HypervisorConfig.JailerPathList, value) {
409+
return fmt.Errorf("jailer %v required from annotation is not valid", value)
410+
}
411+
config.HypervisorConfig.JailerPath = value
412+
}
413+
407414
if value, ok := ocispec.Annotations[vcAnnotations.KernelParams]; ok {
408415
if value != "" {
409416
params := vc.DeserializeParams(strings.Fields(value))

0 commit comments

Comments
 (0)