diff options
Diffstat (limited to 'pkg/subsystem')
| -rw-r--r-- | pkg/subsystem/linux/rules.go | 43 | ||||
| -rw-r--r-- | pkg/subsystem/linux/subsystems.go | 10 | ||||
| -rw-r--r-- | pkg/subsystem/linux/subsystems_test.go | 30 |
3 files changed, 82 insertions, 1 deletions
diff --git a/pkg/subsystem/linux/rules.go b/pkg/subsystem/linux/rules.go index 2df641c5e..946191263 100644 --- a/pkg/subsystem/linux/rules.go +++ b/pkg/subsystem/linux/rules.go @@ -9,5 +9,46 @@ type customRules struct { } var ( - linuxSubsystemRules = &customRules{} + linuxSubsystemRules = &customRules{ + subsystemCalls: map[string][]string{ + "adfs": {"syz_mount_image$adfs"}, + "affs": {"syz_mount_image$affs"}, + "befs": {"syz_mount_image$befs"}, + "bfs": {"syz_mount_image$bfs"}, + "btrfs": {"syz_mount_image$btrfs"}, + "cramfs": {"syz_mount_image$cramfs"}, + "efs": {"syz_mount_image$efs"}, + "erofs": {"syz_mount_image$erofs"}, + "exfat": {"syz_mount_image$exfat"}, + "ext4": {"syz_mount_image$ext4"}, + "f2fs": {"syz_mount_image$f2fs"}, + "fat": {"syz_mount_image$msdos", "syz_mount_image$vfat"}, + "gfs2": {"syz_mount_image$gfs2", "syz_mount_image$gfs2meta"}, + "hfs": {"syz_mount_image$hfs"}, + "hfsplus": {"syz_mount_image$hfsplus"}, + "hpfs": {"syz_mount_image$hpfs"}, + "iso9660": {"syz_mount_image$iso9660"}, + "jffs2": {"syz_mount_image$jffs2"}, + "jfs": {"syz_mount_image$jfs"}, + "minix": {"syz_mount_image$minix"}, + "nilfs2": {"syz_mount_image$nilfs2"}, + "ntfs": {"syz_mount_image$ntfs"}, + "ntfs3": {"syz_mount_image$ntfs3"}, + "ocfs2": {"syz_mount_image$ocfs2"}, + "omfs": {"syz_mount_image$omfs"}, + "qnx4": {"syz_mount_image$qnx4"}, + "qnx6": {"syz_mount_image$qnx6"}, + "reiserfs": {"syz_mount_image$reiserfs"}, + "romfs": {"syz_mount_image$romfs"}, + "squashfs": {"syz_mount_image$squashfs"}, + "sysv": {"syz_mount_image$sysv"}, + "tmpfs": {"syz_mount_image$tmpfs"}, + "ubifs": {"syz_mount_image$ubifs"}, + "udf": {"syz_mount_image$udf"}, + "ufs": {"syz_mount_image$ufs"}, + "vxfs": {"syz_mount_image$vxfs"}, + "xfs": {"syz_mount_image$xfs"}, + "zonefs": {"syz_mount_image$zonefs"}, + }, + } ) diff --git a/pkg/subsystem/linux/subsystems.go b/pkg/subsystem/linux/subsystems.go index 468ba5fbc..9d9688758 100644 --- a/pkg/subsystem/linux/subsystems.go +++ b/pkg/subsystem/linux/subsystems.go @@ -85,9 +85,19 @@ func (ctx *linuxCtx) getSubsystems() ([]*entity.Subsystem, error) { if err := setSubsystemNames(ret); err != nil { return nil, fmt.Errorf("failed to set names: %w", err) } + ctx.applyExtraRules(ret) return ret, nil } +func (ctx *linuxCtx) applyExtraRules(list []*entity.Subsystem) { + if ctx.extraRules == nil { + return + } + for _, entry := range list { + entry.Syscalls = ctx.extraRules.subsystemCalls[entry.Name] + } +} + func mergeRawRecords(subsystem *entity.Subsystem, records []*maintainersRecord) { unique := func(list []string) []string { m := make(map[string]struct{}) diff --git a/pkg/subsystem/linux/subsystems_test.go b/pkg/subsystem/linux/subsystems_test.go index caf675244..4a1ff9f0d 100644 --- a/pkg/subsystem/linux/subsystems_test.go +++ b/pkg/subsystem/linux/subsystems_test.go @@ -47,6 +47,29 @@ func TestGroupLinuxSubsystems(t *testing.T) { assert.ElementsMatch(t, subsystems, expected) } +func TestCustomCallRules(t *testing.T) { + subsystems, err := listFromRepoInner( + prepareTestLinuxRepo(t, []byte(testMaintainers)), + testRules, + ) + if err != nil { + t.Fatal(err) + } + expectCalls := map[string][]string{ + "ext4": []string{"syz_mount_image$ext4"}, + } + gotCalls := map[string][]string{} + for _, s := range subsystems { + if len(s.Syscalls) > 0 { + gotCalls[s.Name] = s.Syscalls + } + } + assert.Equal(t, len(expectCalls), len(gotCalls)) + for name, expect := range expectCalls { + assert.ElementsMatchf(t, expect, gotCalls[name], "syscalls of %s", name) + } +} + func prepareTestLinuxRepo(t *testing.T, maintainers []byte) fs.FS { return fstest.MapFS{ `fs/ext4/fsync.c`: {}, @@ -64,6 +87,13 @@ func prepareTestLinuxRepo(t *testing.T, maintainers []byte) fs.FS { } var ( + testRules = &customRules{ + subsystemCalls: map[string][]string{ + "ext4": []string{"syz_mount_image$ext4"}, + "vxfs": []string{"syz_mount_image$vxfs"}, + "tmpfs": []string{"syz_mount_image$tmpfs"}, + }, + } testMaintainers = ` Maintainers List ---------------- |
