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. --- pkg/subsystem/extract_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'pkg/subsystem/extract_test.go') 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