From 1719ee24e741afb177677e9644f1c74aef1060fb Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 15 Jun 2022 10:53:39 +0200 Subject: sys/syz-extract: fix a deadlock The jobs channel needs to have capacity to hold all files from all arches since they may all be queued to the channel at the same time. The bug was introduced in 44a5ca633e ("pkg/ast, pkg/compiler: support per-file metadata"). Restore full channel capacity. Fixes #3197 --- sys/syz-extract/extract.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'sys/syz-extract') diff --git a/sys/syz-extract/extract.go b/sys/syz-extract/extract.go index 117c10e58..c3629ee17 100644 --- a/sys/syz-extract/extract.go +++ b/sys/syz-extract/extract.go @@ -80,7 +80,7 @@ func main() { if extractor == nil { tool.Failf("unknown os: %v", OS) } - arches, err := createArches(OS, archList(OS, *flagArch), flag.Args()) + arches, nfiles, err := createArches(OS, archList(OS, *flagArch), flag.Args()) if err != nil { tool.Fail(err) } @@ -92,7 +92,7 @@ func main() { tool.Fail(err) } - jobC := make(chan interface{}, len(arches)) + jobC := make(chan interface{}, len(arches)+nfiles) for _, arch := range arches { jobC <- arch } @@ -169,26 +169,27 @@ func worker(extractor Extractor, jobC chan interface{}) { } } -func createArches(OS string, archArray, files []string) ([]*Arch, error) { +func createArches(OS string, archArray, files []string) ([]*Arch, int, error) { errBuf := new(bytes.Buffer) eh := func(pos ast.Pos, msg string) { fmt.Fprintf(errBuf, "%v: %v\n", pos, msg) } top := ast.ParseGlob(filepath.Join("sys", OS, "*.txt"), eh) if top == nil { - return nil, fmt.Errorf("%v", errBuf.String()) + return nil, 0, fmt.Errorf("%v", errBuf.String()) } allFiles := compiler.FileList(top, OS, eh) if allFiles == nil { - return nil, fmt.Errorf("%v", errBuf.String()) + return nil, 0, fmt.Errorf("%v", errBuf.String()) } + nfiles := 0 var arches []*Arch for _, archStr := range archArray { buildDir := "" if *flagBuild { dir, err := ioutil.TempDir("", "syzkaller-kernel-build") if err != nil { - return nil, fmt.Errorf("failed to create temp dir: %v", err) + return nil, 0, fmt.Errorf("failed to create temp dir: %v", err) } buildDir = dir } else if *flagBuildDir != "" { @@ -199,7 +200,7 @@ func createArches(OS string, archArray, files []string) ([]*Arch, error) { target := targets.Get(OS, archStr) if target == nil { - return nil, fmt.Errorf("unknown arch: %v", archStr) + return nil, 0, fmt.Errorf("unknown arch: %v", archStr) } arch := &Arch{ @@ -228,8 +229,9 @@ func createArches(OS string, archArray, files []string) ([]*Arch, error) { }) } arches = append(arches, arch) + nfiles += len(arch.files) } - return arches, nil + return arches, nfiles, nil } func archList(OS, arches string) []string { -- cgit mrf-deployment