aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2022-11-25 12:22:58 +0100
committerDmitry Vyukov <dvyukov@google.com>2022-11-25 12:56:53 +0100
commit0d68fcb4879b7f76e4242bfa0b0004c9a0eb9b5e (patch)
tree92944631f1eba4f97a3efed227f5d2ab4d77dfa8 /tools
parent74a66371788c1eb22bde25c9c422c7754596d7f5 (diff)
tools/syz-imagegen: generate fake empty images for all filesystems
Since syz_mount_image calls are no_generate we need to add at least some empty seeds for all for filesystems.
Diffstat (limited to 'tools')
-rw-r--r--tools/syz-imagegen/imagegen.go45
1 files changed, 37 insertions, 8 deletions
diff --git a/tools/syz-imagegen/imagegen.go b/tools/syz-imagegen/imagegen.go
index f62ef1b3d..f0b0fe53b 100644
--- a/tools/syz-imagegen/imagegen.go
+++ b/tools/syz-imagegen/imagegen.go
@@ -530,13 +530,17 @@ var fileSystems = []FileSystem{
},
}
-const parttable = "parttable"
+const (
+ syzMountImage = "syz_mount_image"
+ syzReadPartTable = "syz_read_part_table"
+ parttable = "parttable"
+)
func (fs FileSystem) filePrefix() string {
if fs.Name == parttable {
- return "syz_read_part_table"
+ return syzReadPartTable
}
- return "syz_mount_image_" + fs.Name
+ return syzMountImage + "_" + fs.Name
}
// Image represents one image we generate for a file system.
@@ -557,8 +561,7 @@ func (image *Image) String() string {
if image.size >= 1<<20 {
size = fmt.Sprintf("%vMB", image.size>>20)
}
- result := fmt.Sprintf("#%02v: mkfs.%v[%5v] %v", image.index, image.fs.Name, size, image.flags)
- return result
+ return fmt.Sprintf("#%02v: mkfs.%v[%5v] %v", image.index, image.fs.Name, size, image.flags)
}
var errShutdown = errors.New("shutdown")
@@ -586,6 +589,7 @@ func main() {
if err != nil {
tool.Fail(err)
}
+ addEmptyImages(target)
images, err := generateImages(target, *flagFS, *flagList)
if err != nil {
tool.Fail(err)
@@ -628,6 +632,31 @@ func main() {
printResults(images, shutdown, *flagKeepImage, *flagVerbose)
}
+func addEmptyImages(target *prog.Target) {
+ // Since syz_mount_image calls are no_generate we need to add at least some
+ // empty seeds for all the filesystems.
+ have := make(map[string]bool)
+ for _, fs := range fileSystems {
+ have[fs.Name] = true
+ }
+ for _, call := range target.Syscalls {
+ if call.CallName != syzMountImage {
+ continue
+ }
+ name := strings.TrimPrefix(call.Name, syzMountImage+"$")
+ if have[name] {
+ continue
+ }
+ fileSystems = append(fileSystems, FileSystem{
+ Name: name,
+ MinSize: 1 << 20,
+ ReadOnly: true,
+ MkfsFlags: []string{"fake empty image"},
+ Mkfs: func(image *Image) error { return nil },
+ })
+ }
+}
+
func printResults(images []*Image, shutdown chan struct{}, keepImage, verbose bool) {
good, failed := 0, 0
hashes := make(map[uint32][]*Image)
@@ -851,10 +880,10 @@ func writeImage(image *Image, data []byte) ([]byte, error) {
compressedData := prog.Compress(data)
b64Data := prog.EncodeB64(compressedData)
if image.fs.Name == parttable {
- fmt.Fprintf(buf, `syz_read_part_table(AUTO, &AUTO="$`)
+ fmt.Fprintf(buf, `%s(AUTO, &AUTO="$`, syzReadPartTable)
} else {
- fmt.Fprintf(buf, `syz_mount_image$%v(&AUTO='%v\x00', &AUTO='./file0\x00', 0x0, &AUTO, 0x1, AUTO, &AUTO="$`,
- image.fs.Name, image.fs.Name)
+ fmt.Fprintf(buf, `%s$%v(&AUTO='%v\x00', &AUTO='./file0\x00', 0x0, &AUTO, 0x1, AUTO, &AUTO="$`,
+ syzMountImage, image.fs.Name, image.fs.Name)
}
buf.Write(b64Data)
fmt.Fprintf(buf, "\")\n")