From f635b41d90ee4c01636d9b7f67091aa2ce2c2f20 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Wed, 12 Jan 2022 13:54:32 +0000 Subject: all: explicitly list pseudo syscall dependencies Pseudo syscalls can (and most of the time) do invoke normal system calls. However, when there's a risk that those calls might not be present, syzkaller needs to take preventive actions - prepend the corresponding defines. Otherwise syz-executor or C reproducers might not compile on the host machine. List those dependencies in sys/targets, check them during machine check and add the corresponding defines during C source generation. --- pkg/host/syscalls_linux.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'pkg/host') diff --git a/pkg/host/syscalls_linux.go b/pkg/host/syscalls_linux.go index 1d305b4e0..f43f1ada3 100644 --- a/pkg/host/syscalls_linux.go +++ b/pkg/host/syscalls_linux.go @@ -71,6 +71,14 @@ func isSupportedSyscall(c *prog.Syscall, target *prog.Target) (bool, string) { return isSupportedTrial(c) } +func isSupportedSyscallName(name string, target *prog.Target) (bool, string) { + syscall := target.SyscallMap[name] + if syscall == nil { + return false, fmt.Sprintf("sys_%v is not present in the target", name) + } + return isSupportedSyscall(syscall, target) +} + func parseKallsyms(kallsyms []byte, arch string) map[string]bool { set := make(map[string]bool) var re *regexp.Regexp @@ -245,12 +253,7 @@ func isSyzReadPartTableSupported(c *prog.Syscall, target *prog.Target, sandbox s } func isSyzIoUringSupported(c *prog.Syscall, target *prog.Target, sandbox string) (bool, string) { - ioUringSyscallName := "io_uring_setup" - ioUringSyscall := target.SyscallMap[ioUringSyscallName] - if ioUringSyscall == nil { - return false, fmt.Sprintf("sys_%v is not present in the target", ioUringSyscallName) - } - return isSupportedSyscall(ioUringSyscall, target) + return isSupportedSyscallName("io_uring_setup", target) } func isSyzMemcpySupported(c *prog.Syscall, target *prog.Target, sandbox string) (bool, string) { @@ -316,6 +319,12 @@ var syzkallSupport = map[string]func(*prog.Syscall, *prog.Target, string) (bool, } func isSupportedSyzkall(c *prog.Syscall, target *prog.Target, sandbox string) (bool, string) { + sysTarget := targets.Get(target.OS, target.Arch) + for _, depCall := range sysTarget.PseudoSyscallDeps[c.CallName] { + if ok, reason := isSupportedSyscallName(depCall, target); !ok { + return ok, reason + } + } if isSupported, ok := syzkallSupport[c.CallName]; ok { return isSupported(c, target, sandbox) } -- cgit mrf-deployment