Home | History | Annotate | Download | only in ipcconfig
      1 // Copyright 2018 syzkaller project authors. All rights reserved.
      2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
      3 
      4 package ipcconfig
      5 
      6 import (
      7 	"flag"
      8 	"fmt"
      9 
     10 	"github.com/google/syzkaller/pkg/ipc"
     11 	"github.com/google/syzkaller/prog"
     12 	"github.com/google/syzkaller/sys/targets"
     13 )
     14 
     15 var (
     16 	flagExecutor = flag.String("executor", "./syz-executor", "path to executor binary")
     17 	flagThreaded = flag.Bool("threaded", true, "use threaded mode in executor")
     18 	flagCollide  = flag.Bool("collide", true, "collide syscalls to provoke data races")
     19 	flagSignal   = flag.Bool("cover", false, "collect feedback signals (coverage)")
     20 	flagSandbox  = flag.String("sandbox", "none", "sandbox for fuzzing (none/setuid/namespace)")
     21 	flagDebug    = flag.Bool("debug", false, "debug output from executor")
     22 	flagTimeout  = flag.Duration("timeout", 0, "execution timeout")
     23 )
     24 
     25 func Default(target *prog.Target) (*ipc.Config, *ipc.ExecOpts, error) {
     26 	c := &ipc.Config{
     27 		Executor: *flagExecutor,
     28 		Timeout:  *flagTimeout,
     29 	}
     30 	if *flagSignal {
     31 		c.Flags |= ipc.FlagSignal
     32 	}
     33 	if *flagDebug {
     34 		c.Flags |= ipc.FlagDebug
     35 	}
     36 	switch *flagSandbox {
     37 	case "none":
     38 	case "setuid":
     39 		c.Flags |= ipc.FlagSandboxSetuid
     40 	case "namespace":
     41 		c.Flags |= ipc.FlagSandboxNamespace
     42 	default:
     43 		return nil, nil, fmt.Errorf("flag sandbox must contain one of none/setuid/namespace")
     44 	}
     45 
     46 	sysTarget := targets.Get(target.OS, target.Arch)
     47 	if sysTarget.ExecutorUsesShmem {
     48 		c.Flags |= ipc.FlagUseShmem
     49 	}
     50 	if sysTarget.ExecutorUsesForkServer {
     51 		c.Flags |= ipc.FlagUseForkServer
     52 	}
     53 
     54 	opts := &ipc.ExecOpts{
     55 		Flags: ipc.FlagDedupCover,
     56 	}
     57 	if *flagThreaded {
     58 		opts.Flags |= ipc.FlagThreaded
     59 	}
     60 	if *flagCollide {
     61 		opts.Flags |= ipc.FlagCollide
     62 	}
     63 
     64 	return c, opts, nil
     65 }
     66