github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/subsystem/raw_extractor_test.go (about) 1 // Copyright 2023 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package subsystem 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestSubsystemExtractor(t *testing.T) { 13 ioUring := &Subsystem{ 14 Name: "io_uring", 15 PathRules: []PathRule{ 16 { 17 IncludeRegexp: `io_uring/.*`, 18 }, 19 }, 20 Syscalls: []string{"syz_io_uring_setup"}, 21 } 22 security := &Subsystem{ 23 Name: "security", 24 PathRules: []PathRule{ 25 { 26 IncludeRegexp: `security/.*`, 27 ExcludeRegexp: `security/selinux/.*`, 28 }, 29 { 30 IncludeRegexp: `net/ipv6/calipso\.c`, 31 }, 32 }, 33 } 34 net := &Subsystem{ 35 Name: "net", 36 PathRules: []PathRule{ 37 { 38 IncludeRegexp: `net/.*`, 39 }, 40 }, 41 } 42 obj := makeRawExtractor([]*Subsystem{ioUring, security, net}) 43 44 // Verify path matching. 45 assert.ElementsMatch(t, obj.FromPath(`io_uring/file.c`), []*Subsystem{ioUring}) 46 assert.ElementsMatch(t, obj.FromPath(`security/file.c`), []*Subsystem{security}) 47 assert.ElementsMatch(t, obj.FromPath(`security/selinux/file.c`), []*Subsystem{}) 48 assert.ElementsMatch(t, obj.FromPath(`net/ipv6/calipso.c`), []*Subsystem{net, security}) 49 50 // Verify prog matching. 51 // nolint: lll 52 assert.ElementsMatch(t, obj.FromProg([]byte( 53 `# https://syzkaller.appspot.com/bug?id=708185e841adf6ca28fc50b126fdf9825fd8ae43 54 # See https://goo.gl/kgGztJ for information about syzkaller reproducers. 55 #{"repeat":true,"procs":1,"slowdown":1,"sandbox":"","close_fds":false} 56 r0 = syz_io_uring_setup(0x3ee4, &(0x7f0000000240), &(0x7f0000002000/0x2000)=nil, &(0x7f0000ffd000/0x3000)=nil, &(0x7f0000000100)=<r1=>0x0, &(0x7f0000000140)=<r2=>0x0) 57 socket$inet_udplite(0x2, 0x2, 0x88) 58 r3 = openat$ptmx(0xffffffffffffff9c, &(0x7f0000000040), 0x8a04, 0x0) 59 syz_io_uring_submit(r1, r2, &(0x7f0000000000)=@IORING_OP_READ=@pass_buffer={0x16, 0x0, 0x0, @fd_index=0x5, 0x0, 0x0}, 0x0) 60 ioctl$TIOCSETD(r3, 0x5423, &(0x7f0000000580)=0x3) 61 io_uring_enter(r0, 0x2ff, 0x0, 0x0, 0x0, 0x0)`)), 62 []*Subsystem{ioUring}) 63 // nolint: lll 64 assert.ElementsMatch(t, obj.FromProg([]byte( 65 `syz_mount_image$nilfs2(&(0x7f0000000000), &(0x7f0000000100)='./file0\x00', 0x100000, 0x3b, &(0x7f0000000200)=[{&(0x7f0000011240)="02", 0x1}, {&(0x7f0000012a40)="03000000", 0x4, 0x1}], 0x0, &(0x7f00000131c0), 0x1) 66 openat$incfs(0xffffffffffffff9c, &(0x7f0000000000)='.pending_reads\x00', 0x4040, 0x0)`)), 67 []*Subsystem{}) 68 }