From 0e8428d26ffd80789aa83442676e6fb800e9c0ff Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 23 Jan 2020 14:07:01 +0100 Subject: 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 --- tools/syz-check/check.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'tools') 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 -- cgit mrf-deployment