aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/host/host_linux.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/host/host_linux.go')
-rw-r--r--pkg/host/host_linux.go127
1 files changed, 79 insertions, 48 deletions
diff --git a/pkg/host/host_linux.go b/pkg/host/host_linux.go
index d5ab3a495..02392a4b0 100644
--- a/pkg/host/host_linux.go
+++ b/pkg/host/host_linux.go
@@ -10,15 +10,15 @@ import (
"runtime"
"strconv"
"strings"
+ "sync"
"syscall"
"github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/prog"
)
-// DetectSupportedSyscalls returns list on supported syscalls on host.
-func DetectSupportedSyscalls(target *prog.Target, sandbox string) (map[*prog.Syscall]bool, error) {
- // There are 3 possible strategies:
+func isSupported(c *prog.Syscall, sandbox string) (bool, string) {
+ // There are 3 possible strategies for detecting supported syscalls:
// 1. Executes all syscalls with presumably invalid arguments and check for ENOprog.
// But not all syscalls are safe to execute. For example, pause will hang,
// while setpgrp will push the process into own process group.
@@ -27,18 +27,9 @@ func DetectSupportedSyscalls(target *prog.Target, sandbox string) (map[*prog.Sys
// For example, on x86_64 it says that sendfile is not present (only sendfile64).
// 3. Check sys_syscallname in /proc/kallsyms.
// Requires CONFIG_KALLSYMS. Seems to be the most reliable. That's what we use here.
-
- kallsyms, _ := ioutil.ReadFile("/proc/kallsyms")
- supported := make(map[*prog.Syscall]bool)
- for _, c := range target.Syscalls {
- if isSupported(sandbox, kallsyms, c) {
- supported[c] = true
- }
- }
- return supported, nil
-}
-
-func isSupported(sandbox string, kallsyms []byte, c *prog.Syscall) bool {
+ kallsymsOnce.Do(func() {
+ kallsyms, _ = ioutil.ReadFile("/proc/kallsyms")
+ })
if strings.HasPrefix(c.CallName, "syz_") {
return isSupportedSyzkall(sandbox, c)
}
@@ -49,42 +40,52 @@ func isSupported(sandbox string, kallsyms []byte, c *prog.Syscall) bool {
return isSupportedOpenAt(c)
}
if len(kallsyms) == 0 {
- return true
+ return true, ""
}
name := c.CallName
if newname := kallsymsMap[name]; newname != "" {
name = newname
}
- return bytes.Contains(kallsyms, []byte(" T sys_"+name+"\n"))
+ if !bytes.Contains(kallsyms, []byte(" T sys_"+name+"\n")) {
+ return false, fmt.Sprintf("sys_%v is not present in /proc/kallsyms", name)
+ }
+ return true, ""
}
// Some syscall names diverge in __NR_* consts and kallsyms.
// umount2 is renamed to umount in arch/x86/entry/syscalls/syscall_64.tbl.
// Where umount is renamed to oldumount is unclear.
-var kallsymsMap = map[string]string{
- "umount": "oldumount",
- "umount2": "umount",
-}
+var (
+ kallsyms []byte
+ kallsymsOnce sync.Once
+ kallsymsMap = map[string]string{
+ "umount": "oldumount",
+ "umount2": "umount",
+ }
+)
-func isSupportedSyzkall(sandbox string, c *prog.Syscall) bool {
+func isSupportedSyzkall(sandbox string, c *prog.Syscall) (bool, string) {
switch c.CallName {
case "syz_open_dev":
if _, ok := c.Args[0].(*prog.ConstType); ok {
// This is for syz_open_dev$char/block.
// They are currently commented out, but in case one enables them.
- return true
+ return true, ""
}
fname, ok := extractStringConst(c.Args[0])
if !ok {
panic("first open arg is not a pointer to string const")
}
if syscall.Getuid() != 0 || sandbox == "setuid" {
- return false
+ return false, "only supported under root with sandbox=none/namespace"
}
var check func(dev string) bool
check = func(dev string) bool {
if !strings.Contains(dev, "#") {
- return osutil.IsExist(dev)
+ if !osutil.IsExist(dev) {
+ return false
+ }
+ return true
}
for i := 0; i < 10; i++ {
if check(strings.Replace(dev, "#", strconv.Itoa(i), 1)) {
@@ -93,59 +94,80 @@ func isSupportedSyzkall(sandbox string, c *prog.Syscall) bool {
}
return false
}
- return check(fname)
+ if !check(fname) {
+ return false, fmt.Sprintf("file %v does not exist", fname)
+ }
+ return true, ""
case "syz_open_procfs":
- return true
+ return true, ""
case "syz_open_pts":
- return true
+ return true, ""
case "syz_fuse_mount":
if syscall.Getuid() != 0 || sandbox == "setuid" {
- return false
+ return false, "only supported under root with sandbox=none/namespace"
+ }
+ if !osutil.IsExist("/dev/fuse") {
+ return false, "/dev/fuse does not exist"
}
- return osutil.IsExist("/dev/fuse")
+ return true, ""
case "syz_fuseblk_mount":
if syscall.Getuid() != 0 || sandbox == "setuid" {
- return false
+ return false, "only supported under root with sandbox=none/namespace"
+ }
+ if !osutil.IsExist("/dev/fuse") {
+ return false, "/dev/fuse does not exist"
}
- return osutil.IsExist("/dev/fuse")
+ return true, ""
case "syz_emit_ethernet", "syz_extract_tcp_res":
fd, err := syscall.Open("/dev/net/tun", syscall.O_RDWR, 0)
- if err == nil {
- syscall.Close(fd)
+ if err != nil {
+ return false, fmt.Sprintf("open(/dev/net/tun) failed: %v", err)
}
- return err == nil
+ syscall.Close(fd)
+ return true, ""
case "syz_kvm_setup_cpu":
switch c.Name {
case "syz_kvm_setup_cpu$x86":
- return runtime.GOARCH == "amd64" || runtime.GOARCH == "386"
+ if runtime.GOARCH == "amd64" || runtime.GOARCH == "386" {
+ return true, ""
+ }
case "syz_kvm_setup_cpu$arm64":
- return runtime.GOARCH == "arm64"
+ if runtime.GOARCH == "arm64" {
+ return true, ""
+ }
}
+ return false, "unsupported arch"
case "syz_init_net_socket":
// Unfortunately this only works with sandbox none at the moment.
// The problem is that setns of a network namespace requires CAP_SYS_ADMIN
// in the target namespace, and we've lost all privs in the init namespace
// during creation of a user namespace.
if syscall.Getuid() != 0 || sandbox != "none" {
- return false
+ return false, "only supported under root with sandbox=none"
}
return isSupportedSocket(c)
case "syz_genetlink_get_family_id":
- fd, _ := syscall.Socket(syscall.AF_NETLINK, syscall.SOCK_RAW, syscall.NETLINK_GENERIC)
+ fd, err := syscall.Socket(syscall.AF_NETLINK, syscall.SOCK_RAW, syscall.NETLINK_GENERIC)
if fd == -1 {
- return false
+ return false, fmt.Sprintf("socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC) failed: %v", err)
}
syscall.Close(fd)
- return true
+ return true, ""
case "syz_mount_image":
- return sandbox != "setuid"
+ if syscall.Getuid() != 0 || sandbox == "setuid" {
+ return false, "only supported under root with sandbox=none/namespace"
+ }
+ return true, ""
case "syz_read_part_table":
- return sandbox == "none" && syscall.Getuid() == 0
+ if syscall.Getuid() != 0 || sandbox != "none" {
+ return false, "only supported under root with sandbox=none"
+ }
+ return true, ""
}
panic("unknown syzkall: " + c.Name)
}
-func isSupportedSocket(c *prog.Syscall) bool {
+func isSupportedSocket(c *prog.Syscall) (bool, string) {
af, ok := c.Args[0].(*prog.ConstType)
if !ok {
panic("socket family is not const")
@@ -154,19 +176,28 @@ func isSupportedSocket(c *prog.Syscall) bool {
if fd != -1 {
syscall.Close(fd)
}
- return err != syscall.ENOSYS && err != syscall.EAFNOSUPPORT
+ if err == syscall.ENOSYS {
+ return false, "socket syscall returns ENOSYS"
+ }
+ if err == syscall.EAFNOSUPPORT {
+ return false, "socket family is not supported (EAFNOSUPPORT)"
+ }
+ return true, ""
}
-func isSupportedOpenAt(c *prog.Syscall) bool {
+func isSupportedOpenAt(c *prog.Syscall) (bool, string) {
fname, ok := extractStringConst(c.Args[1])
if !ok || len(fname) == 0 || fname[0] != '/' {
- return true
+ return true, ""
}
fd, err := syscall.Open(fname, syscall.O_RDONLY, 0)
if fd != -1 {
syscall.Close(fd)
}
- return err == nil
+ if err != nil {
+ return false, fmt.Sprintf("open(%v) failed: %v", fname, err)
+ }
+ return true, ""
}
func extractStringConst(typ prog.Type) (string, bool) {