diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-01-23 14:07:01 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-01-23 15:05:21 +0100 |
| commit | 0e8428d26ffd80789aa83442676e6fb800e9c0ff (patch) | |
| tree | 5d110f7952fcdc8a64e0acb1f714d6d54505d3ff /tools | |
| parent | 9ab9b329d9c8d1477d5b2921671701d9a7a6d2cd (diff) | |
tools/syz-check: add limited checking of varlen structs
Stop at the fist varlen field, but check the preceeding ones.
Frequently the varlen array is the last field,
so we should get good checking for these cases.
Update #590
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/syz-check/check.go | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/tools/syz-check/check.go b/tools/syz-check/check.go index fbb6432fe..513a0d74c 100644 --- a/tools/syz-check/check.go +++ b/tools/syz-check/check.go @@ -92,6 +92,9 @@ func main() { func check(OS, arch, obj string, dwarf, netlink bool) ([]Warn, error) { var warnings []Warn + if obj == "" { + return nil, fmt.Errorf("no object file in -obj-%v flag", arch) + } structDescs, locs, warnings1, err := parseDescriptions(OS, arch) if err != nil { return nil, err @@ -206,9 +209,6 @@ func checkImpl(structs map[string]*dwarf.StructType, structDescs []*prog.KeyedSt checked := make(map[string]bool) for _, str := range structDescs { typ := str.Desc - if typ.Varlen() { - continue - } if checked[typ.Name()] { continue } @@ -234,14 +234,17 @@ func checkStruct(typ *prog.StructDesc, astStruct *ast.Struct, str *dwarf.StructT } name := typ.TemplateName() if str == nil { - warn(astStruct.Pos, WarnNoSuchStruct, "%v", name) + // Varlen structs are frequently not described in kernel (not possible in C). + if !typ.Varlen() { + warn(astStruct.Pos, WarnNoSuchStruct, "%v", name) + } return warnings, nil } - if typ.Size() != uint64(str.ByteSize) { + if !typ.Varlen() && typ.Size() != uint64(str.ByteSize) { warn(astStruct.Pos, WarnBadStructSize, "%v: syz=%v kernel=%v", name, typ.Size(), str.ByteSize) } // TODO: handle unions, currently we should report some false errors. - if str.Kind == "union" { + if str.Kind == "union" || astStruct.IsUnion { return warnings, nil } // TODO: we could also check enums (elements match corresponding flags in syzkaller). @@ -261,6 +264,10 @@ func checkStruct(typ *prog.StructDesc, astStruct *ast.Struct, str *dwarf.StructT ai := 0 offset := uint64(0) for _, field := range typ.Fields { + if field.Varlen() { + ai = len(str.Field) + break + } if prog.IsPad(field) { offset += field.Size() continue |
