github-vet / github-vet/rangeloop-pointer-findings
google/syzkaller: sys/syz-sysgen/sysgen.go; 108 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [google/syzkaller](https://www.github.com/google/syzkaller) at [sys/syz-sysgen/sysgen.go](https://github.com/google/syzkaller/blob/79264ae39c1ef4b4875ab67d6f0c8c3e75aa6a34/sys/syz-sysgen/sysgen.go#L72-L179)
Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.
> range-loop variable OS used in defer or goroutine at line 117
[Click here to see the code in its original context.](https://github.com/google/syzkaller/blob/79264ae39c1ef4b4875ab67d6f0c8c3e75aa6a34/sys/syz-sysgen/sysgen.go#L72-L179)
Click here to show the 108 line(s) of Go which triggered the analyzer.
```go
for _, OS := range OSList {
descriptions := ast.ParseGlob(filepath.Join(*srcDir, "sys", OS, "*.txt"), nil)
if descriptions == nil {
os.Exit(1)
}
constFile := compiler.DeserializeConstFile(filepath.Join(*srcDir, "sys", OS, "*.const"), nil)
if constFile == nil {
os.Exit(1)
}
osutil.MkdirAll(filepath.Join(*outDir, "sys", OS, "gen"))
var archs []string
for arch := range targets.List[OS] {
archs = append(archs, arch)
}
sort.Strings(archs)
type Job struct {
Target *targets.Target
OK bool
Errors []string
Unsupported map[string]bool
ArchData ArchData
}
var jobs []*Job
for _, arch := range archs {
jobs = append(jobs, &Job{
Target: targets.List[OS][arch],
})
}
sort.Slice(jobs, func(i, j int) bool {
return jobs[i].Target.Arch < jobs[j].Target.Arch
})
var wg sync.WaitGroup
wg.Add(len(jobs))
for _, job := range jobs {
job := job
go func() {
defer wg.Done()
eh := func(pos ast.Pos, msg string) {
job.Errors = append(job.Errors, fmt.Sprintf("%v: %v\n", pos, msg))
}
consts := constFile.Arch(job.Target.Arch)
top := descriptions
if OS == targets.Linux && (job.Target.Arch == targets.ARM || job.Target.Arch == targets.RiscV64) {
// Hack: KVM is not supported on ARM anymore. On riscv64 it
// is not supported yet but might be in the future.
// Note: syz-extract also ignores this file for arm and
// riscv64.
top = descriptions.Filter(func(n ast.Node) bool {
pos, _, _ := n.Info()
return !strings.HasSuffix(pos.File, "_kvm.txt")
})
}
if OS == targets.TestOS {
constInfo := compiler.ExtractConsts(top, job.Target, eh)
compiler.FabricateSyscallConsts(job.Target, constInfo, consts)
}
prog := compiler.Compile(top, consts, job.Target, eh)
if prog == nil {
return
}
job.Unsupported = prog.Unsupported
sysFile := filepath.Join(*outDir, "sys", OS, "gen", job.Target.Arch+".go")
out := new(bytes.Buffer)
generate(job.Target, prog, consts, out)
rev := hash.String(out.Bytes())
fmt.Fprintf(out, "const revision_%v = %q\n", job.Target.Arch, rev)
writeSource(sysFile, out.Bytes())
job.ArchData = generateExecutorSyscalls(job.Target, prog.Syscalls, rev)
// Don't print warnings, they are printed in syz-check.
job.Errors = nil
job.OK = true
}()
}
writeEmpty(OS)
wg.Wait()
var syscallArchs []ArchData
unsupported := make(map[string]int)
for _, job := range jobs {
if !job.OK {
fmt.Printf("compilation of %v/%v target failed:\n", job.Target.OS, job.Target.Arch)
for _, msg := range job.Errors {
fmt.Print(msg)
}
os.Exit(1)
}
syscallArchs = append(syscallArchs, job.ArchData)
for u := range job.Unsupported {
unsupported[u]++
}
}
data.OSes = append(data.OSes, OSData{
GOOS: OS,
Archs: syscallArchs,
})
for what, count := range unsupported {
if count == len(jobs) {
tool.Failf("%v is unsupported on all arches (typo?)", what)
}
}
}
```
Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.
commit ID: 79264ae39c1ef4b4875ab67d6f0c8c3e75aa6a34
Contributor guide
No contributing guide indexed for this repository
Research direction
Read sys/syz-sysgen/sysgen.go around lines 72-179, starting at the goroutine near line 117, and trace how OS is used inside the closure. Check the generated output workflow for this tool; done means the goroutines use the intended operating-system value and sysgen still produces correct files for every OS.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100