From 5ca014a29eab3dcdecd58d34c0a332fa78958872 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Fri, 20 Jan 2023 18:00:47 +0100 Subject: pkg/subsystem: add the basic caller-facing interface Users of the pkg/subsystem are only interested in 1) Fetching the list of subsystems for a given OS. 2) Matching a crash against the extracted set of subsystems. --- pkg/subsystem/raw_extractor.go | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 pkg/subsystem/raw_extractor.go (limited to 'pkg/subsystem/raw_extractor.go') diff --git a/pkg/subsystem/raw_extractor.go b/pkg/subsystem/raw_extractor.go new file mode 100644 index 000000000..4a86b1f6b --- /dev/null +++ b/pkg/subsystem/raw_extractor.go @@ -0,0 +1,48 @@ +// Copyright 2023 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 subsystem + +import ( + "github.com/google/syzkaller/pkg/subsystem/entity" + "github.com/google/syzkaller/pkg/subsystem/match" + "github.com/google/syzkaller/prog" +) + +// rawExtractor performs low-level subsystem matching (directly by a path or a syscall). +type rawExtractor struct { + matcher *match.PathMatcher + perCall map[string][]*entity.Subsystem +} + +func makeRawExtractor(list []*entity.Subsystem) *rawExtractor { + ret := &rawExtractor{ + matcher: match.MakePathMatcher(list), + perCall: make(map[string][]*entity.Subsystem), + } + for _, subsystem := range list { + for _, call := range subsystem.Syscalls { + ret.perCall[call] = append(ret.perCall[call], subsystem) + } + } + return ret +} + +func (e *rawExtractor) FromPath(path string) []*entity.Subsystem { + return e.matcher.Match(path) +} + +func (e *rawExtractor) FromProg(progBytes []byte) []*entity.Subsystem { + calls := make(map[*entity.Subsystem]struct{}) + progCalls, _, _ := prog.CallSet(progBytes) + for call := range progCalls { + for _, subsystem := range e.perCall[call] { + calls[subsystem] = struct{}{} + } + } + list := []*entity.Subsystem{} + for key := range calls { + list = append(list, key) + } + return list +} -- cgit mrf-deployment