diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2022-12-16 00:01:51 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2022-12-16 10:22:43 +0100 |
| commit | fcac021fe5ed726e926d2e585e7a2f59d8827f21 (patch) | |
| tree | 6d0c71e92b2494c53014124ca0197c760889453d | |
| parent | bd797b29e63755f6d6fceb2b8ef5430e7def9551 (diff) | |
pkg/subsystem: extract filesystems from guilty path
As we can easily do the subsystem <-> path mapping, let's also use it
for determining the actual involved filesystem.
| -rw-r--r-- | dashboard/app/app_test.go | 2 | ||||
| -rw-r--r-- | dashboard/app/config_linux_test.go | 11 | ||||
| -rw-r--r-- | pkg/subsystem/extract.go | 16 | ||||
| -rw-r--r-- | pkg/subsystem/extract_test.go | 49 |
4 files changed, 50 insertions, 28 deletions
diff --git a/dashboard/app/app_test.go b/dashboard/app/app_test.go index 3fa2e8499..400f16050 100644 --- a/dashboard/app/app_test.go +++ b/dashboard/app/app_test.go @@ -357,7 +357,7 @@ var testConfig = &GlobalConfig{ }, }, }, - Subsystems: &SubsystemsConfig{ + Subsystems: SubsystemsConfig{ SubsystemCc: subsystem.LinuxGetMaintainers, }, }, diff --git a/dashboard/app/config_linux_test.go b/dashboard/app/config_linux_test.go index 595f4b47a..1d4e82ac2 100644 --- a/dashboard/app/config_linux_test.go +++ b/dashboard/app/config_linux_test.go @@ -46,8 +46,15 @@ func TestFsSubsystemFlow(t *testing.T) { client.ReportCrash(crash) reply = c.pollEmailBug() - // We have no means to determine the subsystem now, so it shouldn't be anywhere. - c.expectEQ(reply.Subject, "[syzbot] WARNING in nilfs_dat_commit_end") + // The subsystem should have been taken from the guilty path. + c.expectEQ(reply.Subject, "[syzbot] [nilfs2?] WARNING in nilfs_dat_commit_end") + c.expectEQ(reply.To, []string{ + "konishi.ryusuke@gmail.com", + "linux-kernel@vger.kernel.org", + "linux-nilfs@vger.kernel.org", + "maintainer@kernel.org", + "test@syzkaller.com", + }) // C. Send a possibly vfs bug without a reproducer. // ----------------------------------------- diff --git a/pkg/subsystem/extract.go b/pkg/subsystem/extract.go index 4d952011f..1908f5e54 100644 --- a/pkg/subsystem/extract.go +++ b/pkg/subsystem/extract.go @@ -5,6 +5,7 @@ package subsystem import ( "regexp" + "sync" "github.com/google/syzkaller/prog" ) @@ -58,9 +59,24 @@ func linuxPathToSubsystems(path string) []string { if vfsPathRegexp.MatchString(path) { ret = append(ret, "vfs") } + linuxSubsystemsOnce.Do(func() { + for name, info := range linuxSubsystems { + linuxSubsystemRegexps[name] = regexp.MustCompile("^/?" + info.path + ".*") + } + }) + for name, pattern := range linuxSubsystemRegexps { + if pattern.MatchString(path) { + ret = append(ret, name) + } + } return ret } +var ( + linuxSubsystemsOnce sync.Once + linuxSubsystemRegexps = map[string]*regexp.Regexp{} +) + func linuxCallToSubsystems(call string) []string { name := linuxCallToSubsystemsMap[call] if name != "" { diff --git a/pkg/subsystem/extract_test.go b/pkg/subsystem/extract_test.go index 862d1a6e5..eb04ff6ce 100644 --- a/pkg/subsystem/extract_test.go +++ b/pkg/subsystem/extract_test.go @@ -4,7 +4,6 @@ package subsystem import ( - "reflect" "sort" "testing" @@ -12,27 +11,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestSimpleLinuxExtract(t *testing.T) { - se := MakeLinuxSubsystemExtractor() - - ret := se.Extract(&Crash{ - OS: targets.Linux, - GuiltyFiles: []string{ - "fs/ext4/abc.c", - }, - }) - assert.Empty(t, ret, "the test should have found 0 subsystems") - - ret = se.Extract(&Crash{ - OS: targets.Linux, - GuiltyFiles: []string{ - "fs/ext4/abc.c", - "fs/def.c", - }, - }) - assert.Exactly(t, ret, []string{"vfs"}, "the test should have only found vfs") -} - func TestProgCallRules(t *testing.T) { se := &SubsystemExtractor{ pathToSubsystems: linuxPathToSubsystems, @@ -78,6 +56,10 @@ func TestFsSubsystemExtraction(t *testing.T) { subsystems []string }{ { + guilty: "fs/abc.c", + subsystems: []string{"vfs"}, + }, + { 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) @@ -94,6 +76,24 @@ mkdirat(r0, &(0x7f0000000280)='./bus/file0\x00', 0x0) renameat2(r0, &(0x7f00000004c0)='./file0\x00', r0, &(0x7f0000000500)='./bus/file0/file0\x00', 0x0)`, subsystems: []string{"ntfs3", "vfs"}, }, + { + guilty: "fs/ext4/file.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", "ext4"}, + }, + { + guilty: "fs/gfs2/ops_fstype.c", + subsystems: []string{"gfs2"}, + }, + { + guilty: "net/mac80211/main.c", + subsystems: []string{}, + }, } for i, test := range tests { @@ -103,8 +103,7 @@ renameat2(r0, &(0x7f00000004c0)='./file0\x00', r0, &(0x7f0000000500)='./bus/file SyzRepro: test.prog, }) sort.Strings(ret) - if !reflect.DeepEqual(ret, test.subsystems) { - t.Fatalf("test #%d: got %+v, wanted %+v", i, ret, test.subsystems) - } + sort.Strings(test.subsystems) + assert.Exactlyf(t, ret, test.subsystems, "#%d: invalid resulting subsystems", i) } } |
