aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-11-29 10:40:36 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-11-30 13:33:18 +0100
commit1fd901159188a5e0c2b3559ae7ec7deff7c4e7a2 (patch)
tree82c9a88630b01824aab94866cbe1d405a7e7219d /pkg
parenta142e60d5cf11dc798e4909c97803d75add83a11 (diff)
pkg/mgrconfig: add prog&sys.targets targets to Config
These are widely used with the config as the refactoring shows. This removes a bunch of unnecessary code. Also fixes a number of bugs where we confused Arch with VMArch.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/bisect/bisect.go15
-rw-r--r--pkg/bisect/bisect_test.go2
-rw-r--r--pkg/instance/instance.go11
-rw-r--r--pkg/mgrconfig/config.go2
-rw-r--r--pkg/mgrconfig/load.go34
-rw-r--r--pkg/report/report.go6
-rw-r--r--pkg/repro/repro.go8
7 files changed, 36 insertions, 42 deletions
diff --git a/pkg/bisect/bisect.go b/pkg/bisect/bisect.go
index 3e64233c6..76c518e6c 100644
--- a/pkg/bisect/bisect.go
+++ b/pkg/bisect/bisect.go
@@ -16,7 +16,6 @@ import (
"github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/pkg/report"
"github.com/google/syzkaller/pkg/vcs"
- "github.com/google/syzkaller/sys/targets"
)
type Config struct {
@@ -29,7 +28,7 @@ type Config struct {
Kernel KernelConfig
Syzkaller SyzkallerConfig
Repro ReproConfig
- Manager mgrconfig.Config
+ Manager *mgrconfig.Config
}
type KernelConfig struct {
@@ -63,7 +62,6 @@ type ReproConfig struct {
type env struct {
cfg *Config
- target *targets.Target
repo vcs.Repo
bisecter vcs.Bisecter
minimizer vcs.ConfigMinimizer
@@ -116,7 +114,7 @@ func Run(cfg *Config) (*Result, error) {
if err != nil {
return nil, err
}
- inst, err := instance.NewEnv(&cfg.Manager)
+ inst, err := instance.NewEnv(cfg.Manager)
if err != nil {
return nil, err
}
@@ -135,13 +133,8 @@ func runImpl(cfg *Config, repo vcs.Repo, inst instance.Env) (*Result, error) {
if !ok && len(cfg.Kernel.BaselineConfig) != 0 {
return nil, fmt.Errorf("config minimization is not implemented for %v", cfg.Manager.TargetOS)
}
- target := targets.Get(cfg.Manager.TargetOS, cfg.Manager.TargetVMArch)
- if target == nil {
- return nil, fmt.Errorf("unknown target %v/%v", cfg.Manager.TargetOS, cfg.Manager.TargetVMArch)
- }
env := &env{
cfg: cfg,
- target: target,
repo: repo,
bisecter: bisecter,
minimizer: minimizer,
@@ -309,7 +302,7 @@ func (env *env) minimizeConfig() (*testResult, error) {
testResults[hash.Hash(test)] = testRes
return testRes.verdict, err
}
- minConfig, err := env.minimizer.Minimize(env.target, env.cfg.Kernel.Config,
+ minConfig, err := env.minimizer.Minimize(env.cfg.Manager.SysTarget, env.cfg.Kernel.Config,
env.cfg.Kernel.BaselineConfig, env.cfg.Trace, predMinimize)
if err != nil {
return nil, err
@@ -426,7 +419,7 @@ func (env *env) build() (*vcs.Commit, string, error) {
}
env.log("testing commit %v with %v", current.Hash, compilerID)
buildStart := time.Now()
- mgr := &env.cfg.Manager
+ mgr := env.cfg.Manager
if err := build.Clean(mgr.TargetOS, mgr.TargetVMArch, mgr.Type, mgr.KernelSrc); err != nil {
return nil, "", fmt.Errorf("kernel clean failed: %v", err)
}
diff --git a/pkg/bisect/bisect_test.go b/pkg/bisect/bisect_test.go
index 26e157aaa..db4409a5c 100644
--- a/pkg/bisect/bisect_test.go
+++ b/pkg/bisect/bisect_test.go
@@ -126,7 +126,7 @@ func runBisection(t *testing.T, baseDir string, test BisectionTest) (*Result, er
cfg := &Config{
Fix: test.fix,
Trace: trace,
- Manager: mgrconfig.Config{
+ Manager: &mgrconfig.Config{
Derived: mgrconfig.Derived{
TargetOS: targets.TestOS,
TargetVMArch: targets.TestArch64,
diff --git a/pkg/instance/instance.go b/pkg/instance/instance.go
index 467998a60..5ca1c2b78 100644
--- a/pkg/instance/instance.go
+++ b/pkg/instance/instance.go
@@ -22,7 +22,6 @@ import (
"github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/pkg/report"
"github.com/google/syzkaller/pkg/vcs"
- "github.com/google/syzkaller/prog"
"github.com/google/syzkaller/sys/targets"
"github.com/google/syzkaller/vm"
)
@@ -310,7 +309,7 @@ func (inst *inst) testInstance() error {
// If SyzExecutorCmd is provided, it means that syz-executor is already in
// the image, so no need to copy it.
- executorCmd := targets.Get(inst.cfg.TargetOS, inst.cfg.TargetArch).SyzExecutorCmd
+ executorCmd := inst.cfg.SysTarget.SyzExecutorCmd
if executorCmd == "" {
executorCmd, err = inst.vm.Copy(inst.cfg.SyzExecutorBin)
if err != nil {
@@ -352,7 +351,7 @@ func (inst *inst) testRepro() error {
}
// If SyzExecutorCmd is provided, it means that syz-executor is already in
// the image, so no need to copy it.
- executorCmd := targets.Get(cfg.TargetOS, cfg.TargetArch).SyzExecutorCmd
+ executorCmd := cfg.SysTarget.SyzExecutorCmd
if executorCmd == "" {
executorCmd, err = inst.vm.Copy(inst.cfg.SyzExecutorBin)
if err != nil {
@@ -390,11 +389,7 @@ func (inst *inst) testRepro() error {
if len(inst.reproC) == 0 {
return nil
}
- target, err := prog.GetTarget(cfg.TargetOS, cfg.TargetArch)
- if err != nil {
- return err
- }
- bin, err := csource.BuildNoWarn(target, inst.reproC)
+ bin, err := csource.BuildNoWarn(cfg.Target, inst.reproC)
if err != nil {
return err
}
diff --git a/pkg/mgrconfig/config.go b/pkg/mgrconfig/config.go
index 0fc7316e4..3de0814d5 100644
--- a/pkg/mgrconfig/config.go
+++ b/pkg/mgrconfig/config.go
@@ -9,7 +9,7 @@ type Config struct {
// Instance name (used for identification and as GCE instance prefix).
Name string `json:"name"`
// Target OS/arch, e.g. "linux/arm64" or "linux/amd64/386" (amd64 OS with 386 test process).
- Target string `json:"target"`
+ RawTarget string `json:"target"`
// URL that will display information about the running syz-manager process (e.g. "localhost:50000").
HTTP string `json:"http"`
// TCP address to serve RPC for fuzzer processes (optional).
diff --git a/pkg/mgrconfig/load.go b/pkg/mgrconfig/load.go
index a1bde9efa..d4756a0cd 100644
--- a/pkg/mgrconfig/load.go
+++ b/pkg/mgrconfig/load.go
@@ -19,6 +19,9 @@ import (
// Derived config values that are handy to keep with the config, filled after reading user config.
type Derived struct {
+ Target *prog.Target
+ SysTarget *targets.Target
+
// Parsed Target:
TargetOS string
TargetArch string
@@ -28,6 +31,8 @@ type Derived struct {
SyzFuzzerBin string
SyzExecprogBin string
SyzExecutorBin string
+
+ Syscalls []int
}
func LoadData(data []byte) (*Config, error) {
@@ -81,10 +86,18 @@ func defaultValues() *Config {
func loadPartial(cfg *Config) (*Config, error) {
var err error
- cfg.TargetOS, cfg.TargetVMArch, cfg.TargetArch, err = splitTarget(cfg.Target)
+ cfg.TargetOS, cfg.TargetVMArch, cfg.TargetArch, err = splitTarget(cfg.RawTarget)
+ if err != nil {
+ return nil, err
+ }
+ cfg.Target, err = prog.GetTarget(cfg.TargetOS, cfg.TargetArch)
if err != nil {
return nil, err
}
+ cfg.SysTarget = targets.Get(cfg.TargetOS, cfg.TargetVMArch)
+ if cfg.SysTarget == nil {
+ return nil, fmt.Errorf("unsupported OS/arch: %v/%v", cfg.TargetOS, cfg.TargetVMArch)
+ }
return cfg, nil
}
@@ -114,7 +127,7 @@ func Complete(cfg *Config) error {
}
cfg.Image = osutil.Abs(cfg.Image)
}
- if err := completeBinaries(cfg); err != nil {
+ if err := cfg.completeBinaries(); err != nil {
return err
}
if cfg.Procs < 1 || cfg.Procs > prog.MaxPids {
@@ -125,7 +138,7 @@ func Complete(cfg *Config) error {
default:
return fmt.Errorf("config param sandbox must contain one of none/setuid/namespace/android")
}
- if err := checkSSHParams(cfg); err != nil {
+ if err := cfg.checkSSHParams(); err != nil {
return err
}
cfg.CompleteKernelDirs()
@@ -148,6 +161,11 @@ func Complete(cfg *Config) error {
return err
}
}
+ var err error
+ cfg.Syscalls, err = ParseEnabledSyscalls(cfg.Target, cfg.EnabledSyscalls, cfg.DisabledSyscalls)
+ if err != nil {
+ return err
+ }
return nil
}
@@ -172,7 +190,7 @@ func (cfg *Config) CompleteKernelDirs() {
cfg.KernelBuildSrc = osutil.Abs(cfg.KernelBuildSrc)
}
-func checkSSHParams(cfg *Config) error {
+func (cfg *Config) checkSSHParams() error {
if cfg.SSHKey == "" {
return nil
}
@@ -187,13 +205,9 @@ func checkSSHParams(cfg *Config) error {
return nil
}
-func completeBinaries(cfg *Config) error {
- sysTarget := targets.Get(cfg.TargetOS, cfg.TargetArch)
- if sysTarget == nil {
- return fmt.Errorf("unsupported OS/arch: %v/%v", cfg.TargetOS, cfg.TargetArch)
- }
+func (cfg *Config) completeBinaries() error {
cfg.Syzkaller = osutil.Abs(cfg.Syzkaller)
- exe := sysTarget.ExeExtension
+ exe := cfg.SysTarget.ExeExtension
targetBin := func(name, arch string) string {
return filepath.Join(cfg.Syzkaller, "bin", cfg.TargetOS+"_"+arch, name+exe)
}
diff --git a/pkg/report/report.go b/pkg/report/report.go
index fc923764f..47e8d9412 100644
--- a/pkg/report/report.go
+++ b/pkg/report/report.go
@@ -100,12 +100,8 @@ func NewReporter(cfg *mgrconfig.Config) (Reporter, error) {
if err != nil {
return nil, err
}
- target := targets.Get(cfg.TargetOS, cfg.TargetArch)
- if target == nil && typ != "gvisor" {
- return nil, fmt.Errorf("unknown target %v/%v", cfg.TargetOS, cfg.TargetArch)
- }
config := &config{
- target: target,
+ target: cfg.SysTarget,
kernelSrc: cfg.KernelSrc,
kernelBuildSrc: cfg.KernelBuildSrc,
kernelObj: cfg.KernelObj,
diff --git a/pkg/repro/repro.go b/pkg/repro/repro.go
index 41a3a5874..930127901 100644
--- a/pkg/repro/repro.go
+++ b/pkg/repro/repro.go
@@ -67,11 +67,7 @@ func Run(crashLog []byte, cfg *mgrconfig.Config, features *host.Features, report
if len(vmIndexes) == 0 {
return nil, nil, fmt.Errorf("no VMs provided")
}
- target, err := prog.GetTarget(cfg.TargetOS, cfg.TargetArch)
- if err != nil {
- return nil, nil, err
- }
- entries := target.ParseLog(crashLog)
+ entries := cfg.Target.ParseLog(crashLog)
if len(entries) == 0 {
return nil, nil, fmt.Errorf("crash log does not contain any programs")
}
@@ -101,7 +97,7 @@ func Run(crashLog []byte, cfg *mgrconfig.Config, features *host.Features, report
timeouts = []time.Duration{noOutputTimeout}
}
ctx := &context{
- target: targets.Get(cfg.TargetOS, cfg.TargetArch),
+ target: cfg.SysTarget,
reporter: reporter,
crashTitle: crashTitle,
crashType: crashType,