aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/host/syscalls_linux.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-06-06 14:21:54 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-06-07 10:41:01 +0200
commit2c2b926cb74478a86014f40564517f7d424dc899 (patch)
tree7fbac38838913818333f8a9219b3866b6073f446 /pkg/host/syscalls_linux.go
parent948dd3af445f31e056db6116c09f095933baed5f (diff)
.golangci.yml: reduce function line count from 200 to 140
140 lines should be enough for everyone.
Diffstat (limited to 'pkg/host/syscalls_linux.go')
-rw-r--r--pkg/host/syscalls_linux.go85
1 files changed, 44 insertions, 41 deletions
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")