diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2019-11-14 17:09:07 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2019-11-16 09:58:54 +0100 |
| commit | 8d85129b3cff7398f5aba861f0049afffb566865 (patch) | |
| tree | 0ba0f3668ca0c0a367276ca164ec321a386614d5 /pkg/host/features.go | |
| parent | b5c36524a29838b0ec9345fc1a07daeebf50c833 (diff) | |
pkg/host: split files into syscalls/features
pkg/host does 2 things: detects supported syscalls and supported features.
There is enough code for each for a separate file.
Diffstat (limited to 'pkg/host/features.go')
| -rw-r--r-- | pkg/host/features.go | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/pkg/host/features.go b/pkg/host/features.go new file mode 100644 index 000000000..8c3945a98 --- /dev/null +++ b/pkg/host/features.go @@ -0,0 +1,100 @@ +// Copyright 2018 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package host + +import ( + "time" + + "github.com/google/syzkaller/pkg/csource" + "github.com/google/syzkaller/pkg/osutil" + "github.com/google/syzkaller/prog" + "github.com/google/syzkaller/sys/targets" +) + +const ( + FeatureCoverage = iota + FeatureComparisons + FeatureExtraCoverage + FeatureSandboxSetuid + FeatureSandboxNamespace + FeatureSandboxAndroidUntrustedApp + FeatureFaultInjection + FeatureLeakChecking + FeatureNetworkInjection + FeatureNetworkDevices + FeatureKCSAN + FeatureDevlinkPCI + numFeatures +) + +type Feature struct { + Name string + Enabled bool + Reason string +} + +type Features [numFeatures]Feature + +var checkFeature [numFeatures]func() string + +func unconditionallyEnabled() string { return "" } + +// Check detects features supported on the host. +// Empty string for a feature means the feature is supported, +// otherwise the string contains the reason why the feature is not supported. +func Check(target *prog.Target) (*Features, error) { + const unsupported = "support is not implemented in syzkaller" + res := &Features{ + FeatureCoverage: {Name: "code coverage", Reason: unsupported}, + FeatureComparisons: {Name: "comparison tracing", Reason: unsupported}, + FeatureExtraCoverage: {Name: "extra coverage", Reason: unsupported}, + FeatureSandboxSetuid: {Name: "setuid sandbox", Reason: unsupported}, + FeatureSandboxNamespace: {Name: "namespace sandbox", Reason: unsupported}, + FeatureSandboxAndroidUntrustedApp: {Name: "Android sandbox", Reason: unsupported}, + FeatureFaultInjection: {Name: "fault injection", Reason: unsupported}, + FeatureLeakChecking: {Name: "leak checking", Reason: unsupported}, + FeatureNetworkInjection: {Name: "net packet injection", Reason: unsupported}, + FeatureNetworkDevices: {Name: "net device setup", Reason: unsupported}, + FeatureKCSAN: {Name: "concurrency sanitizer", Reason: unsupported}, + FeatureDevlinkPCI: {Name: "devlink PCI setup", Reason: unsupported}, + } + if targets.Get(target.OS, target.Arch).HostFuzzer { + return res, nil + } + for n, check := range checkFeature { + if check == nil { + continue + } + if reason := check(); reason == "" { + res[n].Enabled = true + res[n].Reason = "enabled" + } else { + res[n].Reason = reason + } + } + return res, nil +} + +// Setup enables and does any one-time setup for the requested features on the host. +// Note: this can be called multiple times and must be idempotent. +func Setup(target *prog.Target, features *Features, featureFlags csource.Features, executor string) error { + if targets.Get(target.OS, target.Arch).HostFuzzer { + return nil + } + args := []string{"setup"} + if features[FeatureLeakChecking].Enabled { + args = append(args, "leak") + } + if features[FeatureFaultInjection].Enabled { + args = append(args, "fault") + } + if target.OS == "linux" && featureFlags["binfmt_misc"].Enabled { + args = append(args, "binfmt_misc") + } + if features[FeatureKCSAN].Enabled { + args = append(args, "kcsan") + } + _, err := osutil.RunCmd(time.Minute, "", executor, args...) + return err +} |
