Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
Signed-off-by: AdamKorcz <adam@adalogics.com>
  • Loading branch information
AdamKorcz committed Apr 5, 2021
1 parent bed4d89 commit b3d3489
Show file tree
Hide file tree
Showing 9 changed files with 524 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/opencontainers/runc
go 1.14

require (
github.com/AdaLogics/go-fuzz-headers v0.0.0-20210330150358-dbd898e17899
github.com/checkpoint-restore/go-criu/v5 v5.0.0
github.com/cilium/ebpf v0.2.0
github.com/containerd/console v1.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20210330150358-dbd898e17899 h1:Cm0cjER/2C+3BEuRBARZ+1HG+jwU5jbVkYysA7zE2H8=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20210330150358-dbd898e17899/go.mod h1:CzsSbkDixRphAF5hS6wbMKq0eI6ccJRb7/A0M6JBnwg=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/checkpoint-restore/go-criu/v5 v5.0.0 h1:TW8f/UvntYoVDMN1K2HlT82qH1rb0sOjpGw3m6Ym+i4=
Expand Down Expand Up @@ -97,7 +99,6 @@ golang.org/x/sys v0.0.0-20191115151921-52ab43148777/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200916030750-2334cc1a136f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -125,7 +126,6 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
Expand Down
96 changes: 96 additions & 0 deletions libcontainer/libcontainer_fuzzer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// +build gofuzz

package libcontainer

import (
"os"

gofuzzheaders "github.com/AdaLogics/go-fuzz-headers"
"github.com/opencontainers/runc/libcontainer/configs"
"github.com/sirupsen/logrus"
)

func FuzzStateApi(data []byte) int {
// We do not want any log output:
logrus.SetLevel(logrus.PanicLevel)

if len(data) < 4 {
return -1
}

// Create the root dir:
root, err := newTestRoot()
if err != nil {
return -1
}
defer os.RemoveAll(root)

// Create a fuzzconsumer for later user
c := gofuzzheaders.NewConsumer(data)

// Create a config
config := new(configs.Config)
c.GenerateStruct(config)
config.Rootfs = root

// Add Namespaces:
ns, err := c.GetInt()
if err != nil {
return -1
}
if (ns % 3) == 0 {
config.Namespaces = configs.Namespaces(
[]configs.Namespace{
{Type: configs.NEWUTS},
},
)
} else if (ns % 4) == 0 {
config.Namespaces = configs.Namespaces(
[]configs.Namespace{
{Type: configs.NEWNS},
},
)
} else {
config.Namespaces = []configs.Namespace{}
}

// Create container:
containerName, err := c.GetString()
if err != nil {
return 0
}
container, err := newContainerWithName(containerName, root, config)
if err != nil {
return 0
}
defer container.Destroy()

// Fuzz container APIs:
_, _ = container.State()
_, _ = container.Stats()
_, _ = container.OCIState()
_, _ = container.Processes()
return 1
}

func newContainerWithName(name, root string, config *configs.Config) (Container, error) {
f, err := New(root, Cgroupfs)
if err != nil {
return nil, err
}
if config.Cgroups != nil && config.Cgroups.Parent == "system.slice" {
f, err = New(root, SystemdCgroups)
if err != nil {
return nil, err
}
}
return f.Create(name, config)
}

func newTestRoot() (string, error) {
dir := "/tmp/fuzzing"
if err := os.MkdirAll(dir, 0700); err != nil {
return "", err
}
return dir, nil
}
4 changes: 4 additions & 0 deletions tests/fuzzing/oss_fuzz_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
compile_go_fuzzer ./libcontainer/system FuzzUIDMap id_map_fuzzer linux
compile_go_fuzzer ./libcontainer/user FuzzUser user_fuzzer
compile_go_fuzzer ./libcontainer/configs FuzzUnmarshalJSON configs_fuzzer
compile_go_fuzzer ./libcontainer FuzzStateApi state_api_fuzzer

zip $OUT/state_api_fuzzer_seed_corpus.zip $SRC/runc/tests/fuzzing/corpus/state_fuzzer_seed_1
mv $SRC/runc/tests/fuzzing/dictionaries/state_api_fuzzer.dict $OUT/
201 changes: 201 additions & 0 deletions vendor/github.com/AdaLogics/go-fuzz-headers/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions vendor/github.com/AdaLogics/go-fuzz-headers/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b3d3489

Please sign in to comment.