Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specconv: Add fuzzer #2864

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.13

require (
github.com/AdaLogics/go-fuzz-headers v0.0.0-20210401092550-0a8691dafd0d
github.com/checkpoint-restore/go-criu/v5 v5.0.0
github.com/cilium/ebpf v0.5.0
github.com/containerd/console v1.0.2
Expand Down
3 changes: 2 additions & 1 deletion 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-20210401092550-0a8691dafd0d h1:oXbCfnomBQyeTWN6RNHmMUrmzyUGLYoF2OOcfkpoCHE=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20210401092550-0a8691dafd0d/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 @@ -103,7 +105,6 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20191115151921-52ab43148777/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
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=
golang.org/x/sys v0.0.0-20210426230700-d19ff857e887 h1:dXfMednGJh/SUUFjTLsWJz3P+TQt9qnR11GgeI3vWKs=
golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
96 changes: 96 additions & 0 deletions libcontainer/specconv/specconv_fuzzer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// +build gofuzz

package specconv
AdamKorcz marked this conversation as resolved.
Show resolved Hide resolved

import (
"io/ioutil"
"os"

"github.com/opencontainers/runc/libcontainer/cgroups/systemd"
"github.com/opencontainers/runc/libcontainer/configs"
"github.com/opencontainers/runc/libcontainer/configs/validate"
"github.com/opencontainers/runtime-spec/specs-go"

gofuzzheaders "github.com/AdaLogics/go-fuzz-headers"
)

func newTestRoot(name string) (string, error) {
dir, err := ioutil.TempDir("", name)
if err != nil {
return "", err
}
if err := os.MkdirAll(dir, 0700); err != nil {
return "", err
}
return dir, nil
}

func Fuzz(data []byte) int {
if len(data) < 30 {
return -1
}
f := gofuzzheaders.NewConsumer(data)
linuxSpec := new(specs.Linux)
err := f.GenerateStruct(linuxSpec)
if err != nil {
return 0
}

// Create spec.Spec
spec := new(specs.Spec)
err = f.GenerateStruct(spec)
if err != nil {
return 0
}
spec.Linux = linuxSpec

// Create CreateOpts
opts := new(CreateOpts)
err = f.GenerateStruct(opts)
if err != nil {
return 0
}
opts.Spec = spec
rootfs, err := newTestRoot("libcontainer")
if err != nil {
return 0
}
config := newTemplateConfig(&fuzzTParam{
rootfs: rootfs,
userns: false,
})
err = f.GenerateStruct(config)
if err != nil {
return 0
}
config.Rootfs = rootfs

// Add network
cn := new(configs.Network)
err = f.GenerateStruct(cn)
if err != nil {
return 0
}

config.Networks = []*configs.Network{cn}

validator := validate.New()
err = validator.Validate(config)
if err != nil {
return 0
}
c, err := CreateCgroupConfig(opts, nil)
if err != nil {
return 0
}

path, err := newTestRoot("fuzzDir")
if err != nil {
return 0
}
um := systemd.NewUnifiedManager(c, path, false)
err = um.Set(config)
err = um.Apply(int(data[0]))
err = um.Destroy()
return 1
}
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