aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--host/host.go11
-rw-r--r--syz-fuzzer/fuzzer.go17
-rw-r--r--syz-gce/syz-gce.go3
-rw-r--r--syz-manager/config/config.go7
-rw-r--r--syz-manager/html.go3
-rw-r--r--syz-manager/manager.go7
-rw-r--r--tools/syz-dashtool/dashtool.go3
-rw-r--r--vm/kvm/kvm.go6
-rw-r--r--vm/odroid/odroid.go8
-rw-r--r--vm/qemu/qemu.go8
10 files changed, 33 insertions, 40 deletions
diff --git a/host/host.go b/host/host.go
index 513f119ac..4e634f1aa 100644
--- a/host/host.go
+++ b/host/host.go
@@ -6,12 +6,12 @@ package host
import (
"bytes"
"io/ioutil"
- "os"
"runtime"
"strconv"
"strings"
"syscall"
+ "github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/sys"
)
@@ -79,8 +79,7 @@ func isSupportedSyzkall(c *sys.Call) bool {
var check func(dev string) bool
check = func(dev string) bool {
if !strings.Contains(dev, "#") {
- _, err := os.Stat(dev)
- return err == nil
+ return osutil.IsExist(dev)
}
for i := 0; i < 10; i++ {
if check(strings.Replace(dev, "#", strconv.Itoa(i), 1)) {
@@ -93,11 +92,9 @@ func isSupportedSyzkall(c *sys.Call) bool {
case "syz_open_pts":
return true
case "syz_fuse_mount":
- _, err := os.Stat("/dev/fuse")
- return err == nil
+ return osutil.IsExist("/dev/fuse")
case "syz_fuseblk_mount":
- _, err := os.Stat("/dev/fuse")
- return err == nil && syscall.Getuid() == 0
+ return osutil.IsExist("/dev/fuse") && syscall.Getuid() == 0
case "syz_emit_ethernet", "syz_extract_tcp_res":
fd, err := syscall.Open("/dev/net/tun", syscall.O_RDWR, 0)
if err == nil {
diff --git a/syz-fuzzer/fuzzer.go b/syz-fuzzer/fuzzer.go
index 6b2b0bc6d..167a6a7cb 100644
--- a/syz-fuzzer/fuzzer.go
+++ b/syz-fuzzer/fuzzer.go
@@ -26,6 +26,7 @@ import (
"github.com/google/syzkaller/ipc"
"github.com/google/syzkaller/pkg/hash"
. "github.com/google/syzkaller/pkg/log"
+ "github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/prog"
. "github.com/google/syzkaller/rpctype"
"github.com/google/syzkaller/sys"
@@ -161,7 +162,10 @@ func main() {
}
if r.NeedCheck {
- a := &CheckArgs{Name: *flagName, UserNamespaces: hasUserNamespaces()}
+ a := &CheckArgs{
+ Name: *flagName,
+ UserNamespaces: osutil.IsExist("/proc/self/ns/user"),
+ }
if fd, err := syscall.Open("/sys/kernel/debug/kcov", syscall.O_RDWR, 0); err == nil {
syscall.Close(fd)
a.Kcov = true
@@ -786,14 +790,3 @@ func kmemleakScan(report bool) {
panic(err)
}
}
-
-func hasUserNamespaces() bool {
- if _, err := os.Stat("/proc/self/ns/user"); err != nil {
- // failed to stat /proc/self/ns/user this could be because
- // 1) the file does not exist
- // 2) we do not have permission
- return false
- }
-
- return true
-}
diff --git a/syz-gce/syz-gce.go b/syz-gce/syz-gce.go
index 59a83f9ae..2d4c58dbd 100644
--- a/syz-gce/syz-gce.go
+++ b/syz-gce/syz-gce.go
@@ -41,6 +41,7 @@ import (
"github.com/google/syzkaller/pkg/git"
"github.com/google/syzkaller/pkg/kernel"
. "github.com/google/syzkaller/pkg/log"
+ "github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/syz-manager/config"
)
@@ -462,7 +463,7 @@ func writeManagerConfig(cfg *Config, httpPort int, file string) error {
tag = tag[:len(tag)-1]
}
sshKey := ""
- if _, err := os.Stat("image/key"); err == nil {
+ if osutil.IsExist("image/key") {
sshKey = "image/key"
}
managerCfg := &config.Config{
diff --git a/syz-manager/config/config.go b/syz-manager/config/config.go
index 495daba09..a864a517d 100644
--- a/syz-manager/config/config.go
+++ b/syz-manager/config/config.go
@@ -6,7 +6,6 @@ package config
import (
"encoding/json"
"fmt"
- "os"
"path/filepath"
"regexp"
"strings"
@@ -70,13 +69,13 @@ func Parse(filename string) (*Config, map[int]bool, error) {
if err := pkgconfig.LoadFile(filename, cfg); err != nil {
return nil, nil, err
}
- if _, err := os.Stat(filepath.Join(cfg.Syzkaller, "bin/syz-fuzzer")); err != nil {
+ if !osutil.IsExist(filepath.Join(cfg.Syzkaller, "bin/syz-fuzzer")) {
return nil, nil, fmt.Errorf("bad config syzkaller param: can't find bin/syz-fuzzer")
}
- if _, err := os.Stat(filepath.Join(cfg.Syzkaller, "bin/syz-executor")); err != nil {
+ if !osutil.IsExist(filepath.Join(cfg.Syzkaller, "bin/syz-executor")) {
return nil, nil, fmt.Errorf("bad config syzkaller param: can't find bin/syz-executor")
}
- if _, err := os.Stat(filepath.Join(cfg.Syzkaller, "bin/syz-execprog")); err != nil {
+ if !osutil.IsExist(filepath.Join(cfg.Syzkaller, "bin/syz-execprog")) {
return nil, nil, fmt.Errorf("bad config syzkaller param: can't find bin/syz-execprog")
}
if cfg.Http == "" {
diff --git a/syz-manager/html.go b/syz-manager/html.go
index 5cb208170..c8a34c300 100644
--- a/syz-manager/html.go
+++ b/syz-manager/html.go
@@ -21,6 +21,7 @@ import (
"github.com/google/syzkaller/cover"
. "github.com/google/syzkaller/pkg/log"
+ "github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/prog"
"github.com/google/syzkaller/report"
"github.com/google/syzkaller/sys"
@@ -349,7 +350,7 @@ func readCrash(workdir, dir string, full bool) *UICrashType {
tag, _ := ioutil.ReadFile(filepath.Join(crashdir, dir, "tag"+index))
crash.Tag = string(tag)
reportFile := filepath.Join("crashes", dir, "report"+index)
- if _, err := os.Stat(filepath.Join(workdir, reportFile)); err == nil {
+ if osutil.IsExist(filepath.Join(workdir, reportFile)) {
crash.Report = reportFile
}
}
diff --git a/syz-manager/manager.go b/syz-manager/manager.go
index b5e578c9f..be480dca5 100644
--- a/syz-manager/manager.go
+++ b/syz-manager/manager.go
@@ -25,6 +25,7 @@ import (
"github.com/google/syzkaller/pkg/db"
"github.com/google/syzkaller/pkg/hash"
. "github.com/google/syzkaller/pkg/log"
+ "github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/prog"
"github.com/google/syzkaller/report"
"github.com/google/syzkaller/repro"
@@ -580,11 +581,11 @@ func (mgr *Manager) needRepro(desc string) bool {
}
sig := hash.Hash([]byte(desc))
dir := filepath.Join(mgr.crashdir, sig.String())
- if _, err := os.Stat(filepath.Join(dir, "repro.prog")); err == nil {
+ if osutil.IsExist(filepath.Join(dir, "repro.prog")) {
return false
}
for i := 0; i < maxReproAttempts; i++ {
- if _, err := os.Stat(filepath.Join(dir, fmt.Sprintf("repro%v", i))); err != nil {
+ if !osutil.IsExist(filepath.Join(dir, fmt.Sprintf("repro%v", i))) {
return true
}
}
@@ -609,7 +610,7 @@ func (mgr *Manager) saveRepro(crash *Crash, res *repro.Result) {
}
for i := 0; i < maxReproAttempts; i++ {
name := filepath.Join(dir, fmt.Sprintf("repro%v", i))
- if _, err := os.Stat(name); err != nil {
+ if !osutil.IsExist(name) {
ioutil.WriteFile(name, nil, 0660)
break
}
diff --git a/tools/syz-dashtool/dashtool.go b/tools/syz-dashtool/dashtool.go
index ca5fe7eac..df31f32e7 100644
--- a/tools/syz-dashtool/dashtool.go
+++ b/tools/syz-dashtool/dashtool.go
@@ -17,6 +17,7 @@ import (
"strings"
"github.com/google/syzkaller/dashboard"
+ "github.com/google/syzkaller/pkg/osutil"
)
var (
@@ -149,7 +150,7 @@ func reportRepro(dash *dashboard.Dashboard, crashdir string) {
}
func reportAll(dash *dashboard.Dashboard, crashes string) {
- if _, err := os.Stat(filepath.Join(crashes, "description")); err == nil {
+ if osutil.IsExist(filepath.Join(crashes, "description")) {
uploadDir(dash, crashes)
return
}
diff --git a/vm/kvm/kvm.go b/vm/kvm/kvm.go
index c18ed27c7..5c4c0f036 100644
--- a/vm/kvm/kvm.go
+++ b/vm/kvm/kvm.go
@@ -78,8 +78,8 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) {
if _, err := exec.LookPath(cfg.Lkvm); err != nil {
return nil, err
}
- if _, err := os.Stat(cfg.Kernel); err != nil {
- return nil, fmt.Errorf("kernel file '%v' does not exist: %v", cfg.Kernel, err)
+ if !osutil.IsExist(cfg.Kernel) {
+ return nil, fmt.Errorf("kernel file '%v' does not exist", cfg.Kernel)
}
if cfg.Cpu < 1 || cfg.Cpu > 1024 {
return nil, fmt.Errorf("invalid config param cpu: %v, want [1-1024]", cfg.Cpu)
@@ -268,7 +268,7 @@ func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command strin
resultErr = vmimpl.TimeoutErr
break loop
case <-secondTicker.C:
- if _, err := os.Stat(cmdFile); err != nil {
+ if !osutil.IsExist(cmdFile) {
resultErr = nil
break loop
}
diff --git a/vm/odroid/odroid.go b/vm/odroid/odroid.go
index dcc4135b6..69c77b9c6 100644
--- a/vm/odroid/odroid.go
+++ b/vm/odroid/odroid.go
@@ -76,11 +76,11 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) {
if cfg.Hub_Port == 0 {
return nil, fmt.Errorf("config param hub_port is empty")
}
- if _, err := os.Stat(cfg.Sshkey); err != nil {
- return nil, fmt.Errorf("ssh key '%v' does not exist: %v", cfg.Sshkey, err)
+ if !osutil.IsExist(cfg.Sshkey) {
+ return nil, fmt.Errorf("ssh key '%v' does not exist", cfg.Sshkey)
}
- if _, err := os.Stat(cfg.Console); err != nil {
- return nil, fmt.Errorf("console file '%v' does not exist: %v", cfg.Console, err)
+ if !osutil.IxExist(cfg.Console) {
+ return nil, fmt.Errorf("console file '%v' does not exist", cfg.Console)
}
pool := &Pool{
cfg: cfg,
diff --git a/vm/qemu/qemu.go b/vm/qemu/qemu.go
index ba0cb6f78..62fb408f9 100644
--- a/vm/qemu/qemu.go
+++ b/vm/qemu/qemu.go
@@ -83,11 +83,11 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) {
return nil, fmt.Errorf("9p image requires kernel")
}
} else {
- if _, err := os.Stat(env.Image); err != nil {
- return nil, fmt.Errorf("image file '%v' does not exist: %v", env.Image, err)
+ if !osutil.IsExist(env.Image) {
+ return nil, fmt.Errorf("image file '%v' does not exist", env.Image)
}
- if _, err := os.Stat(cfg.Sshkey); err != nil {
- return nil, fmt.Errorf("ssh key '%v' does not exist: %v", cfg.Sshkey, err)
+ if !osutil.IsExist(cfg.Sshkey) {
+ return nil, fmt.Errorf("ssh key '%v' does not exist", cfg.Sshkey)
}
}
if cfg.Cpu <= 0 || cfg.Cpu > 1024 {