aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/build
diff options
context:
space:
mode:
authorSabyrzhan Tasbolatov <snovitoll@gmail.com>2024-09-17 01:10:32 +0500
committerDmitry Vyukov <dvyukov@google.com>2024-09-23 08:03:41 +0000
commit49f9c2d289d546c97aae87130574abe5b963b72a (patch)
treeff45b7339ce694a523b3df2a657bebd4f1510557 /pkg/build
parent6f888b7530906167ecb1f5a35e060fec736d6d32 (diff)
pkg/build: handle OOM-killed build error
Handle SIGKILL (exit code = 137) on osutil.Run() during Linux kernel image building and return build.InfraError without reporting. Fixes: https://github.com/google/syzkaller/issues/5317
Diffstat (limited to 'pkg/build')
-rw-r--r--pkg/build/build.go20
-rw-r--r--pkg/build/build_test.go49
2 files changed, 68 insertions, 1 deletions
diff --git a/pkg/build/build.go b/pkg/build/build.go
index bb6d089fd..ec47822a6 100644
--- a/pkg/build/build.go
+++ b/pkg/build/build.go
@@ -131,6 +131,18 @@ func (err *KernelError) Error() string {
return string(err.Report)
}
+type InfraError struct {
+ Title string
+ Output []byte
+}
+
+func (e InfraError) Error() string {
+ if len(e.Output) > 0 {
+ return fmt.Sprintf("%s: %s", e.Title, e.Output)
+ }
+ return e.Title
+}
+
type builder interface {
build(params Params) (ImageDetails, error)
clean(kernelDir, targetArch string) error
@@ -208,6 +220,13 @@ func extractRootCause(err error, OS, kernelSrc string) error {
if len(reason) == 0 {
return err
}
+ // Don't report upon SIGKILL for Linux builds.
+ if OS == targets.Linux && string(reason) == "Killed" && verr.ExitCode == 137 {
+ return &InfraError{
+ Title: string(reason),
+ Output: verr.Output,
+ }
+ }
kernelErr := &KernelError{
Report: reason,
Output: verr.Output,
@@ -313,6 +332,7 @@ var buildFailureCauses = [...]buildFailureCause{
{pattern: regexp.MustCompile(`^([a-zA-Z0-9_\-/.]+):[0-9]+:([0-9]+:)?.*(error|invalid|fatal|wrong)`)},
{pattern: regexp.MustCompile(`FAILED unresolved symbol`)},
{pattern: regexp.MustCompile(`No rule to make target`)},
+ {pattern: regexp.MustCompile(`^Killed$`)},
{weak: true, pattern: regexp.MustCompile(`: not found`)},
{weak: true, pattern: regexp.MustCompile(`: final link failed: `)},
{weak: true, pattern: regexp.MustCompile(`collect2: error: `)},
diff --git a/pkg/build/build_test.go b/pkg/build/build_test.go
index c89f63151..6aa9d9216 100644
--- a/pkg/build/build_test.go
+++ b/pkg/build/build_test.go
@@ -8,6 +8,10 @@ import (
"os/exec"
"strings"
"testing"
+
+ "github.com/google/syzkaller/pkg/osutil"
+ "github.com/google/syzkaller/sys/targets"
+ "github.com/stretchr/testify/assert"
)
func TestCompilerIdentity(t *testing.T) {
@@ -36,7 +40,7 @@ func TestCompilerIdentity(t *testing.T) {
}
}
-func TestExtractRootCause(t *testing.T) {
+func TestExtractCauseInner(t *testing.T) {
for i, test := range rootCauseTests {
test := test
t.Run(fmt.Sprint(i), func(t *testing.T) {
@@ -51,6 +55,36 @@ func TestExtractRootCause(t *testing.T) {
}
}
+func TestExtractRootCause(t *testing.T) {
+ targetOs := targets.TestOS
+ for i, test := range rootCauseTests {
+ var expected error
+ err := &osutil.VerboseError{Output: []byte(test.e)}
+ if test.reason == "" {
+ continue
+ } else if test.reason == "Killed" {
+ err.ExitCode = 137
+ targetOs = targets.Linux
+ expected = &InfraError{
+ Title: test.reason,
+ Output: err.Output,
+ }
+ } else {
+ expected = &KernelError{
+ Report: []byte(test.reason),
+ Output: err.Output,
+ guiltyFile: test.file,
+ }
+ }
+ t.Run(fmt.Sprint(i), func(t *testing.T) {
+ got := extractRootCause(err, targetOs, test.src)
+ if got != nil {
+ assert.Equal(t, expected, got)
+ }
+ })
+ }
+}
+
type RootCauseTest struct {
e string
reason string
@@ -546,4 +580,17 @@ ninja: build stopped: subcommand failed.
"",
"",
},
+ {`
+ AR built-in.a
+ AR vmlinux.a
+ LD vmlinux.o
+Killed
+make[1]: *** [scripts/Makefile.vmlinux_o:61: vmlinux.o] Error 137
+make[1]: *** Deleting file 'vmlinux.o'
+make: *** [Makefile:1231: vmlinux_o] Error 2
+`,
+ "Killed",
+ "",
+ "",
+ },
}