github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/sys/linux/init_test.go (about) 1 // Copyright 2018 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 linux_test 5 6 import ( 7 "testing" 8 9 "github.com/google/syzkaller/prog" 10 _ "github.com/google/syzkaller/sys/linux/gen" 11 "github.com/google/syzkaller/sys/targets" 12 ) 13 14 func TestNeutralize(t *testing.T) { 15 prog.TestDeserializeHelper(t, targets.Linux, targets.AMD64, nil, []prog.DeserializeTest{ 16 { 17 In: `syslog(0x10000000006, 0x0, 0x0)`, 18 Out: `syslog(0x9, 0x0, 0x0)`, 19 }, 20 { 21 In: `syslog(0x10000000007, 0x0, 0x0)`, 22 Out: `syslog(0x9, 0x0, 0x0)`, 23 }, 24 { 25 In: `syslog(0x1, 0x0, 0x0)`, 26 }, 27 28 { 29 In: `ptrace(0xf000000000, 0x0)`, 30 Out: `ptrace(0xffffffffffffffff, 0x0)`, 31 }, 32 { 33 In: `ptrace$peek(0x0, 0x0, &(0x7f0000000000))`, 34 Out: `ptrace$peek(0xffffffffffffffff, 0x0, &(0x7f0000000000))`, 35 }, 36 { 37 In: `ptrace(0x1, 0x0)`, 38 }, 39 { 40 In: `arch_prctl$ARCH_SET_GS(0xf00000001002, 0x0)`, 41 Out: `arch_prctl$ARCH_SET_GS(0x1001, 0x0)`, 42 }, 43 { 44 In: `arch_prctl$ARCH_SET_GS(0x1003, 0x0)`, 45 }, 46 { 47 In: `ioctl(0x0, 0x200000c0045877, 0x0)`, 48 Out: `ioctl(0x0, 0xc0045878, 0x0)`, 49 }, 50 { 51 In: `ioctl$int_in(0x0, 0x2000008004587d, 0x0)`, 52 Out: `ioctl$int_in(0x0, 0x6609, 0x0)`, 53 }, 54 { 55 In: `fanotify_mark(0x1, 0x2, 0x407fe029, 0x3, 0x0)`, 56 Out: `fanotify_mark(0x1, 0x2, 0x4078e029, 0x3, 0x0)`, 57 }, 58 { 59 In: `fanotify_mark(0xffffffffffffffff, 0xffffffffffffffff, 0xfffffffffff8ffff, 0xffffffffffffffff, 0x0)`, 60 }, 61 { 62 In: `syz_init_net_socket$bt_hci(0x1, 0x0, 0x0)`, 63 Out: `syz_init_net_socket$bt_hci(0xffffffffffffffff, 0x0, 0x0)`, 64 }, 65 { 66 In: `syz_init_net_socket$bt_hci(0x27, 0x0, 0x0)`, 67 }, 68 { 69 In: `syz_init_net_socket$bt_hci(0x1a, 0x0, 0x0)`, 70 }, 71 { 72 In: `syz_init_net_socket$bt_hci(0x1f, 0x0, 0x0)`, 73 }, 74 { 75 In: `mmap(0x0, 0x0, 0x0, 0x0, 0x0, 0x0)`, 76 Out: `mmap(0x0, 0x0, 0x0, 0x10, 0x0, 0x0)`, 77 }, 78 { 79 In: `mremap(0x0, 0x0, 0x0, 0xcc, 0x0)`, 80 }, 81 { 82 In: `mremap(0x0, 0x0, 0x0, 0xcd, 0x0)`, 83 Out: `mremap(0x0, 0x0, 0x0, 0xcf, 0x0)`, 84 }, 85 { 86 In: ` 87 mknod(0x0, 0x1000, 0x0) 88 mknod(0x0, 0x8000, 0x0) 89 mknod(0x0, 0xc000, 0x0) 90 mknod(0x0, 0x2000, 0x0) 91 mknod(0x0, 0x6000, 0x0) 92 mknod(0x0, 0x6000, 0x700) 93 `, 94 Out: ` 95 mknod(0x0, 0x1000, 0x0) 96 mknod(0x0, 0x8000, 0x0) 97 mknod(0x0, 0xc000, 0x0) 98 mknod(0x0, 0x8000, 0x0) 99 mknod(0x0, 0x8000, 0x0) 100 mknod(0x0, 0x6000, 0x700) 101 `, 102 }, 103 { 104 In: ` 105 exit(0x3) 106 exit(0x43) 107 exit(0xc3) 108 exit(0xc3) 109 exit_group(0x5a) 110 exit_group(0x43) 111 exit_group(0x443) 112 `, 113 Out: ` 114 exit(0x3) 115 exit(0x1) 116 exit(0x1) 117 exit(0x1) 118 exit_group(0x5a) 119 exit_group(0x1) 120 exit_group(0x1) 121 `, 122 }, 123 { 124 In: ` 125 syz_open_dev$tty1(0xc, 0x4, 0x4) 126 syz_open_dev$tty1(0xb, 0x2, 0x4) 127 syz_open_dev$tty1(0xc, 0x4, 0x5) 128 `, 129 Out: ` 130 syz_open_dev$tty1(0xc, 0x4, 0x4) 131 syz_open_dev$tty1(0xc, 0x4, 0x4) 132 syz_open_dev$tty1(0xc, 0x4, 0x1) 133 `, 134 }, 135 { 136 In: `sched_setattr(0x0, &(0x7f00000002c0)={0x0, 0x1, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0}, 0x0)`, 137 Out: `sched_setattr(0x0, &(0x7f00000002c0)={0x0, 0x0, 0x0, 0x0, 0x3}, 0x0)`, 138 }, 139 { 140 In: `sched_setattr(0x0, &(0x7f00000002c0)={0x0, 0x2, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0}, 0x0)`, 141 Out: `sched_setattr(0x0, &(0x7f00000002c0)={0x0, 0x0, 0x0, 0x0, 0x3}, 0x0)`, 142 }, 143 { 144 In: `sched_setattr(0x0, &(0x7f00000002c0)={0x0, 0x3, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0}, 0x0)`, 145 Out: `sched_setattr(0x0, &(0x7f00000002c0)={0x0, 0x3, 0x0, 0x0, 0x3}, 0x0)`, 146 }, 147 { 148 In: `sched_setattr(0x0, 0x123456, 0x0)`, 149 Out: `sched_setattr(0x0, 0x0, 0x0)`, 150 }, 151 { 152 In: `sched_setattr(0x0, &(0x7f00000001c0)=ANY=[@ANYBLOB="1234567812345678"], 0x0)`, 153 Out: `sched_setattr(0x0, &(0x7f00000001c0)={0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 0x0)`, 154 StrictErr: `wrong array arg`, 155 }, 156 }) 157 } 158 159 func TestDeserializeStrictUnsafe(t *testing.T) { 160 t.Parallel() 161 target, _ := prog.GetTarget("linux", "amd64") 162 // Raw mode must preserve the global file name, allow to use mmap with non-fixed addr, 163 // and allow to use disabled syscalls. 164 had := `openat(0x0, &(0x7f0000000000)='/dev/foo', 0x0, 0x0) 165 mmap(0x0, 0x0, 0x0, 0x0, 0x0, 0x0) 166 clone(0x0, &(0x7f0000000000), &(0x7f0000000010), &(0x7f0000000020), &(0x7f0000000030)) 167 ` 168 p, err := target.Deserialize([]byte(had), prog.StrictUnsafe) 169 if err != nil { 170 t.Fatal(err) 171 } 172 got := string(p.Serialize()) 173 if had != got { 174 t.Fatalf("program was changed:\n%s\ngot:\n%s", had, got) 175 } 176 } 177 178 func TestDeserializeNonStrictUnsafe(t *testing.T) { 179 t.Parallel() 180 target, _ := prog.GetTarget("linux", "amd64") 181 _, err := target.Deserialize([]byte("clone()"), prog.NonStrictUnsafe) 182 if err != nil { 183 t.Fatal(err) 184 } 185 }