From 48ec7344e13eaeee104976fb52d3ed30c1073d5d Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Wed, 14 Dec 2022 19:23:40 +0100 Subject: pkg/subsystem: extract subsystems from syz_mount_image$ calls Dump the mapping between the currently available pseudo syscalls and the corresponding subsystems. --- dashboard/app/config_linux_test.go | 4 +++ pkg/subsystem/extract.go | 53 ++++++++++++++++++++++++++++++++++++++ pkg/subsystem/extract_test.go | 41 +++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 dashboard/app/config_linux_test.go diff --git a/dashboard/app/config_linux_test.go b/dashboard/app/config_linux_test.go new file mode 100644 index 000000000..c95204de3 --- /dev/null +++ b/dashboard/app/config_linux_test.go @@ -0,0 +1,4 @@ +// Copyright 2022 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 main diff --git a/pkg/subsystem/extract.go b/pkg/subsystem/extract.go index 181c15835..e29fbab01 100644 --- a/pkg/subsystem/extract.go +++ b/pkg/subsystem/extract.go @@ -24,6 +24,7 @@ type Crash struct { func MakeLinuxSubsystemExtractor() *SubsystemExtractor { return &SubsystemExtractor{ pathToSubsystems: linuxPathToSubsystems, + callToSubsystems: linuxCallToSubsystems, } } @@ -60,6 +61,58 @@ func linuxPathToSubsystems(path string) []string { return ret } +func linuxCallToSubsystems(call string) []string { + name := linuxCallToSubsystemsMap[call] + if name != "" { + return []string{name} + } + return nil +} + +var linuxCallToSubsystemsMap = map[string]string{ + "syz_mount_image$adfs": "adfs", + "syz_mount_image$affs": "affs", + "syz_mount_image$befs": "befs", + "syz_mount_image$bfs": "bfs", + "syz_mount_image$btrfs": "btrfs", + "syz_mount_image$cramfs": "cramfs", + "syz_mount_image$efs": "efs", + "syz_mount_image$erofs": "erofs", + "syz_mount_image$exfat": "exfat", + "syz_mount_image$ext4": "ext4", + "syz_mount_image$f2fs": "f2fs", + "syz_mount_image$gfs2": "gfs2", + "syz_mount_image$gfs2meta": "gfs2", + "syz_mount_image$hfs": "hfs", + "syz_mount_image$hfsplus": "hfsplus", + "syz_mount_image$hpfs": "hpfs", + "syz_mount_image$iso9660": "iso9660", + "syz_mount_image$jffs2": "jffs2", + "syz_mount_image$jfs": "jfs", + "syz_mount_image$minix": "minix", + "syz_mount_image$msdos": "fat", + "syz_mount_image$nilfs2": "nilfs2", + "syz_mount_image$ntfs": "ntfs", + "syz_mount_image$ntfs3": "ntfs3", + "syz_mount_image$ocfs2": "ocfs2", + "syz_mount_image$omfs": "omfs", + "syz_mount_image$qnx4": "qnx4", + "syz_mount_image$qnx6": "qnx6", + "syz_mount_image$reiserfs": "reiserfs", + "syz_mount_image$romfs": "romfs", + "syz_mount_image$squashfs": "squashfs", + "syz_mount_image$sysv": "sysv", + "syz_mount_image$tmpfs": "tmpfs", + "syz_mount_image$ubifs": "ubifs", + "syz_mount_image$udf": "udf", + "syz_mount_image$ufs": "ufs", + "syz_mount_image$v7": "v7", + "syz_mount_image$vfat": "vfat", + "syz_mount_image$vxfs": "vxfs", + "syz_mount_image$xfs": "xfs", + "syz_mount_image$zonefs": "zonefs", +} + var ( vfsPathRegexp = regexp.MustCompile(`^fs/[^/]+\.c`) ) diff --git a/pkg/subsystem/extract_test.go b/pkg/subsystem/extract_test.go index 29512f460..862d1a6e5 100644 --- a/pkg/subsystem/extract_test.go +++ b/pkg/subsystem/extract_test.go @@ -4,6 +4,7 @@ package subsystem import ( + "reflect" "sort" "testing" @@ -67,3 +68,43 @@ io_uring_enter(r0, 0x2ff, 0x0, 0x0, 0x0, 0x0)`, assert.Exactlyf(t, ret, []string{"io_uring", "tty", "tty_ioctls"}, "invalid resulting subsystems: %s", ret) } + +func TestFsSubsystemExtraction(t *testing.T) { + extractor := MakeLinuxSubsystemExtractor() + + tests := []struct { + guilty string + prog string + subsystems []string + }{ + { + guilty: "fs/nilfs2/dat.c", + // nolint: lll + prog: `syz_mount_image$nilfs2(&(0x7f0000000000), &(0x7f0000000100)='./file0\x00', 0x100000, 0x3b, &(0x7f0000000200)=[{&(0x7f0000011240)="02", 0x1}, {&(0x7f0000012a40)="03000000", 0x4, 0x1}], 0x0, &(0x7f00000131c0), 0x1) +openat$incfs(0xffffffffffffff9c, &(0x7f0000000000)='.pending_reads\x00', 0x4040, 0x0)`, + subsystems: []string{"nilfs2"}, + }, + { + guilty: "fs/namei.c", + // nolint: lll + prog: `syz_mount_image$ntfs3(&(0x7f0000000240), &(0x7f000001f3c0)='./file0\x00', 0xc40, &(0x7f00000005c0)=ANY=[@ANYBLOB="0032"], 0x3, 0x1f398, &(0x7f000003e7c0)="111") +r0 = openat(0xffffffffffffff9c, &(0x7f0000000040)='.\x00', 0x0, 0x0) +mkdirat(r0, &(0x7f0000000180)='./bus\x00', 0x0) +mkdirat(r0, &(0x7f0000000280)='./bus/file0\x00', 0x0) +renameat2(r0, &(0x7f00000004c0)='./file0\x00', r0, &(0x7f0000000500)='./bus/file0/file0\x00', 0x0)`, + subsystems: []string{"ntfs3", "vfs"}, + }, + } + + for i, test := range tests { + ret := extractor.Extract(&Crash{ + OS: targets.Linux, + GuiltyFiles: []string{test.guilty}, + SyzRepro: test.prog, + }) + sort.Strings(ret) + if !reflect.DeepEqual(ret, test.subsystems) { + t.Fatalf("test #%d: got %+v, wanted %+v", i, ret, test.subsystems) + } + } +} -- cgit mrf-deployment