aboutsummaryrefslogtreecommitdiffstats
path: root/prog/rand.go
diff options
context:
space:
mode:
authorHrutvik Kanabar <hrutvik@google.com>2022-09-19 10:19:25 +0000
committerMarco Elver <me@marcoelver.com>2022-09-22 16:42:04 +0200
commit6099a1719c3532818617a2616a3380b080c56554 (patch)
tree0b9ec3effbcac3aace955f0222c8b7315be56126 /prog/rand.go
parent60af505093169db753e7b7b319460495e4df554b (diff)
prog: add an attribute for syscalls which should not be generated
Create a `no_generate` attribute to be used with syscalls that `syzkaller` should not try to generate from scratch. In other words, `syzkaller` will only use seeds of this call. This will be useful for syscalls which are unlikely to be correctly generated. In particular, prevent these syscalls from being included in the choice table or from being considered as possible resource constructors. Also add a test which will attempt to generate programs with a bias towards `no_generate` syscalls, and flag up any that make it into result programs. Currently there are no `no_generate` syscalls, but the next commit will add some.
Diffstat (limited to 'prog/rand.go')
-rw-r--r--prog/rand.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/prog/rand.go b/prog/rand.go
index 1db5cd07a..2b08998c6 100644
--- a/prog/rand.go
+++ b/prog/rand.go
@@ -436,7 +436,7 @@ func (r *randGen) createResource(s *state, res *ResourceType, dir Dir) (Arg, []*
func (r *randGen) enabledCtors(s *state, kind string) []*Syscall {
var metas []*Syscall
for _, meta := range r.target.resourceCtors[kind] {
- if s.ct.Enabled(meta.ID) {
+ if s.ct.Generatable(meta.ID) {
metas = append(metas, meta)
}
}
@@ -562,7 +562,11 @@ func (r *randGen) generateCall(s *state, p *Prog, insertionPoint int) []*Call {
biasCall := -1
if insertionPoint > 0 {
// Choosing the base call is based on the insertion point of the new calls sequence.
- biasCall = p.Calls[r.Intn(insertionPoint)].Meta.ID
+ insertionCall := p.Calls[r.Intn(insertionPoint)].Meta
+ if !insertionCall.Attrs.NoGenerate {
+ // We must be careful not to bias towards a non-generatable call.
+ biasCall = insertionCall.ID
+ }
}
idx := s.ct.choose(r.Rand, biasCall)
meta := r.target.Syscalls[idx]
@@ -573,6 +577,9 @@ func (r *randGen) generateParticularCall(s *state, meta *Syscall) (calls []*Call
if meta.Attrs.Disabled {
panic(fmt.Sprintf("generating disabled call %v", meta.Name))
}
+ if meta.Attrs.NoGenerate {
+ panic(fmt.Sprintf("generating no_generate call: %v", meta.Name))
+ }
c := MakeCall(meta, nil)
c.Args, calls = r.generateArgs(s, meta.Args, DirIn)
r.target.assignSizesCall(c)
@@ -588,7 +595,10 @@ func (target *Target) GenerateAllSyzProg(rs rand.Source) *Prog {
s := newState(target, target.DefaultChoiceTable(), nil)
handled := make(map[string]bool)
for _, meta := range target.Syscalls {
- if !strings.HasPrefix(meta.CallName, "syz_") || handled[meta.CallName] || meta.Attrs.Disabled {
+ if !strings.HasPrefix(meta.CallName, "syz_") ||
+ handled[meta.CallName] ||
+ meta.Attrs.Disabled ||
+ meta.Attrs.NoGenerate {
continue
}
handled[meta.CallName] = true