aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Steuck <blackgnezdo@gmail.com>2018-11-27 04:16:05 -0800
committerDmitry Vyukov <dvyukov@google.com>2018-11-27 13:16:05 +0100
commit0b29b7f95253d645475f4cc66a74f653437fa72d (patch)
treeb1ec00ce49d96d04a9606f6745ffcf9a1534c9d3
parent6419afbb779b26af853b46d8ad79cfe52b6f7805 (diff)
prog: prevent sandbox escaping files from entering s.files
-rw-r--r--prog/analysis.go2
-rw-r--r--prog/rand.go2
-rw-r--r--prog/rand_test.go26
3 files changed, 28 insertions, 2 deletions
diff --git a/prog/analysis.go b/prog/analysis.go
index c26e14014..f03f828b9 100644
--- a/prog/analysis.go
+++ b/prog/analysis.go
@@ -83,7 +83,7 @@ func (s *state) analyzeImpl(c *Call, resources bool) {
case BufferString:
s.strings[val] = true
case BufferFilename:
- if len(val) < 3 {
+ if len(val) < 3 || escapingFilename(val) {
// This is not our file, probalby one of specialFiles.
return
}
diff --git a/prog/rand.go b/prog/rand.go
index 2e028d230..b479d1e8c 100644
--- a/prog/rand.go
+++ b/prog/rand.go
@@ -158,7 +158,7 @@ func (r *randGen) filename(s *state, typ *BufferType) string {
panic(fmt.Sprintf("zero-terminated filename: %q", fn))
}
if escapingFilename(fn) {
- panic(fmt.Sprintf("sandbox escaping file name %q", fn))
+ panic(fmt.Sprintf("sandbox escaping file name %q, s.files are %v", fn, s.files))
}
if !typ.Varlen() {
size := typ.Size()
diff --git a/prog/rand_test.go b/prog/rand_test.go
new file mode 100644
index 000000000..1771a0052
--- /dev/null
+++ b/prog/rand_test.go
@@ -0,0 +1,26 @@
+// Copyright 2018 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 prog
+
+import (
+ "math/rand"
+ "testing"
+)
+
+func TestNotEscaping(t *testing.T) {
+ r := newRand(nil, rand.NewSource(0))
+ s := &state{
+ files: map[string]bool{"./file0": true},
+ }
+ bound := 1000000
+ if testing.Short() {
+ bound = 1000
+ }
+ for i := 0; i < bound; i++ {
+ fn := r.filenameImpl(s)
+ if escapingFilename(fn) {
+ t.Errorf("sandbox escaping file name %q", fn)
+ }
+ }
+}