aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-11-25 12:03:30 +0100
committerDmitry Vyukov <dvyukov@google.com>2024-11-25 14:12:10 +0000
commit02832ca35ded902878eb2a3aa43a1235de5f8ac4 (patch)
treed9f362983f5df58518549650bc27806853b38b6f /pkg
parenta84878fcfef572bb166d73bcc5974ea50a3fde64 (diff)
pkg/vminfo: refactor few things
Use default nop implementation for most openbsd/netbsd methods. Move linux-specific vm type checks to linux code. Remove indirection for CheckFiles as we have for RequiredFiles.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/vminfo/linux.go13
-rw-r--r--pkg/vminfo/netbsd.go18
-rw-r--r--pkg/vminfo/openbsd.go18
-rw-r--r--pkg/vminfo/vminfo.go30
4 files changed, 24 insertions, 55 deletions
diff --git a/pkg/vminfo/linux.go b/pkg/vminfo/linux.go
index 0f598515c..52f6982b2 100644
--- a/pkg/vminfo/linux.go
+++ b/pkg/vminfo/linux.go
@@ -13,9 +13,13 @@ import (
"sort"
"strconv"
"strings"
+
+ "github.com/google/syzkaller/sys/targets"
)
-type linux int
+type linux struct {
+ vmType string
+}
func (linux) RequiredFiles() []string {
return []string{
@@ -27,7 +31,7 @@ func (linux) RequiredFiles() []string {
}
}
-func (linux) checkFiles() []string {
+func (linux) CheckFiles() []string {
return []string{
"/proc/version",
"/proc/filesystems",
@@ -42,7 +46,10 @@ func (linux) machineInfos() []machineInfoFunc {
}
}
-func (linux) parseModules(files filesystem) ([]*KernelModule, error) {
+func (linux linux) parseModules(files filesystem) ([]*KernelModule, error) {
+ if linux.vmType == targets.GVisor || linux.vmType == targets.Starnix {
+ return nil, nil
+ }
var modules []*KernelModule
re := regexp.MustCompile(`(\w+) ([0-9]+) .*(0[x|X][a-fA-F0-9]+)[^\n]*`)
modulesText, _ := files.ReadFile("/proc/modules")
diff --git a/pkg/vminfo/netbsd.go b/pkg/vminfo/netbsd.go
index e79e5a05f..13b666f91 100644
--- a/pkg/vminfo/netbsd.go
+++ b/pkg/vminfo/netbsd.go
@@ -7,22 +7,8 @@ import (
"github.com/google/syzkaller/prog"
)
-type netbsd int
-
-func (netbsd) RequiredFiles() []string {
- return nil
-}
-
-func (netbsd) checkFiles() []string {
- return nil
-}
-
-func (netbsd) parseModules(files filesystem) ([]*KernelModule, error) {
- return nil, nil
-}
-
-func (netbsd) machineInfos() []machineInfoFunc {
- return nil
+type netbsd struct {
+ nopChecker
}
func (netbsd) syscallCheck(ctx *checkContext, call *prog.Syscall) string {
diff --git a/pkg/vminfo/openbsd.go b/pkg/vminfo/openbsd.go
index e7c0d78e2..fe7c0191e 100644
--- a/pkg/vminfo/openbsd.go
+++ b/pkg/vminfo/openbsd.go
@@ -7,22 +7,8 @@ import (
"github.com/google/syzkaller/prog"
)
-type openbsd int
-
-func (openbsd) RequiredFiles() []string {
- return nil
-}
-
-func (openbsd) checkFiles() []string {
- return nil
-}
-
-func (openbsd) parseModules(files filesystem) ([]*KernelModule, error) {
- return nil, nil
-}
-
-func (openbsd) machineInfos() []machineInfoFunc {
- return nil
+type openbsd struct {
+ nopChecker
}
func (openbsd) syscallCheck(ctx *checkContext, call *prog.Syscall) string {
diff --git a/pkg/vminfo/vminfo.go b/pkg/vminfo/vminfo.go
index 89a35e2b2..d2a728585 100644
--- a/pkg/vminfo/vminfo.go
+++ b/pkg/vminfo/vminfo.go
@@ -37,7 +37,6 @@ type KernelModule struct {
type Checker struct {
checker
- vmType string
source queue.Source
checkContext *checkContext
}
@@ -59,18 +58,17 @@ func New(ctx context.Context, cfg *Config) *Checker {
var impl checker
switch cfg.Target.OS {
case targets.Linux:
- impl = new(linux)
+ impl = &linux{vmType: cfg.VMType}
case targets.NetBSD:
impl = new(netbsd)
case targets.OpenBSD:
impl = new(openbsd)
default:
- impl = new(stub)
+ impl = new(nopChecker)
}
executor := queue.Plain()
return &Checker{
checker: impl,
- vmType: cfg.VMType,
source: queue.Deduplicate(ctx, executor),
checkContext: newCheckContext(ctx, cfg, impl, executor),
}
@@ -78,11 +76,7 @@ func New(ctx context.Context, cfg *Config) *Checker {
func (checker *Checker) MachineInfo(fileInfos []*flatrpc.FileInfo) ([]*KernelModule, []byte, error) {
files := createVirtualFilesystem(fileInfos)
- var modules []*KernelModule
- var err error
- if checker.vmType != targets.GVisor && checker.vmType != targets.Starnix {
- modules, err = checker.parseModules(files)
- }
+ modules, err := checker.parseModules(files)
if err != nil {
return nil, nil, err
}
@@ -105,10 +99,6 @@ func (checker *Checker) MachineInfo(fileInfos []*flatrpc.FileInfo) ([]*KernelMod
return modules, info.Bytes(), nil
}
-func (checker *Checker) CheckFiles() []string {
- return checker.checkFiles()
-}
-
func (checker *Checker) Run(files []*flatrpc.FileInfo, featureInfos []*flatrpc.FeatureInfo) (
map[*prog.Syscall]bool, map[*prog.Syscall]string, Features, error) {
ctx := checker.checkContext
@@ -128,7 +118,7 @@ type machineInfoFunc func(files filesystem, w io.Writer) (string, error)
type checker interface {
RequiredFiles() []string
- checkFiles() []string
+ CheckFiles() []string
parseModules(files filesystem) ([]*KernelModule, error)
machineInfos() []machineInfoFunc
syscallCheck(*checkContext, *prog.Syscall) string
@@ -179,24 +169,24 @@ func (files filesystem) ReadDir(dir string) []string {
return res
}
-type stub int
+type nopChecker int
-func (stub) RequiredFiles() []string {
+func (nopChecker) RequiredFiles() []string {
return nil
}
-func (stub) checkFiles() []string {
+func (nopChecker) CheckFiles() []string {
return nil
}
-func (stub) parseModules(files filesystem) ([]*KernelModule, error) {
+func (nopChecker) parseModules(files filesystem) ([]*KernelModule, error) {
return nil, nil
}
-func (stub) machineInfos() []machineInfoFunc {
+func (nopChecker) machineInfos() []machineInfoFunc {
return nil
}
-func (stub) syscallCheck(*checkContext, *prog.Syscall) string {
+func (nopChecker) syscallCheck(*checkContext, *prog.Syscall) string {
return ""
}