Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #186 from LiangZhou-CTY/master
Browse files Browse the repository at this point in the history
add support for "sandbox" feature to qemu
  • Loading branch information
Julio Montes authored Jul 23, 2021
2 parents 0173713 + 9518675 commit b507f32
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -2448,6 +2448,9 @@ type Config struct {
// CPUModel is the CPU model to be used by qemu.
CPUModel string

// SeccompSandbox is the qemu function which enables the seccomp feature
SeccompSandbox string

// Machine
Machine Machine

Expand Down Expand Up @@ -2524,6 +2527,13 @@ func (config *Config) appendFDs(fds []*os.File) []int {
return fdInts
}

func (config *Config) appendSeccompSandbox() {
if config.SeccompSandbox != "" {
config.qemuParams = append(config.qemuParams, "-sandbox")
config.qemuParams = append(config.qemuParams, config.SeccompSandbox)
}
}

func (config *Config) appendName() {
if config.Name != "" {
config.qemuParams = append(config.qemuParams, "-name")
Expand Down Expand Up @@ -2877,6 +2887,7 @@ func LaunchQemu(config Config, logger QMPLog) (string, error) {
config.appendPidFile()
config.appendLogFile()
config.appendFwCfg(logger)
config.appendSeccompSandbox()

if err := config.appendCPUs(); err != nil {
return "", err
Expand Down
19 changes: 19 additions & 0 deletions qemu/qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,25 @@ func TestValidPFlash(t *testing.T) {
}
}

func TestBadSeccompSandbox(t *testing.T) {
c := &Config{}
c.appendSeccompSandbox()
if len(c.qemuParams) != 0 {
t.Errorf("Expected empty qemuParams, found %s", c.qemuParams)
}
}

func TestValidSeccompSandbox(t *testing.T) {
c := &Config{}
c.SeccompSandbox = string("on,obsolete=deny")
c.appendSeccompSandbox()
expected := []string{"-sandbox", "on,obsolete=deny"}
ok := reflect.DeepEqual(expected, c.qemuParams)
if !ok {
t.Errorf("Expected %v, found %v", expected, c.qemuParams)
}
}

func TestBadVGA(t *testing.T) {
c := &Config{}
c.appendVGA()
Expand Down

0 comments on commit b507f32

Please sign in to comment.