Merge pull request #7056 from kzys/go118-fuzz
Use Go 1.18's testing.F on simple fuzzers
This commit is contained in:
commit
8aa3459459
@ -1,7 +1,10 @@
|
|||||||
name: CI Fuzz
|
name: Fuzzing
|
||||||
on: [pull_request]
|
on: [pull_request]
|
||||||
jobs:
|
jobs:
|
||||||
Fuzzing:
|
# Run all fuzzing tests. Some of them use Go 1.18's testing.F.
|
||||||
|
# Others use https://github.com/AdaLogics/go-fuzz-headers.
|
||||||
|
ci_fuzz:
|
||||||
|
name: CI Fuzz
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Build Fuzzers
|
- name: Build Fuzzers
|
||||||
@ -24,3 +27,15 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: artifacts
|
name: artifacts
|
||||||
path: ./out/artifacts
|
path: ./out/artifacts
|
||||||
|
|
||||||
|
# Make sure all fuzzing tests which use Go 1.18's testing.F are
|
||||||
|
# runnable with go test -fuzz.
|
||||||
|
go_test_fuzz:
|
||||||
|
name : go test -fuzz
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.18
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- run: script/go-test-fuzz.sh
|
@ -1,28 +0,0 @@
|
|||||||
//go:build gofuzz
|
|
||||||
// +build gofuzz
|
|
||||||
|
|
||||||
/*
|
|
||||||
Copyright The containerd Authors.
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package fuzz
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
|
|
||||||
"github.com/containerd/containerd/pkg/cap"
|
|
||||||
)
|
|
||||||
|
|
||||||
func FuzzParseProcPIDStatus(data []byte) int {
|
|
||||||
_, _ = cap.ParseProcPIDStatus(bytes.NewReader(data))
|
|
||||||
return 1
|
|
||||||
}
|
|
@ -69,16 +69,16 @@ mv $SRC/cmd-containerd-backup $SRC/containerd/cmd/containerd
|
|||||||
mv $SRC/containerd/filters/filter_test.go $SRC/containerd/filters/filter_test_fuzz.go
|
mv $SRC/containerd/filters/filter_test.go $SRC/containerd/filters/filter_test_fuzz.go
|
||||||
go get github.com/AdamKorcz/go-118-fuzz-build/utils
|
go get github.com/AdamKorcz/go-118-fuzz-build/utils
|
||||||
compile_native_go_fuzzer github.com/containerd/containerd/filters FuzzFiltersParse fuzz_filters_parse
|
compile_native_go_fuzzer github.com/containerd/containerd/filters FuzzFiltersParse fuzz_filters_parse
|
||||||
|
compile_native_go_fuzzer github.com/containerd/containerd/pkg/cap FuzzParseProcPIDStatus fuzz_parse_proc_pid_status
|
||||||
|
compile_native_go_fuzzer github.com/containerd/containerd/platforms FuzzPlatformsParse fuzz_platforms_parse
|
||||||
|
|
||||||
compile_go_fuzzer github.com/containerd/containerd/remotes/docker FuzzFetcher fuzz_fetcher
|
compile_go_fuzzer github.com/containerd/containerd/remotes/docker FuzzFetcher fuzz_fetcher
|
||||||
compile_go_fuzzer github.com/containerd/containerd/remotes/docker FuzzParseDockerRef fuzz_parse_docker_ref
|
compile_go_fuzzer github.com/containerd/containerd/remotes/docker FuzzParseDockerRef fuzz_parse_docker_ref
|
||||||
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzPlatformsParse fuzz_platforms_parse
|
|
||||||
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzApply fuzz_apply
|
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzApply fuzz_apply
|
||||||
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzImportIndex fuzz_import_index
|
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzImportIndex fuzz_import_index
|
||||||
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzCSWalk fuzz_cs_walk
|
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzCSWalk fuzz_cs_walk
|
||||||
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzArchiveExport fuzz_archive_export
|
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzArchiveExport fuzz_archive_export
|
||||||
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzParseAuth fuzz_parse_auth
|
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzParseAuth fuzz_parse_auth
|
||||||
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzParseProcPIDStatus fuzz_parse_proc_pid_status
|
|
||||||
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzImageStore fuzz_image_store
|
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzImageStore fuzz_image_store
|
||||||
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzLeaseManager fuzz_lease_manager
|
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzLeaseManager fuzz_lease_manager
|
||||||
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzContainerStore fuzz_container_store
|
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzContainerStore fuzz_container_store
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
//go:build gofuzz
|
|
||||||
// +build gofuzz
|
|
||||||
|
|
||||||
/*
|
|
||||||
Copyright The containerd Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package fuzz
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/containerd/containerd/platforms"
|
|
||||||
)
|
|
||||||
|
|
||||||
func FuzzPlatformsParse(data []byte) int {
|
|
||||||
_, err := platforms.Parse(string(data))
|
|
||||||
if err != nil {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return 1
|
|
||||||
}
|
|
@ -17,12 +17,70 @@
|
|||||||
package cap
|
package cap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const procPIDStatus = `Name: cat
|
||||||
|
Umask: 0022
|
||||||
|
State: R (running)
|
||||||
|
Tgid: 170065
|
||||||
|
Ngid: 0
|
||||||
|
Pid: 170065
|
||||||
|
PPid: 170064
|
||||||
|
TracerPid: 0
|
||||||
|
Uid: 0 0 0 0
|
||||||
|
Gid: 0 0 0 0
|
||||||
|
FDSize: 64
|
||||||
|
Groups: 0
|
||||||
|
NStgid: 170065
|
||||||
|
NSpid: 170065
|
||||||
|
NSpgid: 170064
|
||||||
|
NSsid: 3784
|
||||||
|
VmPeak: 8216 kB
|
||||||
|
VmSize: 8216 kB
|
||||||
|
VmLck: 0 kB
|
||||||
|
VmPin: 0 kB
|
||||||
|
VmHWM: 676 kB
|
||||||
|
VmRSS: 676 kB
|
||||||
|
RssAnon: 72 kB
|
||||||
|
RssFile: 604 kB
|
||||||
|
RssShmem: 0 kB
|
||||||
|
VmData: 324 kB
|
||||||
|
VmStk: 132 kB
|
||||||
|
VmExe: 20 kB
|
||||||
|
VmLib: 1612 kB
|
||||||
|
VmPTE: 56 kB
|
||||||
|
VmSwap: 0 kB
|
||||||
|
HugetlbPages: 0 kB
|
||||||
|
CoreDumping: 0
|
||||||
|
THP_enabled: 1
|
||||||
|
Threads: 1
|
||||||
|
SigQ: 0/63692
|
||||||
|
SigPnd: 0000000000000000
|
||||||
|
ShdPnd: 0000000000000000
|
||||||
|
SigBlk: 0000000000000000
|
||||||
|
SigIgn: 0000000000000000
|
||||||
|
SigCgt: 0000000000000000
|
||||||
|
CapInh: 0000000000000000
|
||||||
|
CapPrm: 000000ffffffffff
|
||||||
|
CapEff: 000000ffffffffff
|
||||||
|
CapBnd: 000000ffffffffff
|
||||||
|
CapAmb: 0000000000000000
|
||||||
|
NoNewPrivs: 0
|
||||||
|
Seccomp: 0
|
||||||
|
Speculation_Store_Bypass: thread vulnerable
|
||||||
|
Cpus_allowed: 00000000,00000000,00000000,0000000f
|
||||||
|
Cpus_allowed_list: 0-3
|
||||||
|
Mems_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001
|
||||||
|
Mems_allowed_list: 0
|
||||||
|
voluntary_ctxt_switches: 0
|
||||||
|
nonvoluntary_ctxt_switches: 0
|
||||||
|
`
|
||||||
|
|
||||||
func TestCapsList(t *testing.T) {
|
func TestCapsList(t *testing.T) {
|
||||||
assert.Len(t, caps316, 38)
|
assert.Len(t, caps316, 38)
|
||||||
assert.Len(t, caps58, 40)
|
assert.Len(t, caps58, 40)
|
||||||
@ -89,62 +147,6 @@ func TestFromBitmap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseProcPIDStatus(t *testing.T) {
|
func TestParseProcPIDStatus(t *testing.T) {
|
||||||
procPIDStatus := `Name: cat
|
|
||||||
Umask: 0022
|
|
||||||
State: R (running)
|
|
||||||
Tgid: 170065
|
|
||||||
Ngid: 0
|
|
||||||
Pid: 170065
|
|
||||||
PPid: 170064
|
|
||||||
TracerPid: 0
|
|
||||||
Uid: 0 0 0 0
|
|
||||||
Gid: 0 0 0 0
|
|
||||||
FDSize: 64
|
|
||||||
Groups: 0
|
|
||||||
NStgid: 170065
|
|
||||||
NSpid: 170065
|
|
||||||
NSpgid: 170064
|
|
||||||
NSsid: 3784
|
|
||||||
VmPeak: 8216 kB
|
|
||||||
VmSize: 8216 kB
|
|
||||||
VmLck: 0 kB
|
|
||||||
VmPin: 0 kB
|
|
||||||
VmHWM: 676 kB
|
|
||||||
VmRSS: 676 kB
|
|
||||||
RssAnon: 72 kB
|
|
||||||
RssFile: 604 kB
|
|
||||||
RssShmem: 0 kB
|
|
||||||
VmData: 324 kB
|
|
||||||
VmStk: 132 kB
|
|
||||||
VmExe: 20 kB
|
|
||||||
VmLib: 1612 kB
|
|
||||||
VmPTE: 56 kB
|
|
||||||
VmSwap: 0 kB
|
|
||||||
HugetlbPages: 0 kB
|
|
||||||
CoreDumping: 0
|
|
||||||
THP_enabled: 1
|
|
||||||
Threads: 1
|
|
||||||
SigQ: 0/63692
|
|
||||||
SigPnd: 0000000000000000
|
|
||||||
ShdPnd: 0000000000000000
|
|
||||||
SigBlk: 0000000000000000
|
|
||||||
SigIgn: 0000000000000000
|
|
||||||
SigCgt: 0000000000000000
|
|
||||||
CapInh: 0000000000000000
|
|
||||||
CapPrm: 000000ffffffffff
|
|
||||||
CapEff: 000000ffffffffff
|
|
||||||
CapBnd: 000000ffffffffff
|
|
||||||
CapAmb: 0000000000000000
|
|
||||||
NoNewPrivs: 0
|
|
||||||
Seccomp: 0
|
|
||||||
Speculation_Store_Bypass: thread vulnerable
|
|
||||||
Cpus_allowed: 00000000,00000000,00000000,0000000f
|
|
||||||
Cpus_allowed_list: 0-3
|
|
||||||
Mems_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001
|
|
||||||
Mems_allowed_list: 0
|
|
||||||
voluntary_ctxt_switches: 0
|
|
||||||
nonvoluntary_ctxt_switches: 0
|
|
||||||
`
|
|
||||||
res, err := ParseProcPIDStatus(strings.NewReader(procPIDStatus))
|
res, err := ParseProcPIDStatus(strings.NewReader(procPIDStatus))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
expected := map[Type]uint64{
|
expected := map[Type]uint64{
|
||||||
@ -167,3 +169,13 @@ func TestKnown(t *testing.T) {
|
|||||||
caps := Known()
|
caps := Known()
|
||||||
assert.EqualValues(t, caps59, caps)
|
assert.EqualValues(t, caps59, caps)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FuzzParseProcPIDStatus(f *testing.F) {
|
||||||
|
f.Add(procPIDStatus)
|
||||||
|
f.Fuzz(func(t *testing.T, s string) {
|
||||||
|
result, err := ParseProcPIDStatus(bytes.NewReader([]byte(s)))
|
||||||
|
if err != nil && result != nil {
|
||||||
|
t.Errorf("either %+v or %+v must be nil", result, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -364,3 +364,13 @@ func TestParseSelectorInvalid(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FuzzPlatformsParse(f *testing.F) {
|
||||||
|
f.Add("linux/amd64")
|
||||||
|
f.Fuzz(func(t *testing.T, s string) {
|
||||||
|
pf, err := Parse(s)
|
||||||
|
if err != nil && (pf.OS != "" || pf.Architecture != "") {
|
||||||
|
t.Errorf("either %+v or %+v must be nil", err, pf)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
29
script/go-test-fuzz.sh
Executable file
29
script/go-test-fuzz.sh
Executable file
@ -0,0 +1,29 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Copyright The containerd Authors.
|
||||||
|
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
# Running Go 1.18's fuzzing for 30 seconds each. While this would be too
|
||||||
|
# short to acutally find issues, we want to make sure that these fuzzing
|
||||||
|
# tests are not fundamentally broken.
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
fuzztime=30s
|
||||||
|
pkgs=$(git grep 'func Fuzz.*testing\.F' | grep -o '.*\/' | sort | uniq)
|
||||||
|
|
||||||
|
for pkg in $pkgs
|
||||||
|
do
|
||||||
|
go test -fuzz=. ./$pkg -fuzztime=$fuzztime
|
||||||
|
done
|
Loading…
Reference in New Issue
Block a user