From 0b3dad4606c0984ce2d81ba5dd698fa248ce91b8 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 3 May 2024 10:16:58 +0200 Subject: pkg/vminfo: move feature checking to host Feature checking procedure is split into 2 phases: 1. syz-fuzzer invokes "syz-executor setup feature" for each feature one-by-one, and checks if executor does not fail. Executor can also return a special "this feature does not need custom setup", this allows to not call setup of these features in each new VM. 2. pkg/vminfo runs a simple program with ipc.ExecOpts specific for a concrete feature, e.g. for wifi injection it will try to run a program with wifi feature enabled, if setup of the feature fails, executor should also exit with an error. For coverage features we also additionally check that we actually got coverage. Then pkg/vminfo combines results of these 2 checks into final result. syz-execprog now also uses vminfo package and mimics the same checking procedure. Update #1541 --- pkg/ipc/ipc.go | 31 +++++++++++++++++++++++++------ pkg/ipc/ipc_test.go | 2 +- 2 files changed, 26 insertions(+), 7 deletions(-) (limited to 'pkg/ipc') diff --git a/pkg/ipc/ipc.go b/pkg/ipc/ipc.go index 79b2acc18..c83fabe84 100644 --- a/pkg/ipc/ipc.go +++ b/pkg/ipc/ipc.go @@ -159,6 +159,12 @@ func FlagsToSandbox(flags EnvFlags) string { // nolint: gocyclo func FeaturesToFlags(features flatrpc.Feature, manual csource.Features) EnvFlags { + for feat := range flatrpc.EnumNamesFeature { + opt := FlatRPCFeaturesToCSource[feat] + if opt != "" && manual != nil && !manual[opt].Enabled { + features &= ^feat + } + } var flags EnvFlags if manual == nil || manual["net_reset"].Enabled { flags |= FlagEnableNetReset @@ -175,27 +181,40 @@ func FeaturesToFlags(features flatrpc.Feature, manual csource.Features) EnvFlags if features&flatrpc.FeatureDelayKcovMmap != 0 { flags |= FlagDelayKcovMmap } - if features&flatrpc.FeatureNetInjection != 0 && (manual == nil || manual["tun"].Enabled) { + if features&flatrpc.FeatureNetInjection != 0 { flags |= FlagEnableTun } - if features&flatrpc.FeatureNetDevices != 0 && (manual == nil || manual["net_dev"].Enabled) { + if features&flatrpc.FeatureNetDevices != 0 { flags |= FlagEnableNetDev } - if features&flatrpc.FeatureDevlinkPCI != 0 && (manual == nil || manual["devlink_pci"].Enabled) { + if features&flatrpc.FeatureDevlinkPCI != 0 { flags |= FlagEnableDevlinkPCI } - if features&flatrpc.FeatureNicVF != 0 && (manual == nil || manual["nic_vf"].Enabled) { + if features&flatrpc.FeatureNicVF != 0 { flags |= FlagEnableNicVF } - if features&flatrpc.FeatureVhciInjection != 0 && (manual == nil || manual["vhci"].Enabled) { + if features&flatrpc.FeatureVhciInjection != 0 { flags |= FlagEnableVhciInjection } - if features&flatrpc.FeatureWifiEmulation != 0 && (manual == nil || manual["wifi"].Enabled) { + if features&flatrpc.FeatureWifiEmulation != 0 { flags |= FlagEnableWifi } return flags } +var FlatRPCFeaturesToCSource = map[flatrpc.Feature]string{ + flatrpc.FeatureNetInjection: "tun", + flatrpc.FeatureNetDevices: "net_dev", + flatrpc.FeatureDevlinkPCI: "devlink_pci", + flatrpc.FeatureNicVF: "nic_vf", + flatrpc.FeatureVhciInjection: "vhci", + flatrpc.FeatureWifiEmulation: "wifi", + flatrpc.FeatureUSBEmulation: "usb", + flatrpc.FeatureBinFmtMisc: "binfmt_misc", + flatrpc.FeatureLRWPANEmulation: "ieee802154", + flatrpc.FeatureSwap: "swap", +} + 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/ipc/ipc_test.go b/pkg/ipc/ipc_test.go index 8a8cdfac8..af4eaf24a 100644 --- a/pkg/ipc/ipc_test.go +++ b/pkg/ipc/ipc_test.go @@ -226,7 +226,7 @@ func TestExecutorCommonExt(t *testing.T) { t.Skipf("skipping, broken cross-compiler: %v", sysTarget.BrokenCompiler) } bin := csource.BuildExecutor(t, target, "../..", "-DSYZ_TEST_COMMON_EXT_EXAMPLE=1") - out, err := osutil.RunCmd(time.Minute, "", bin, "setup") + out, err := osutil.RunCmd(time.Minute, "", bin, "setup", "0") if err != nil { t.Fatal(err) } -- cgit mrf-deployment