seccomp-tools 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,382 @@
1
+ {
2
+ exit: 1,
3
+ fork: 2,
4
+ read: 3,
5
+ write: 4,
6
+ open: 5,
7
+ close: 6,
8
+ waitpid: 7,
9
+ creat: 8,
10
+ link: 9,
11
+ unlink: 10,
12
+ execve: 11,
13
+ chdir: 12,
14
+ time: 13,
15
+ mknod: 14,
16
+ chmod: 15,
17
+ lchown: 16,
18
+ break: 17,
19
+ oldstat: 18,
20
+ lseek: 19,
21
+ getpid: 20,
22
+ mount: 21,
23
+ umount: 22,
24
+ setuid: 23,
25
+ getuid: 24,
26
+ stime: 25,
27
+ ptrace: 26,
28
+ alarm: 27,
29
+ oldfstat: 28,
30
+ pause: 29,
31
+ utime: 30,
32
+ stty: 31,
33
+ gtty: 32,
34
+ access: 33,
35
+ nice: 34,
36
+ ftime: 35,
37
+ sync: 36,
38
+ kill: 37,
39
+ rename: 38,
40
+ mkdir: 39,
41
+ rmdir: 40,
42
+ dup: 41,
43
+ pipe: 42,
44
+ times: 43,
45
+ prof: 44,
46
+ brk: 45,
47
+ setgid: 46,
48
+ getgid: 47,
49
+ signal: 48,
50
+ geteuid: 49,
51
+ getegid: 50,
52
+ acct: 51,
53
+ umount2: 52,
54
+ lock: 53,
55
+ ioctl: 54,
56
+ fcntl: 55,
57
+ mpx: 56,
58
+ setpgid: 57,
59
+ ulimit: 58,
60
+ oldolduname: 59,
61
+ umask: 60,
62
+ chroot: 61,
63
+ ustat: 62,
64
+ dup2: 63,
65
+ getppid: 64,
66
+ getpgrp: 65,
67
+ setsid: 66,
68
+ sigaction: 67,
69
+ sgetmask: 68,
70
+ ssetmask: 69,
71
+ setreuid: 70,
72
+ setregid: 71,
73
+ sigsuspend: 72,
74
+ sigpending: 73,
75
+ sethostname: 74,
76
+ setrlimit: 75,
77
+ getrlimit: 76,
78
+ getrusage: 77,
79
+ gettimeofday: 78,
80
+ settimeofday: 79,
81
+ getgroups: 80,
82
+ setgroups: 81,
83
+ select: 82,
84
+ symlink: 83,
85
+ oldlstat: 84,
86
+ readlink: 85,
87
+ uselib: 86,
88
+ swapon: 87,
89
+ reboot: 88,
90
+ readdir: 89,
91
+ mmap: 90,
92
+ munmap: 91,
93
+ truncate: 92,
94
+ ftruncate: 93,
95
+ fchmod: 94,
96
+ fchown: 95,
97
+ getpriority: 96,
98
+ setpriority: 97,
99
+ profil: 98,
100
+ statfs: 99,
101
+ fstatfs: 100,
102
+ ioperm: 101,
103
+ socketcall: 102,
104
+ syslog: 103,
105
+ setitimer: 104,
106
+ getitimer: 105,
107
+ stat: 106,
108
+ lstat: 107,
109
+ fstat: 108,
110
+ olduname: 109,
111
+ iopl: 110,
112
+ vhangup: 111,
113
+ idle: 112,
114
+ vm86old: 113,
115
+ wait4: 114,
116
+ swapoff: 115,
117
+ sysinfo: 116,
118
+ ipc: 117,
119
+ fsync: 118,
120
+ sigreturn: 119,
121
+ clone: 120,
122
+ setdomainname: 121,
123
+ uname: 122,
124
+ modify_ldt: 123,
125
+ adjtimex: 124,
126
+ mprotect: 125,
127
+ sigprocmask: 126,
128
+ create_module: 127,
129
+ init_module: 128,
130
+ delete_module: 129,
131
+ get_kernel_syms: 130,
132
+ quotactl: 131,
133
+ getpgid: 132,
134
+ fchdir: 133,
135
+ bdflush: 134,
136
+ sysfs: 135,
137
+ personality: 136,
138
+ afs_syscall: 137,
139
+ setfsuid: 138,
140
+ setfsgid: 139,
141
+ _llseek: 140,
142
+ getdents: 141,
143
+ _newselect: 142,
144
+ flock: 143,
145
+ msync: 144,
146
+ readv: 145,
147
+ writev: 146,
148
+ getsid: 147,
149
+ fdatasync: 148,
150
+ _sysctl: 149,
151
+ mlock: 150,
152
+ munlock: 151,
153
+ mlockall: 152,
154
+ munlockall: 153,
155
+ sched_setparam: 154,
156
+ sched_getparam: 155,
157
+ sched_setscheduler: 156,
158
+ sched_getscheduler: 157,
159
+ sched_yield: 158,
160
+ sched_get_priority_max: 159,
161
+ sched_get_priority_min: 160,
162
+ sched_rr_get_interval: 161,
163
+ nanosleep: 162,
164
+ mremap: 163,
165
+ setresuid: 164,
166
+ getresuid: 165,
167
+ vm86: 166,
168
+ query_module: 167,
169
+ poll: 168,
170
+ nfsservctl: 169,
171
+ setresgid: 170,
172
+ getresgid: 171,
173
+ prctl: 172,
174
+ rt_sigreturn: 173,
175
+ rt_sigaction: 174,
176
+ rt_sigprocmask: 175,
177
+ rt_sigpending: 176,
178
+ rt_sigtimedwait: 177,
179
+ rt_sigqueueinfo: 178,
180
+ rt_sigsuspend: 179,
181
+ pread: 180,
182
+ pwrite: 181,
183
+ chown: 182,
184
+ getcwd: 183,
185
+ capget: 184,
186
+ capset: 185,
187
+ sigaltstack: 186,
188
+ sendfile: 187,
189
+ getpmsg: 188,
190
+ putpmsg: 189,
191
+ vfork: 190,
192
+ ugetrlimit: 191,
193
+ mmap2: 192,
194
+ truncate64: 193,
195
+ ftruncate64: 194,
196
+ stat64: 195,
197
+ lstat64: 196,
198
+ fstat64: 197,
199
+ lchown32: 198,
200
+ getuid32: 199,
201
+ getgid32: 200,
202
+ geteuid32: 201,
203
+ getegid32: 202,
204
+ setreuid32: 203,
205
+ setregid32: 204,
206
+ getgroups32: 205,
207
+ setgroups32: 206,
208
+ fchown32: 207,
209
+ setresuid32: 208,
210
+ getresuid32: 209,
211
+ setresgid32: 210,
212
+ getresgid32: 211,
213
+ chown32: 212,
214
+ setuid32: 213,
215
+ setgid32: 214,
216
+ setfsuid32: 215,
217
+ setfsgid32: 216,
218
+ pivot_root: 217,
219
+ mincore: 218,
220
+ madvise: 219,
221
+ madvise1: 219,
222
+ getdents64: 220,
223
+ fcntl64: 221,
224
+ gettid: 224,
225
+ readahead: 225,
226
+ setxattr: 226,
227
+ lsetxattr: 227,
228
+ fsetxattr: 228,
229
+ getxattr: 229,
230
+ lgetxattr: 230,
231
+ fgetxattr: 231,
232
+ listxattr: 232,
233
+ llistxattr: 233,
234
+ flistxattr: 234,
235
+ removexattr: 235,
236
+ lremovexattr: 236,
237
+ fremovexattr: 237,
238
+ tkill: 238,
239
+ sendfile64: 239,
240
+ futex: 240,
241
+ sched_setaffinity: 241,
242
+ sched_getaffinity: 242,
243
+ set_thread_area: 243,
244
+ get_thread_area: 244,
245
+ io_setup: 245,
246
+ io_destroy: 246,
247
+ io_getevents: 247,
248
+ io_submit: 248,
249
+ io_cancel: 249,
250
+ fadvise64: 250,
251
+ exit_group: 252,
252
+ lookup_dcookie: 253,
253
+ epoll_create: 254,
254
+ epoll_ctl: 255,
255
+ epoll_wait: 256,
256
+ remap_file_pages: 257,
257
+ set_tid_address: 258,
258
+ timer_create: 259,
259
+ timer_settime: (259 + 1),
260
+ timer_gettime: (259 + 2),
261
+ timer_getoverrun: (259 + 3),
262
+ timer_delete: (259 + 4),
263
+ clock_settime: (259 + 5),
264
+ clock_gettime: (259 + 6),
265
+ clock_getres: (259 + 7),
266
+ clock_nanosleep: (259 + 8),
267
+ statfs64: 268,
268
+ fstatfs64: 269,
269
+ tgkill: 270,
270
+ utimes: 271,
271
+ fadvise64_64: 272,
272
+ vserver: 273,
273
+ mbind: 274,
274
+ get_mempolicy: 275,
275
+ set_mempolicy: 276,
276
+ mq_open: 277,
277
+ mq_unlink: (277 + 1),
278
+ mq_timedsend: (277 + 2),
279
+ mq_timedreceive: (277 + 3),
280
+ mq_notify: (277 + 4),
281
+ mq_getsetattr: (277 + 5),
282
+ sys_kexec_load: 283,
283
+ waitid: 284,
284
+ add_key: 286,
285
+ request_key: 287,
286
+ keyctl: 288,
287
+ ioprio_set: 289,
288
+ ioprio_get: 290,
289
+ inotify_init: 291,
290
+ inotify_add_watch: 292,
291
+ inotify_rm_watch: 293,
292
+ migrate_pages: 294,
293
+ openat: 295,
294
+ mkdirat: 296,
295
+ mknodat: 297,
296
+ fchownat: 298,
297
+ futimesat: 299,
298
+ fstatat64: 300,
299
+ unlinkat: 301,
300
+ renameat: 302,
301
+ linkat: 303,
302
+ symlinkat: 304,
303
+ readlinkat: 305,
304
+ fchmodat: 306,
305
+ faccessat: 307,
306
+ pselect6: 308,
307
+ ppoll: 309,
308
+ unshare: 310,
309
+ set_robust_list: 311,
310
+ get_robust_list: 312,
311
+ splice: 313,
312
+ sync_file_range: 314,
313
+ tee: 315,
314
+ vmsplice: 316,
315
+ move_pages: 317,
316
+ getcpu: 318,
317
+ epoll_pwait: 319,
318
+ utimensat: 320,
319
+ signalfd: 321,
320
+ timerfd: 322,
321
+ eventfd: 323,
322
+ fallocate: 324,
323
+ timerfd_settime: 325,
324
+ timerfd_gettime: 326,
325
+ signalfd4: 327,
326
+ eventfd2: 328,
327
+ epoll_create1: 329,
328
+ dup3: 330,
329
+ pipe2: 331,
330
+ inotify_init1: 332,
331
+ preadv: 333,
332
+ pwritev: 334,
333
+ rt_tgsigqueueinfo: 335,
334
+ perf_event_open: 336,
335
+ recvmmsg: 337,
336
+ fanotify_init: 338,
337
+ fanotify_mark: 339,
338
+ prlimit64: 340,
339
+ name_to_handle_at: 341,
340
+ open_by_handle_at: 342,
341
+ clock_adjtime: 343,
342
+ syncfs: 344,
343
+ sendmmsg: 345,
344
+ setns: 346,
345
+ process_vm_readv: 347,
346
+ process_vm_writev: 348,
347
+ kcmp: 349,
348
+ finit_module: 350,
349
+ sched_setattr: 351,
350
+ sched_getattr: 352,
351
+ renameat2: 353,
352
+ seccomp: 354,
353
+ getrandom: 355,
354
+ memfd_create: 356,
355
+ bpf: 357,
356
+ execveat: 358,
357
+ socket: 359,
358
+ socketpair: 360,
359
+ bind: 361,
360
+ connect: 362,
361
+ listen: 363,
362
+ accept4: 364,
363
+ getsockopt: 365,
364
+ setsockopt: 366,
365
+ getsockname: 367,
366
+ getpeername: 368,
367
+ sendto: 369,
368
+ sendmsg: 370,
369
+ recvfrom: 371,
370
+ recvmsg: 372,
371
+ shutdown: 373,
372
+ userfaultfd: 374,
373
+ membarrier: 375,
374
+ mlock2: 376,
375
+ copy_file_range: 377,
376
+ preadv2: 378,
377
+ pwritev2: 379,
378
+ pkey_mprotect: 380,
379
+ pkey_alloc: 381,
380
+ pkey_free: 382,
381
+ statx: 383
382
+ }
@@ -0,0 +1,31 @@
1
+ module SeccompTools
2
+ # The context when emulating.
3
+ #
4
+ # @todo
5
+ # No lambda value, not support ALU instructions.
6
+ class Context
7
+ attr_accessor :a, :x, :mem
8
+ def initialize(a: nil, x: nil, mem: {})
9
+ @a = a
10
+ @x = x
11
+ @mem = mem
12
+ end
13
+
14
+ # Implement a deep dup.
15
+ # @return [Context]
16
+ def dup
17
+ Context.new(a: a, x: x, mem: mem.dup)
18
+ end
19
+
20
+ # For conveniently get instance variable.
21
+ # @param [String, Symbol] key
22
+ def [](key)
23
+ instance_variable_get(('@' + key.downcase).to_sym)
24
+ end
25
+
26
+ # For conveniently set instance variable.
27
+ def []=(key, val)
28
+ instance_variable_set(('@' + key.downcase).to_sym, val)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,37 @@
1
+ require 'seccomp-tools/bpf'
2
+ require 'seccomp-tools/context'
3
+ require 'seccomp-tools/util'
4
+
5
+ module SeccompTools
6
+ # Disassembler of seccomp bpf.
7
+ module Disasm
8
+ module_function
9
+
10
+ # Disassemble bpf codes.
11
+ # @param [String] bpf
12
+ # The bpf codes.
13
+ # @param [Symbol] arch
14
+ # Architecture.
15
+ # @todo
16
+ # Detect system architecture as default.
17
+ def disasm(bpf, arch: nil)
18
+ arch ||= Util.system_arch
19
+ codes = bpf.scan(/.{8}/m).map.with_index { |b, i| BPF.new(b, arch, i) }
20
+ contexts = Array.new(codes.size) { [] }
21
+ contexts[0].push(Context.new)
22
+ dis = codes.zip(contexts).map do |code, ctxs|
23
+ ctxs.each do |ctx|
24
+ code.branch(ctx) do |pc, c|
25
+ contexts[pc].push(c) unless c.nil? || pc >= contexts.size
26
+ end
27
+ end
28
+ code.contexts = ctxs
29
+ code.disasm
30
+ end.join("\n")
31
+ <<EOS + dis + "\n"
32
+ line CODE JT JF K
33
+ =================================
34
+ EOS
35
+ end
36
+ end
37
+ end