diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-10-20 13:10:04 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-10-21 10:22:10 +0200 |
| commit | cc97498cfe89a38b9837444d5b00b73b67ebdaa6 (patch) | |
| tree | bfbfff5d4043ba6518640fd8a9eac90656801060 /tools/syz-kconf | |
| parent | 9c36bbb03e89295439ece94f5648253e0b8573d0 (diff) | |
tools/syz-kconf: don't enable configs implicitly
Currenty we run oldconfig and set all missing configs to their
default values. Sometimes this enables configs implicitly/unintentionally.
Set all missing configs to "is not set" proactively to prevent
using default values.
Also replace oldconfig with olddefconfig.
I assumed oldconfig sets missing values to "is not set",
but it does not. It does the same as olddefconfig without stdin.
Update #2171
Diffstat (limited to 'tools/syz-kconf')
| -rw-r--r-- | tools/syz-kconf/kconf.go | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/tools/syz-kconf/kconf.go b/tools/syz-kconf/kconf.go index 97b28f79a..02ce0e929 100644 --- a/tools/syz-kconf/kconf.go +++ b/tools/syz-kconf/kconf.go @@ -58,6 +58,7 @@ func main() { fail(err) } // In order to speed up the process we generate instances that use the same kernel revision in parallel. + failed := false generated := make(map[string]bool) for _, inst := range instances { // Find the first instance that we did not generate yet. @@ -105,10 +106,14 @@ func main() { } for i := 0; i < batch; i++ { if err := <-results; err != nil { - fail(err) + fmt.Printf("%v\n", err) + failed = true } } } + if failed { + failf("some configs failed") + } if len(generated) == 0 { failf("unknown instance name") } @@ -155,18 +160,34 @@ func (ctx *Context) generate() error { } ctx.applyConfigs(cf) cf.ModToYes() + // Set all configs that are not present (actually not present, rather than "is not set") to "is not set". + // This avoids olddefconfig turning on random things we did not ask for. + for _, cfg := range ctx.Kconf.Configs { + if (cfg.Type == kconfig.TypeTristate || cfg.Type == kconfig.TypeBool) && cf.Map[cfg.Name] == nil { + cf.Set(cfg.Name, kconfig.No) + } + } original := cf.Serialize() if err := osutil.WriteFile(configFile, original); err != nil { return fmt.Errorf("failed to write .config file: %v", err) } - if err := ctx.Make("oldconfig"); err != nil { + // Save what we've got before olddefconfig for debugging purposes, it allows to see if we did not set a config, + // or olddefconfig removed it. Save as .tmp so that it's not checked-in accidentially. + outputFile := filepath.Join(ctx.ConfigDir, ctx.Inst.Name+".config") + outputFileTmp := outputFile + ".tmp" + if err := osutil.WriteFile(outputFileTmp, original); err != nil { + return fmt.Errorf("failed to write tmp config file: %v", err) + } + if err := ctx.Make("olddefconfig"); err != nil { return err } cf, err = kconfig.ParseConfig(configFile) if err != nil { return err } - verifyErr := ctx.verifyConfigs(cf) + if err := ctx.verifyConfigs(cf); err != nil { + return fmt.Errorf("%vsaved config before olddefconfig to %v", err, outputFileTmp) + } cf.ModToNo() config := []byte(fmt.Sprintf(`# Automatically generated by syz-kconf; DO NOT EDIT. # Kernel: %v %v @@ -175,15 +196,6 @@ func (ctx *Context) generate() error { %s `, ctx.Inst.Kernel.Repo, ctx.Inst.Kernel.Tag, cf.Serialize(), ctx.Inst.Verbatim)) - outputFile := filepath.Join(ctx.ConfigDir, ctx.Inst.Name+".config") - if verifyErr != nil { - // Write bad config for debugging with .tmp suffix so that it's not checked-in accidentially. - outputFile += ".tmp" - if err := osutil.WriteFile(outputFile, original); err != nil { - return fmt.Errorf("failed to write output file: %v", err) - } - return fmt.Errorf("%vsaved config to %v (run oldconfig)", verifyErr, outputFile) - } return osutil.WriteFile(outputFile, config) } @@ -250,7 +262,6 @@ func (ctx *Context) addUSBConfigs(cf *kconfig.ConfigFile) error { distroConfig := filepath.Join(ctx.ConfigDir, "distros", android+"*") // Some USB drivers don't depend on any USB related symbols, but rather on a generic symbol // for some input subsystem (e.g. HID), so include it as well. - // TODO: don't include HID, it does not seem to add anything relevant. return ctx.addDependentConfigs(cf, []string{"USB_SUPPORT", "HID"}, distroConfig) } |
