From 2b420c9686b7c95216d491a97fcd5158acb810f2 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Thu, 15 Sep 2022 13:36:15 +0000 Subject: sys/linux: extract raw images from syz_mount_image To simplify the extraction code, let's make segments non-overlapping even before execution. --- prog/analysis.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'prog/analysis.go') diff --git a/prog/analysis.go b/prog/analysis.go index 1b572f0c0..04f0b270a 100644 --- a/prog/analysis.go +++ b/prog/analysis.go @@ -10,6 +10,7 @@ package prog import ( "fmt" + "io" ) type state struct { @@ -337,3 +338,40 @@ func checkMaxCallID(id int) { panic(fmt.Sprintf("too many syscalls, have %v, max supported %v", id, fallbackCallMask+1)) } } + +type ExtractedAssetType int + +const ( + MountInRepro ExtractedAssetType = iota +) + +type ExtractedAsset struct { + Call int + Type ExtractedAssetType + Reader io.Reader + Error error +} + +func (p *Prog) ExtractAssets() []*ExtractedAsset { + handler := p.Target.ExtractMountedImage + if handler == nil { + // Such an operation is not supported by the target. + return nil + } + ret := []*ExtractedAsset{} + for id, c := range p.Calls { + // So far we only support the MountInRepro asset. + reader, err := handler(c) + if reader == nil && err == nil { + // This is not the call that contains the mount image. + continue + } + ret = append(ret, &ExtractedAsset{ + Type: MountInRepro, + Call: id, + Reader: reader, + Error: err, + }) + } + return ret +} -- cgit mrf-deployment