aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorGeorge Kennedy <george.kennedy@oracle.com>2022-09-13 15:53:09 +0000
committerAleksandr Nogikh <wp32pw@gmail.com>2022-09-21 11:46:22 +0200
commit84a66e8e4f8324de38eb230b5e2539570b4d05a5 (patch)
tree454fe315bd0db53913128d99516201ac606addf1 /pkg
parent799171eb67633beabfe4f86022c58de3a796f1b4 (diff)
executor: add NIC PCI pass-through VF support
Add support for moving a NIC PCI pass-through VF into Syzkaller's network namespace so that it will tested. As DEVLINK support is triggered by setting the pass-through device to "addr=0x10", NIC PCI pass-through VF support will be triggered by setting the device to "addr=0x11". If a NIC PCI pass-through VF is detected in do_sandbox, setup a staging namespace before the fork() and transfer the NIC VF interface to it. After the fork() and in the child transfer the NIC VF interface to Syzkaller's network namespace and rename the interface to netpci0 so that it will be tested. Signed-off-by: George Kennedy <george.kennedy@oracle.com>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/csource/common.go1
-rw-r--r--pkg/csource/options.go4
-rw-r--r--pkg/csource/options_test.go4
-rw-r--r--pkg/host/features.go2
-rw-r--r--pkg/host/features_linux.go8
-rw-r--r--pkg/ipc/ipc.go1
-rw-r--r--pkg/repro/repro.go11
-rw-r--r--pkg/runtest/run.go3
8 files changed, 34 insertions, 0 deletions
diff --git a/pkg/csource/common.go b/pkg/csource/common.go
index 4b9b37455..6f3920126 100644
--- a/pkg/csource/common.go
+++ b/pkg/csource/common.go
@@ -117,6 +117,7 @@ func commonDefines(p *prog.Prog, opts Options) map[string]bool {
"SYZ_CLOSE_FDS": opts.CloseFDs,
"SYZ_KCSAN": opts.KCSAN,
"SYZ_DEVLINK_PCI": opts.DevlinkPCI,
+ "SYZ_NIC_VF": opts.NicVF,
"SYZ_USB": opts.USB,
"SYZ_VHCI_INJECTION": opts.VhciInjection,
"SYZ_USE_TMP_DIR": opts.UseTmpDir,
diff --git a/pkg/csource/options.go b/pkg/csource/options.go
index b150e79a0..45cedb6a9 100644
--- a/pkg/csource/options.go
+++ b/pkg/csource/options.go
@@ -37,6 +37,7 @@ type Options struct {
CloseFDs bool `json:"close_fds"`
KCSAN bool `json:"kcsan,omitempty"`
DevlinkPCI bool `json:"devlinkpci,omitempty"`
+ NicVF bool `json:"nicvf,omitempty"`
USB bool `json:"usb,omitempty"`
VhciInjection bool `json:"vhci,omitempty"`
Wifi bool `json:"wifi,omitempty"`
@@ -141,6 +142,7 @@ func (opts Options) checkLinuxOnly(OS string) error {
"CloseFDs": &opts.CloseFDs,
"KCSAN": &opts.KCSAN,
"DevlinkPCI": &opts.DevlinkPCI,
+ "NicVF": &opts.NicVF,
"USB": &opts.USB,
"VhciInjection": &opts.VhciInjection,
"Wifi": &opts.Wifi,
@@ -175,6 +177,7 @@ func DefaultOpts(cfg *mgrconfig.Config) Options {
opts.BinfmtMisc = true
opts.CloseFDs = true
opts.DevlinkPCI = true
+ opts.NicVF = true
opts.USB = true
opts.VhciInjection = true
opts.Wifi = true
@@ -307,6 +310,7 @@ func defaultFeatures(value bool) Features {
"binfmt_misc": {"setup binfmt_misc for testing", value},
"close_fds": {"close fds after each program", value},
"devlink_pci": {"setup devlink PCI device", value},
+ "nic_vf": {"setup NIC VF device", value},
"usb": {"setup and use /dev/raw-gadget for USB emulation", value},
"vhci": {"setup and use /dev/vhci for hci packet injection", value},
"wifi": {"setup and use mac80211_hwsim for wifi emulation", value},
diff --git a/pkg/csource/options_test.go b/pkg/csource/options_test.go
index 41d7cdbab..5edc56d02 100644
--- a/pkg/csource/options_test.go
+++ b/pkg/csource/options_test.go
@@ -308,6 +308,7 @@ func TestParseFeaturesFlags(t *testing.T) {
"binfmt_misc": true,
"close_fds": true,
"devlink_pci": true,
+ "nic_vf": true,
"usb": true,
"vhci": true,
"wifi": true,
@@ -323,6 +324,7 @@ func TestParseFeaturesFlags(t *testing.T) {
"binfmt_misc": true,
"close_fds": true,
"devlink_pci": true,
+ "nic_vf": true,
"usb": true,
"vhci": true,
"wifi": true,
@@ -339,6 +341,7 @@ func TestParseFeaturesFlags(t *testing.T) {
"binfmt_misc": true,
"close_fds": true,
"devlink_pci": true,
+ "nic_vf": true,
"usb": true,
"vhci": true,
"wifi": true,
@@ -355,6 +358,7 @@ func TestParseFeaturesFlags(t *testing.T) {
"binfmt_misc": true,
"close_fds": true,
"devlink_pci": true,
+ "nic_vf": true,
"usb": true,
"vhci": true,
"wifi": true,
diff --git a/pkg/host/features.go b/pkg/host/features.go
index d2105b203..343e76783 100644
--- a/pkg/host/features.go
+++ b/pkg/host/features.go
@@ -29,6 +29,7 @@ const (
FeatureNetDevices
FeatureKCSAN
FeatureDevlinkPCI
+ FeatureNicVF
FeatureUSBEmulation
FeatureVhciInjection
FeatureWifiEmulation
@@ -71,6 +72,7 @@ func Check(target *prog.Target) (*Features, error) {
FeatureNetDevices: {Name: "net device setup", Reason: unsupported},
FeatureKCSAN: {Name: "concurrency sanitizer", Reason: unsupported},
FeatureDevlinkPCI: {Name: "devlink PCI setup", Reason: unsupported},
+ FeatureNicVF: {Name: "NIC VF setup", Reason: unsupported},
FeatureUSBEmulation: {Name: "USB emulation", Reason: unsupported},
FeatureVhciInjection: {Name: "hci packet injection", Reason: unsupported},
FeatureWifiEmulation: {Name: "wifi device emulation", Reason: unsupported},
diff --git a/pkg/host/features_linux.go b/pkg/host/features_linux.go
index de04e7a4d..acc7e0829 100644
--- a/pkg/host/features_linux.go
+++ b/pkg/host/features_linux.go
@@ -32,6 +32,7 @@ func init() {
checkFeature[FeatureNetDevices] = unconditionallyEnabled
checkFeature[FeatureKCSAN] = checkKCSAN
checkFeature[FeatureDevlinkPCI] = checkDevlinkPCI
+ checkFeature[FeatureNicVF] = checkNicVF
checkFeature[FeatureUSBEmulation] = checkUSBEmulation
checkFeature[FeatureVhciInjection] = checkVhciInjection
checkFeature[FeatureWifiEmulation] = checkWifiEmulation
@@ -260,6 +261,13 @@ func checkDevlinkPCI() string {
return ""
}
+func checkNicVF() string {
+ if err := osutil.IsAccessible("/sys/bus/pci/devices/0000:00:11.0/"); err != nil {
+ return "PCI device 0000:00:11.0 is not available"
+ }
+ return ""
+}
+
func checkWifiEmulation() string {
if err := osutil.IsAccessible("/sys/class/mac80211_hwsim/"); err != nil {
return err.Error()
diff --git a/pkg/ipc/ipc.go b/pkg/ipc/ipc.go
index 5537ce0f8..33e87f706 100644
--- a/pkg/ipc/ipc.go
+++ b/pkg/ipc/ipc.go
@@ -43,6 +43,7 @@ const (
FlagEnableVhciInjection // setup and use /dev/vhci for hci packet injection
FlagEnableWifi // setup and use mac80211_hwsim for wifi emulation
FlagDelayKcovMmap // manage kcov memory in an optimized way
+ FlagEnableNicVF // setup NIC VF device
)
// Per-exec flags for ExecOpts.Flags.
diff --git a/pkg/repro/repro.go b/pkg/repro/repro.go
index fe20c7330..d614cdfb6 100644
--- a/pkg/repro/repro.go
+++ b/pkg/repro/repro.go
@@ -192,6 +192,9 @@ func createStartOptions(cfg *mgrconfig.Config, features *host.Features, crashTyp
if !features[host.FeatureDevlinkPCI].Enabled {
opts.DevlinkPCI = false
}
+ if !features[host.FeatureNicVF].Enabled {
+ opts.NicVF = false
+ }
if !features[host.FeatureUSBEmulation].Enabled {
opts.USB = false
}
@@ -759,6 +762,7 @@ var cSimplifies = append(progSimplifies, []Simplify{
opts.BinfmtMisc = false
opts.CloseFDs = false
opts.DevlinkPCI = false
+ opts.NicVF = false
opts.USB = false
opts.VhciInjection = false
opts.Wifi = false
@@ -816,6 +820,13 @@ var cSimplifies = append(progSimplifies, []Simplify{
return true
},
func(opts *csource.Options) bool {
+ if !opts.NicVF {
+ return false
+ }
+ opts.NicVF = false
+ return true
+ },
+ func(opts *csource.Options) bool {
if !opts.USB {
return false
}
diff --git a/pkg/runtest/run.go b/pkg/runtest/run.go
index 985c5979c..e1c3ae1f8 100644
--- a/pkg/runtest/run.go
+++ b/pkg/runtest/run.go
@@ -428,6 +428,9 @@ func (ctx *Context) createSyzTest(p *prog.Prog, sandbox string, threaded, cov bo
if ctx.Features[host.FeatureDevlinkPCI].Enabled {
cfg.Flags |= ipc.FlagEnableDevlinkPCI
}
+ if ctx.Features[host.FeatureNicVF].Enabled {
+ cfg.Flags |= ipc.FlagEnableNicVF
+ }
if ctx.Features[host.FeatureVhciInjection].Enabled {
cfg.Flags |= ipc.FlagEnableVhciInjection
}