From e46390ef02fc48613bdcbaa50910f7ec44d10ee5 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 13 Dec 2021 10:33:24 +0100 Subject: sys/targets: fix race in setCompiler make configs triggers the following race. Always initialize the main target before initializing the alternative target, otherwise they both read/modify CFlags. ================== WARNING: DATA RACE Write at 0x00c00027b700 by goroutine 102: github.com/google/syzkaller/sys/targets.(*Target).setCompiler() sys/targets/targets.go:749 +0x7c9 github.com/google/syzkaller/sys/targets.GetEx.func1() sys/targets/targets.go:158 +0xb9 sync.(*Once).doSlow() /usr/local/go/src/sync/once.go:68 +0x127 sync.(*Once).Do() /usr/local/go/src/sync/once.go:59 +0x46 github.com/google/syzkaller/sys/targets.GetEx() sys/targets/targets.go:155 +0x184 main.(*Context).setTarget() tools/syz-kconf/kconf.go:360 +0x244 main.(*Context).generate() tools/syz-kconf/kconf.go:171 +0x17e main.main.func1() tools/syz-kconf/kconf.go:97 +0x4e Previous read at 0x00c00027b700 by goroutine 97: runtime.slicecopy() /usr/local/go/src/runtime/slice.go:284 +0x0 github.com/google/syzkaller/sys/targets.(*Target).lazyInit() sys/targets/targets.go:796 +0x464 github.com/google/syzkaller/sys/targets.(*Target).lazyInit-fm() sys/targets/targets.go:782 +0x39 sync.(*Once).doSlow() /usr/local/go/src/sync/once.go:68 +0x127 sync.(*Once).Do() /usr/local/go/src/sync/once.go:59 +0x46 github.com/google/syzkaller/sys/targets.GetEx() sys/targets/targets.go:152 +0x127 main.(*Context).setTarget() tools/syz-kconf/kconf.go:360 +0x244 main.(*Context).generate() tools/syz-kconf/kconf.go:171 +0x17e main.main.func1() tools/syz-kconf/kconf.go:97 +0x4e Goroutine 102 (running) created at: main.main() tools/syz-kconf/kconf.go:96 +0x1184 Goroutine 97 (running) created at: main.main() tools/syz-kconf/kconf.go:96 +0x1184 ================== --- sys/targets/targets.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sys/targets') diff --git a/sys/targets/targets.go b/sys/targets/targets.go index 2f696b4b3..65b258ccb 100644 --- a/sys/targets/targets.go +++ b/sys/targets/targets.go @@ -148,8 +148,8 @@ func GetEx(OS, arch string, clang bool) *Target { if target == nil { return nil } + target.init.Do(target.lazyInit) if clang == useClang { - target.init.Do(target.lazyInit) return target } target.initOther.Do(func() { -- cgit mrf-deployment