Skip to content

Commit bc1a1b5

Browse files
sephalondvyukov
authored andcommitted
all: add support for binaries shipped with target
In some build environments (notably Yocto), syzkaller host and target binaries end up in separate packages for each built architecture, which are then shipped with the respective image/SDK. Add the "Execprog/ExecutorBinOnTarget" and "StraceBinOnTarget" options to the manager config, which when set expects the respective binaries to be shipped with the target image and does not attempt to copy them from the host.
1 parent f93b2b5 commit bc1a1b5

File tree

5 files changed

+41
-13
lines changed

5 files changed

+41
-13
lines changed

executor/subprocess.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ class Subprocess
5656
"GLIBC_TUNABLES=glibc.pthread.rseq=0",
5757
nullptr};
5858

59-
if (posix_spawn(&pid_, argv[0], &actions, &attr,
60-
const_cast<char**>(argv), const_cast<char**>(child_envp)))
61-
fail("posix_spawn failed");
59+
if (posix_spawnp(&pid_, argv[0], &actions, &attr,
60+
const_cast<char**>(argv), const_cast<char**>(child_envp)))
61+
fail("posix_spawnp failed");
6262

6363
if (posix_spawn_file_actions_destroy(&actions))
6464
fail("posix_spawn_file_actions_destroy failed");

pkg/instance/execprog.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ const (
5050

5151
func SetupExecProg(vmInst *vm.Instance, mgrCfg *mgrconfig.Config, reporter *report.Reporter,
5252
opt *OptionalConfig) (*ExecProgInstance, error) {
53-
execprogBin, err := vmInst.Copy(mgrCfg.ExecprogBin)
54-
if err != nil {
55-
return nil, &TestError{Title: fmt.Sprintf("failed to copy syz-execprog to VM: %v", err)}
53+
var err error
54+
execprogBin := mgrCfg.SysTarget.ExecprogBin
55+
if execprogBin == "" {
56+
execprogBin, err = vmInst.Copy(mgrCfg.ExecprogBin)
57+
if err != nil {
58+
return nil, &TestError{Title: fmt.Sprintf("failed to copy syz-execprog to VM: %v", err)}
59+
}
5660
}
5761
executorBin := mgrCfg.SysTarget.ExecutorBin
5862
if executorBin == "" {
@@ -70,7 +74,7 @@ func SetupExecProg(vmInst *vm.Instance, mgrCfg *mgrconfig.Config, reporter *repo
7074
}
7175
if opt != nil {
7276
ret.OptionalConfig = *opt
73-
if ret.StraceBin != "" {
77+
if !mgrCfg.StraceBinOnTarget && ret.StraceBin != "" {
7478
var err error
7579
ret.StraceBin, err = vmInst.Copy(ret.StraceBin)
7680
if err != nil {

pkg/mgrconfig/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ type Config struct {
191191
// If set, for each reproducer syzkaller will run it once more under strace and save
192192
// the output.
193193
StraceBin string `json:"strace_bin"`
194+
// If true, syzkaller will expect strace_bin to be part of the target
195+
// image instead of copying it from the host (default: false).
196+
StraceBinOnTarget bool `json:"strace_bin_on_target"`
197+
198+
// File in PATH to syz-execprog/executor on the target. If set,
199+
// syzkaller will expect the execprog/executor binaries to be part of
200+
// the target image instead of copying them from the host.
201+
ExecprogBinOnTarget string `json:"execprog_bin_on_target"`
202+
ExecutorBinOnTarget string `json:"executor_bin_on_target"`
194203

195204
// Whether to run fsck commands on file system images found in new crash
196205
// reproducers. The fsck logs get reported as assets in the dashboard.

pkg/mgrconfig/load.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,17 +308,31 @@ func (cfg *Config) completeBinaries() error {
308308
}
309309
cfg.ExecprogBin = targetBin("syz-execprog", cfg.TargetVMArch)
310310
cfg.ExecutorBin = targetBin("syz-executor", cfg.TargetArch)
311-
// If the target already provides an executor binary, we don't need to copy it.
311+
312+
if cfg.ExecprogBinOnTarget != "" {
313+
cfg.SysTarget.ExecprogBin = cfg.ExecprogBinOnTarget
314+
}
315+
if cfg.ExecutorBinOnTarget != "" {
316+
cfg.SysTarget.ExecutorBin = cfg.ExecutorBinOnTarget
317+
}
318+
if cfg.StraceBinOnTarget && cfg.StraceBin == "" {
319+
cfg.StraceBin = "strace"
320+
}
321+
322+
// If the target already provides binaries, we don't need to copy them.
323+
if cfg.SysTarget.ExecprogBin != "" {
324+
cfg.ExecprogBin = ""
325+
}
312326
if cfg.SysTarget.ExecutorBin != "" {
313327
cfg.ExecutorBin = ""
314328
}
315-
if !osutil.IsExist(cfg.ExecprogBin) {
329+
if cfg.ExecprogBin != "" && !osutil.IsExist(cfg.ExecprogBin) {
316330
return fmt.Errorf("bad config syzkaller param: can't find %v", cfg.ExecprogBin)
317331
}
318332
if cfg.ExecutorBin != "" && !osutil.IsExist(cfg.ExecutorBin) {
319333
return fmt.Errorf("bad config syzkaller param: can't find %v", cfg.ExecutorBin)
320334
}
321-
if cfg.StraceBin != "" {
335+
if !cfg.StraceBinOnTarget && cfg.StraceBin != "" {
322336
if !osutil.IsExist(cfg.StraceBin) {
323337
return fmt.Errorf("bad config param strace_bin: can't find %v", cfg.StraceBin)
324338
}

sys/targets/targets.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ type osCommon struct {
8282
// Special mode for OSes that do not have support for building Go binaries.
8383
// In this mode we run Go binaries on the host machine, only executor runs on target.
8484
HostFuzzer bool
85-
// How to run syz-executor directly.
86-
// Some systems build syz-executor into their images.
87-
// If this flag is not empty, syz-executor will not be copied to the machine, and will be run using
85+
// How to run syz-execprog/executor directly.
86+
// Some systems build syz-execprog/executor into their images.
87+
// If this flag is not empty, syz-execprog/executor will not be copied to the machine, and will be run using
8888
// this command instead.
89+
ExecprogBin string
8990
ExecutorBin string
9091
// Extension of executable files (notably, .exe for windows).
9192
ExeExtension string

0 commit comments

Comments
 (0)