aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-04-18 10:59:34 +0200
committerDmitry Vyukov <dvyukov@google.com>2024-04-30 09:36:03 +0000
commitc142aa8dbff8ac1ecb65cf4ecc90b32a3478967f (patch)
tree4c2466c799a6192b54904f1573cc87a582697867
parentb55e33926118ca417bb0ce0c76ceec7c220f65bc (diff)
pkg/ipc: dedup features to flags conversion
Currently it's duplicated 4 times, dedup it.
-rw-r--r--pkg/ipc/ipc.go41
-rw-r--r--pkg/runtest/run.go27
-rw-r--r--syz-fuzzer/fuzzer.go32
-rw-r--r--syz-fuzzer/testing.go2
-rw-r--r--tools/syz-execprog/execprog.go34
-rw-r--r--tools/syz-stress/stress.go28
6 files changed, 46 insertions, 118 deletions
diff --git a/pkg/ipc/ipc.go b/pkg/ipc/ipc.go
index ebdca1ef8..818c88a84 100644
--- a/pkg/ipc/ipc.go
+++ b/pkg/ipc/ipc.go
@@ -16,6 +16,8 @@ import (
"unsafe"
"github.com/google/syzkaller/pkg/cover"
+ "github.com/google/syzkaller/pkg/csource"
+ "github.com/google/syzkaller/pkg/host"
"github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/pkg/signal"
"github.com/google/syzkaller/prog"
@@ -154,6 +156,45 @@ func FlagsToSandbox(flags EnvFlags) string {
return "none"
}
+// nolint: gocyclo
+func FeaturesToFlags(feat *host.Features, manual csource.Features) EnvFlags {
+ var flags EnvFlags
+ if manual == nil || manual["net_reset"].Enabled {
+ flags |= FlagEnableNetReset
+ }
+ if manual == nil || manual["cgroups"].Enabled {
+ flags |= FlagEnableCgroups
+ }
+ if manual == nil || manual["close_fds"].Enabled {
+ flags |= FlagEnableCloseFds
+ }
+ if feat[host.FeatureExtraCoverage].Enabled {
+ flags |= FlagExtraCover
+ }
+ if feat[host.FeatureDelayKcovMmap].Enabled {
+ flags |= FlagDelayKcovMmap
+ }
+ if feat[host.FeatureNetInjection].Enabled && (manual == nil || manual["tun"].Enabled) {
+ flags |= FlagEnableTun
+ }
+ if feat[host.FeatureNetDevices].Enabled && (manual == nil || manual["net_dev"].Enabled) {
+ flags |= FlagEnableNetDev
+ }
+ if feat[host.FeatureDevlinkPCI].Enabled && (manual == nil || manual["devlink_pci"].Enabled) {
+ flags |= FlagEnableDevlinkPCI
+ }
+ if feat[host.FeatureNicVF].Enabled && (manual == nil || manual["nic_vf"].Enabled) {
+ flags |= FlagEnableNicVF
+ }
+ if feat[host.FeatureVhciInjection].Enabled && (manual == nil || manual["vhci"].Enabled) {
+ flags |= FlagEnableVhciInjection
+ }
+ if feat[host.FeatureWifiEmulation].Enabled && (manual == nil || manual["wifi"].Enabled) {
+ flags |= FlagEnableWifi
+ }
+ return flags
+}
+
func MakeEnv(config *Config, pid int) (*Env, error) {
if config.Timeouts.Slowdown == 0 || config.Timeouts.Scale == 0 ||
config.Timeouts.Syscall == 0 || config.Timeouts.Program == 0 {
diff --git a/pkg/runtest/run.go b/pkg/runtest/run.go
index 9e111377d..5c00bf982 100644
--- a/pkg/runtest/run.go
+++ b/pkg/runtest/run.go
@@ -419,32 +419,7 @@ func (ctx *Context) createSyzTest(p *prog.Prog, sandbox string, threaded, cov bo
opts.ExecFlags |= ipc.FlagCollectSignal
opts.ExecFlags |= ipc.FlagCollectCover
}
- if ctx.Features[host.FeatureExtraCoverage].Enabled {
- opts.EnvFlags |= ipc.FlagExtraCover
- }
- if ctx.Features[host.FeatureDelayKcovMmap].Enabled {
- opts.EnvFlags |= ipc.FlagDelayKcovMmap
- }
- if ctx.Features[host.FeatureNetInjection].Enabled {
- opts.EnvFlags |= ipc.FlagEnableTun
- }
- if ctx.Features[host.FeatureNetDevices].Enabled {
- opts.EnvFlags |= ipc.FlagEnableNetDev
- }
- opts.EnvFlags |= ipc.FlagEnableNetReset
- opts.EnvFlags |= ipc.FlagEnableCgroups
- if ctx.Features[host.FeatureDevlinkPCI].Enabled {
- opts.EnvFlags |= ipc.FlagEnableDevlinkPCI
- }
- if ctx.Features[host.FeatureNicVF].Enabled {
- opts.EnvFlags |= ipc.FlagEnableNicVF
- }
- if ctx.Features[host.FeatureVhciInjection].Enabled {
- opts.EnvFlags |= ipc.FlagEnableVhciInjection
- }
- if ctx.Features[host.FeatureWifiEmulation].Enabled {
- opts.EnvFlags |= ipc.FlagEnableWifi
- }
+ opts.EnvFlags |= ipc.FeaturesToFlags(ctx.Features, nil)
if ctx.Debug {
opts.EnvFlags |= ipc.FlagDebug
}
diff --git a/syz-fuzzer/fuzzer.go b/syz-fuzzer/fuzzer.go
index abee43107..9d3b2fcbe 100644
--- a/syz-fuzzer/fuzzer.go
+++ b/syz-fuzzer/fuzzer.go
@@ -59,36 +59,6 @@ type executionResult struct {
info *ipc.ProgInfo
}
-func createIPCConfig(features *host.Features, opts *ipc.ExecOpts) {
- if features[host.FeatureExtraCoverage].Enabled {
- opts.EnvFlags |= ipc.FlagExtraCover
- }
- if features[host.FeatureDelayKcovMmap].Enabled {
- opts.EnvFlags |= ipc.FlagDelayKcovMmap
- }
- if features[host.FeatureNetInjection].Enabled {
- opts.EnvFlags |= ipc.FlagEnableTun
- }
- if features[host.FeatureNetDevices].Enabled {
- opts.EnvFlags |= ipc.FlagEnableNetDev
- }
- opts.EnvFlags |= ipc.FlagEnableNetReset
- opts.EnvFlags |= ipc.FlagEnableCgroups
- opts.EnvFlags |= ipc.FlagEnableCloseFds
- if features[host.FeatureDevlinkPCI].Enabled {
- opts.EnvFlags |= ipc.FlagEnableDevlinkPCI
- }
- if features[host.FeatureNicVF].Enabled {
- opts.EnvFlags |= ipc.FlagEnableNicVF
- }
- if features[host.FeatureVhciInjection].Enabled {
- opts.EnvFlags |= ipc.FlagEnableVhciInjection
- }
- if features[host.FeatureWifiEmulation].Enabled {
- opts.EnvFlags |= ipc.FlagEnableWifi
- }
-}
-
// Gate size controls how deep in the log the last executed by every proc
// program may be. The intent is to make sure that, given the output log,
// we always understand what was happening.
@@ -218,7 +188,7 @@ func main() {
for _, feat := range r.Features.Supported() {
log.Logf(0, "%v: %v", feat.Name, feat.Reason)
}
- createIPCConfig(r.Features, execOpts)
+ execOpts.EnvFlags |= ipc.FeaturesToFlags(r.Features, nil)
if *flagRunTest {
runTest(target, manager, *flagName, config.Executor)
diff --git a/syz-fuzzer/testing.go b/syz-fuzzer/testing.go
index 78d1be585..92c15b5e2 100644
--- a/syz-fuzzer/testing.go
+++ b/syz-fuzzer/testing.go
@@ -144,7 +144,7 @@ func checkMachine(args *checkArgs) (*rpctype.CheckArgs, error) {
args.ipcExecOpts.EnvFlags&ipc.FlagSandboxAndroid != 0 {
return nil, fmt.Errorf("sandbox=android is not supported (%v)", feat.Reason)
}
- createIPCConfig(features, args.ipcExecOpts)
+ args.ipcExecOpts.EnvFlags |= ipc.FeaturesToFlags(features, nil)
if err := checkSimpleProgram(args, features); err != nil {
return nil, err
}
diff --git a/tools/syz-execprog/execprog.go b/tools/syz-execprog/execprog.go
index 5d68dd2dd..9cfebf15b 100644
--- a/tools/syz-execprog/execprog.go
+++ b/tools/syz-execprog/execprog.go
@@ -375,38 +375,6 @@ func createConfig(target *prog.Target, features *host.Features, featuresFlags cs
}
execOpts.ExecFlags |= ipc.FlagCollectComps
}
- if features[host.FeatureExtraCoverage].Enabled {
- execOpts.EnvFlags |= ipc.FlagExtraCover
- }
- if features[host.FeatureDelayKcovMmap].Enabled {
- execOpts.EnvFlags |= ipc.FlagDelayKcovMmap
- }
- if featuresFlags["tun"].Enabled && features[host.FeatureNetInjection].Enabled {
- execOpts.EnvFlags |= ipc.FlagEnableTun
- }
- if featuresFlags["net_dev"].Enabled && features[host.FeatureNetDevices].Enabled {
- execOpts.EnvFlags |= ipc.FlagEnableNetDev
- }
- if featuresFlags["net_reset"].Enabled {
- execOpts.EnvFlags |= ipc.FlagEnableNetReset
- }
- if featuresFlags["cgroups"].Enabled {
- execOpts.EnvFlags |= ipc.FlagEnableCgroups
- }
- if featuresFlags["close_fds"].Enabled {
- execOpts.EnvFlags |= ipc.FlagEnableCloseFds
- }
- if featuresFlags["devlink_pci"].Enabled && features[host.FeatureDevlinkPCI].Enabled {
- execOpts.EnvFlags |= ipc.FlagEnableDevlinkPCI
- }
- if featuresFlags["nic_vf"].Enabled && features[host.FeatureNicVF].Enabled {
- execOpts.EnvFlags |= ipc.FlagEnableNicVF
- }
- if featuresFlags["vhci"].Enabled && features[host.FeatureVhciInjection].Enabled {
- execOpts.EnvFlags |= ipc.FlagEnableVhciInjection
- }
- if featuresFlags["wifi"].Enabled && features[host.FeatureWifiEmulation].Enabled {
- execOpts.EnvFlags |= ipc.FlagEnableWifi
- }
+ execOpts.EnvFlags |= ipc.FeaturesToFlags(features, featuresFlags)
return config, execOpts
}
diff --git a/tools/syz-stress/stress.go b/tools/syz-stress/stress.go
index 8396148e2..080c8615e 100644
--- a/tools/syz-stress/stress.go
+++ b/tools/syz-stress/stress.go
@@ -150,33 +150,7 @@ func createIPCConfig(target *prog.Target, features *host.Features, featuresFlags
if err != nil {
return nil, nil, err
}
- if featuresFlags["tun"].Enabled && features[host.FeatureNetInjection].Enabled {
- execOpts.EnvFlags |= ipc.FlagEnableTun
- }
- if featuresFlags["net_dev"].Enabled && features[host.FeatureNetDevices].Enabled {
- execOpts.EnvFlags |= ipc.FlagEnableNetDev
- }
- if featuresFlags["net_reset"].Enabled {
- execOpts.EnvFlags |= ipc.FlagEnableNetReset
- }
- if featuresFlags["cgroups"].Enabled {
- execOpts.EnvFlags |= ipc.FlagEnableCgroups
- }
- if featuresFlags["close_fds"].Enabled {
- execOpts.EnvFlags |= ipc.FlagEnableCloseFds
- }
- if featuresFlags["devlink_pci"].Enabled && features[host.FeatureDevlinkPCI].Enabled {
- execOpts.EnvFlags |= ipc.FlagEnableDevlinkPCI
- }
- if featuresFlags["nic_vf"].Enabled && features[host.FeatureNicVF].Enabled {
- execOpts.EnvFlags |= ipc.FlagEnableNicVF
- }
- if featuresFlags["vhci"].Enabled && features[host.FeatureVhciInjection].Enabled {
- execOpts.EnvFlags |= ipc.FlagEnableVhciInjection
- }
- if featuresFlags["wifi"].Enabled && features[host.FeatureWifiEmulation].Enabled {
- execOpts.EnvFlags |= ipc.FlagEnableWifi
- }
+ execOpts.EnvFlags |= ipc.FeaturesToFlags(features, featuresFlags)
return config, execOpts, nil
}