diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2024-04-16 10:04:45 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-04-24 15:23:14 +0000 |
| commit | 7009aebcd4c978e0f9d7cbb1f45c482104ff3019 (patch) | |
| tree | 23f0df5110b6dc308c48c7d02a321e9f430c3bde /pkg/vminfo/vminfo_test.go | |
| parent | 4bf1b40dbb879b2f7b28511b0adbd0a1ff16e4a0 (diff) | |
pkg/vminfo: add package
This moves significant part of logic from the target to host (#1541),
eventually this will allow us to switch target code from Go to C++.
Currnetly syz-fuzzer parses a number of system files (/proc/cpuinfo)
in non-trivial ways and passes that info to the host.
This is problematic to recreate in C++.
So instead make the fuzzer part as simple as possible:
now it merely reads the gives set of files and returns contents.
The rest of the parsing happens on the host (the new vminfo package).
Package vminfo extracts information about the target VM.
The package itself runs on the host, which may be a different OS/arch.
User of the package first requests set of files that needs to be fetched from the VM
(Checker.RequiredFiles), then fetches these files, and calls Checker.MachineInfo
to parse the files and extract information about the VM.
The information includes information about kernel modules and OS-specific info
(for Linux that includes things like parsed /proc/cpuinfo).
This also requires changing RPC flow between fuzzer and manager.
Currently, Check call is optional and happens only for first VMs.
With this change Check is always done because we need to return
contents of the requested files always.
The plan is to switch the rest of the pkg/host package to this scheme later:
instead of some complex custom logic, we need to express it as some
simple operations on the target (checking file presence, etc), and the rest
of the logic on the host.
Diffstat (limited to 'pkg/vminfo/vminfo_test.go')
| -rw-r--r-- | pkg/vminfo/vminfo_test.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/pkg/vminfo/vminfo_test.go b/pkg/vminfo/vminfo_test.go new file mode 100644 index 000000000..e4dc1bfb8 --- /dev/null +++ b/pkg/vminfo/vminfo_test.go @@ -0,0 +1,52 @@ +// Copyright 2024 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package vminfo + +import ( + "runtime" + "strings" + "testing" + + "github.com/google/syzkaller/pkg/host" + "github.com/google/syzkaller/pkg/mgrconfig" +) + +func TestHostMachineInfo(t *testing.T) { + checker, files := hostChecker() + dups := make(map[string]bool) + for _, file := range files { + if file.Name[0] != '/' || file.Name[len(file.Name)-1] == '/' || strings.Contains(file.Name, "\\") { + t.Errorf("malformed file %q", file.Name) + } + // Reading duplicate files leads to duplicate work. + if dups[file.Name] { + t.Errorf("duplicate file %q", file.Name) + } + dups[file.Name] = true + if file.Error != "" { + t.Logf("failed to read %q: %s", file.Name, file.Error) + } + } + modules, info, err := checker.MachineInfo(files) + if err != nil { + t.Fatal(err) + } + t.Logf("machine info:\n%s", info) + for _, module := range modules { + t.Logf("module %q: addr 0x%x size %v", module.Name, module.Addr, module.Size) + } +} + +func hostChecker() (*Checker, []host.FileInfo) { + cfg := &mgrconfig.Config{ + Derived: mgrconfig.Derived{ + TargetOS: runtime.GOOS, + TargetArch: runtime.GOARCH, + TargetVMArch: runtime.GOARCH, + }, + } + checker := New(cfg) + files := host.ReadFiles(checker.RequiredFiles()) + return checker, files +} |
