From 2c2b926cb74478a86014f40564517f7d424dc899 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sat, 6 Jun 2020 14:21:54 +0200 Subject: .golangci.yml: reduce function line count from 200 to 140 140 lines should be enough for everyone. --- .golangci.yml | 4 ++- pkg/host/syscalls_linux.go | 85 ++++++++++++++++++++++++---------------------- syz-manager/manager.go | 2 +- 3 files changed, 48 insertions(+), 43 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 7bee35ebf..e645b3910 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -88,7 +88,7 @@ linters-settings: min-complexity: 70 funlen: # TODO: consider reducing these value. - lines: 200 + lines: 140 statements: 80 issues: @@ -112,3 +112,5 @@ issues: - path: (prog/.*_test\.go) linters: - goconst + - path: (.*_test\.go) + text: "Function '.*' is too long" diff --git a/pkg/host/syscalls_linux.go b/pkg/host/syscalls_linux.go index 17ea17dd4..3abc7668a 100644 --- a/pkg/host/syscalls_linux.go +++ b/pkg/host/syscalls_linux.go @@ -162,50 +162,10 @@ var ( // The function is lengthy as it handles all pseudo-syscalls, // but it does not seem to cause comprehension problems as there is no shared state. // Splitting this per-syscall will only increase code size. -// nolint: gocyclo func isSupportedSyzkall(sandbox string, c *prog.Syscall) (bool, string) { switch c.CallName { case "syz_open_dev": - if _, ok := c.Args[0].Type.(*prog.ConstType); ok { - // This is for syz_open_dev$char/block. - return true, "" - } - fname, ok := extractStringConst(c.Args[0].Type) - if !ok { - panic("first open arg is not a pointer to string const") - } - if !strings.Contains(fname, "#") { - panic(fmt.Sprintf("%v does not contain # in the file name (should be openat)", c.Name)) - } - if checkUSBEmulation() == "" { - // These entries might not be available at boot time, - // but will be created by connected USB devices. - USBDevicePrefixes := []string{ - "/dev/hidraw", "/dev/usb/hiddev", "/dev/input/", - } - for _, prefix := range USBDevicePrefixes { - if strings.HasPrefix(fname, prefix) { - return true, "" - } - } - } - var check func(dev string) bool - check = func(dev string) bool { - if !strings.Contains(dev, "#") { - // Note: don't try to open them all, some can hang (e.g. /dev/snd/pcmC#D#p). - return osutil.IsExist(dev) - } - for i := 0; i < 10; i++ { - if check(strings.Replace(dev, "#", strconv.Itoa(i), 1)) { - return true - } - } - return false - } - if !check(fname) { - return false, fmt.Sprintf("file %v does not exist", fname) - } - return onlySandboxNoneOrNamespace(sandbox) + return isSupportedSyzOpenDev(sandbox, c) case "syz_open_procfs": return true, "" case "syz_open_pts": @@ -262,6 +222,49 @@ func isSupportedSyzkall(sandbox string, c *prog.Syscall) (bool, string) { panic("unknown syzkall: " + c.Name) } +func isSupportedSyzOpenDev(sandbox string, c *prog.Syscall) (bool, string) { + if _, ok := c.Args[0].Type.(*prog.ConstType); ok { + // This is for syz_open_dev$char/block. + return true, "" + } + fname, ok := extractStringConst(c.Args[0].Type) + if !ok { + panic("first open arg is not a pointer to string const") + } + if !strings.Contains(fname, "#") { + panic(fmt.Sprintf("%v does not contain # in the file name (should be openat)", c.Name)) + } + if checkUSBEmulation() == "" { + // These entries might not be available at boot time, + // but will be created by connected USB devices. + USBDevicePrefixes := []string{ + "/dev/hidraw", "/dev/usb/hiddev", "/dev/input/", + } + for _, prefix := range USBDevicePrefixes { + if strings.HasPrefix(fname, prefix) { + return true, "" + } + } + } + var check func(dev string) bool + check = func(dev string) bool { + if !strings.Contains(dev, "#") { + // Note: don't try to open them all, some can hang (e.g. /dev/snd/pcmC#D#p). + return osutil.IsExist(dev) + } + for i := 0; i < 10; i++ { + if check(strings.Replace(dev, "#", strconv.Itoa(i), 1)) { + return true + } + } + return false + } + if !check(fname) { + return false, fmt.Sprintf("file %v does not exist", fname) + } + return onlySandboxNoneOrNamespace(sandbox) +} + func isSupportedLSM(c *prog.Syscall) string { lsmOnce.Do(func() { data, err := ioutil.ReadFile("/sys/kernel/security/lsm") diff --git a/syz-manager/manager.go b/syz-manager/manager.go index e13747236..7c275e280 100644 --- a/syz-manager/manager.go +++ b/syz-manager/manager.go @@ -289,7 +289,7 @@ type ReproResult struct { } // Manager needs to be refactored (#605). -// nolint: gocyclo, gocognit +// nolint: gocyclo, gocognit, funlen func (mgr *Manager) vmLoop() { log.Logf(0, "booting test machines...") log.Logf(0, "wait for the connection from test machine...") -- cgit mrf-deployment