Browse code

Remove dependency in dockerd on libseccomp

This was just using libseccomp to get the right arch, but we can use
GOARCH to get this.
The nativeToSeccomp map needed to be adjusted a bit for mipsle vs mipsel
since that's go how refers to it. Also added some other arches to it.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Brian Goff authored on 2020/08/28 08:17:21
Showing 4 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,697 @@
0
+// +build seccomp
1
+
2
+package seccomp // import "github.com/docker/docker/profiles/seccomp"
3
+
4
+import (
5
+	"github.com/docker/docker/api/types"
6
+	"golang.org/x/sys/unix"
7
+)
8
+
9
+func arches() []types.Architecture {
10
+	return []types.Architecture{
11
+		{
12
+			Arch:      types.ArchX86_64,
13
+			SubArches: []types.Arch{types.ArchX86, types.ArchX32},
14
+		},
15
+		{
16
+			Arch:      types.ArchAARCH64,
17
+			SubArches: []types.Arch{types.ArchARM},
18
+		},
19
+		{
20
+			Arch:      types.ArchMIPS64,
21
+			SubArches: []types.Arch{types.ArchMIPS, types.ArchMIPS64N32},
22
+		},
23
+		{
24
+			Arch:      types.ArchMIPS64N32,
25
+			SubArches: []types.Arch{types.ArchMIPS, types.ArchMIPS64},
26
+		},
27
+		{
28
+			Arch:      types.ArchMIPSEL64,
29
+			SubArches: []types.Arch{types.ArchMIPSEL, types.ArchMIPSEL64N32},
30
+		},
31
+		{
32
+			Arch:      types.ArchMIPSEL64N32,
33
+			SubArches: []types.Arch{types.ArchMIPSEL, types.ArchMIPSEL64},
34
+		},
35
+		{
36
+			Arch:      types.ArchS390X,
37
+			SubArches: []types.Arch{types.ArchS390},
38
+		},
39
+	}
40
+}
41
+
42
+// DefaultProfile defines the allowed syscalls for the default seccomp profile.
43
+func DefaultProfile() *types.Seccomp {
44
+	syscalls := []*types.Syscall{
45
+		{
46
+			Names: []string{
47
+				"accept",
48
+				"accept4",
49
+				"access",
50
+				"adjtimex",
51
+				"alarm",
52
+				"bind",
53
+				"brk",
54
+				"capget",
55
+				"capset",
56
+				"chdir",
57
+				"chmod",
58
+				"chown",
59
+				"chown32",
60
+				"clock_adjtime",
61
+				"clock_adjtime64",
62
+				"clock_getres",
63
+				"clock_getres_time64",
64
+				"clock_gettime",
65
+				"clock_gettime64",
66
+				"clock_nanosleep",
67
+				"clock_nanosleep_time64",
68
+				"close",
69
+				"connect",
70
+				"copy_file_range",
71
+				"creat",
72
+				"dup",
73
+				"dup2",
74
+				"dup3",
75
+				"epoll_create",
76
+				"epoll_create1",
77
+				"epoll_ctl",
78
+				"epoll_ctl_old",
79
+				"epoll_pwait",
80
+				"epoll_wait",
81
+				"epoll_wait_old",
82
+				"eventfd",
83
+				"eventfd2",
84
+				"execve",
85
+				"execveat",
86
+				"exit",
87
+				"exit_group",
88
+				"faccessat",
89
+				"faccessat2",
90
+				"fadvise64",
91
+				"fadvise64_64",
92
+				"fallocate",
93
+				"fanotify_mark",
94
+				"fchdir",
95
+				"fchmod",
96
+				"fchmodat",
97
+				"fchown",
98
+				"fchown32",
99
+				"fchownat",
100
+				"fcntl",
101
+				"fcntl64",
102
+				"fdatasync",
103
+				"fgetxattr",
104
+				"flistxattr",
105
+				"flock",
106
+				"fork",
107
+				"fremovexattr",
108
+				"fsetxattr",
109
+				"fstat",
110
+				"fstat64",
111
+				"fstatat64",
112
+				"fstatfs",
113
+				"fstatfs64",
114
+				"fsync",
115
+				"ftruncate",
116
+				"ftruncate64",
117
+				"futex",
118
+				"futex_time64",
119
+				"futimesat",
120
+				"getcpu",
121
+				"getcwd",
122
+				"getdents",
123
+				"getdents64",
124
+				"getegid",
125
+				"getegid32",
126
+				"geteuid",
127
+				"geteuid32",
128
+				"getgid",
129
+				"getgid32",
130
+				"getgroups",
131
+				"getgroups32",
132
+				"getitimer",
133
+				"getpeername",
134
+				"getpgid",
135
+				"getpgrp",
136
+				"getpid",
137
+				"getppid",
138
+				"getpriority",
139
+				"getrandom",
140
+				"getresgid",
141
+				"getresgid32",
142
+				"getresuid",
143
+				"getresuid32",
144
+				"getrlimit",
145
+				"get_robust_list",
146
+				"getrusage",
147
+				"getsid",
148
+				"getsockname",
149
+				"getsockopt",
150
+				"get_thread_area",
151
+				"gettid",
152
+				"gettimeofday",
153
+				"getuid",
154
+				"getuid32",
155
+				"getxattr",
156
+				"inotify_add_watch",
157
+				"inotify_init",
158
+				"inotify_init1",
159
+				"inotify_rm_watch",
160
+				"io_cancel",
161
+				"ioctl",
162
+				"io_destroy",
163
+				"io_getevents",
164
+				"io_pgetevents",
165
+				"io_pgetevents_time64",
166
+				"ioprio_get",
167
+				"ioprio_set",
168
+				"io_setup",
169
+				"io_submit",
170
+				"io_uring_enter",
171
+				"io_uring_register",
172
+				"io_uring_setup",
173
+				"ipc",
174
+				"kill",
175
+				"lchown",
176
+				"lchown32",
177
+				"lgetxattr",
178
+				"link",
179
+				"linkat",
180
+				"listen",
181
+				"listxattr",
182
+				"llistxattr",
183
+				"_llseek",
184
+				"lremovexattr",
185
+				"lseek",
186
+				"lsetxattr",
187
+				"lstat",
188
+				"lstat64",
189
+				"madvise",
190
+				"membarrier",
191
+				"memfd_create",
192
+				"mincore",
193
+				"mkdir",
194
+				"mkdirat",
195
+				"mknod",
196
+				"mknodat",
197
+				"mlock",
198
+				"mlock2",
199
+				"mlockall",
200
+				"mmap",
201
+				"mmap2",
202
+				"mprotect",
203
+				"mq_getsetattr",
204
+				"mq_notify",
205
+				"mq_open",
206
+				"mq_timedreceive",
207
+				"mq_timedreceive_time64",
208
+				"mq_timedsend",
209
+				"mq_timedsend_time64",
210
+				"mq_unlink",
211
+				"mremap",
212
+				"msgctl",
213
+				"msgget",
214
+				"msgrcv",
215
+				"msgsnd",
216
+				"msync",
217
+				"munlock",
218
+				"munlockall",
219
+				"munmap",
220
+				"nanosleep",
221
+				"newfstatat",
222
+				"_newselect",
223
+				"open",
224
+				"openat",
225
+				"openat2",
226
+				"pause",
227
+				"pipe",
228
+				"pipe2",
229
+				"poll",
230
+				"ppoll",
231
+				"ppoll_time64",
232
+				"prctl",
233
+				"pread64",
234
+				"preadv",
235
+				"preadv2",
236
+				"prlimit64",
237
+				"pselect6",
238
+				"pselect6_time64",
239
+				"pwrite64",
240
+				"pwritev",
241
+				"pwritev2",
242
+				"read",
243
+				"readahead",
244
+				"readlink",
245
+				"readlinkat",
246
+				"readv",
247
+				"recv",
248
+				"recvfrom",
249
+				"recvmmsg",
250
+				"recvmmsg_time64",
251
+				"recvmsg",
252
+				"remap_file_pages",
253
+				"removexattr",
254
+				"rename",
255
+				"renameat",
256
+				"renameat2",
257
+				"restart_syscall",
258
+				"rmdir",
259
+				"rseq",
260
+				"rt_sigaction",
261
+				"rt_sigpending",
262
+				"rt_sigprocmask",
263
+				"rt_sigqueueinfo",
264
+				"rt_sigreturn",
265
+				"rt_sigsuspend",
266
+				"rt_sigtimedwait",
267
+				"rt_sigtimedwait_time64",
268
+				"rt_tgsigqueueinfo",
269
+				"sched_getaffinity",
270
+				"sched_getattr",
271
+				"sched_getparam",
272
+				"sched_get_priority_max",
273
+				"sched_get_priority_min",
274
+				"sched_getscheduler",
275
+				"sched_rr_get_interval",
276
+				"sched_rr_get_interval_time64",
277
+				"sched_setaffinity",
278
+				"sched_setattr",
279
+				"sched_setparam",
280
+				"sched_setscheduler",
281
+				"sched_yield",
282
+				"seccomp",
283
+				"select",
284
+				"semctl",
285
+				"semget",
286
+				"semop",
287
+				"semtimedop",
288
+				"semtimedop_time64",
289
+				"send",
290
+				"sendfile",
291
+				"sendfile64",
292
+				"sendmmsg",
293
+				"sendmsg",
294
+				"sendto",
295
+				"setfsgid",
296
+				"setfsgid32",
297
+				"setfsuid",
298
+				"setfsuid32",
299
+				"setgid",
300
+				"setgid32",
301
+				"setgroups",
302
+				"setgroups32",
303
+				"setitimer",
304
+				"setpgid",
305
+				"setpriority",
306
+				"setregid",
307
+				"setregid32",
308
+				"setresgid",
309
+				"setresgid32",
310
+				"setresuid",
311
+				"setresuid32",
312
+				"setreuid",
313
+				"setreuid32",
314
+				"setrlimit",
315
+				"set_robust_list",
316
+				"setsid",
317
+				"setsockopt",
318
+				"set_thread_area",
319
+				"set_tid_address",
320
+				"setuid",
321
+				"setuid32",
322
+				"setxattr",
323
+				"shmat",
324
+				"shmctl",
325
+				"shmdt",
326
+				"shmget",
327
+				"shutdown",
328
+				"sigaltstack",
329
+				"signalfd",
330
+				"signalfd4",
331
+				"sigprocmask",
332
+				"sigreturn",
333
+				"socket",
334
+				"socketcall",
335
+				"socketpair",
336
+				"splice",
337
+				"stat",
338
+				"stat64",
339
+				"statfs",
340
+				"statfs64",
341
+				"statx",
342
+				"symlink",
343
+				"symlinkat",
344
+				"sync",
345
+				"sync_file_range",
346
+				"syncfs",
347
+				"sysinfo",
348
+				"tee",
349
+				"tgkill",
350
+				"time",
351
+				"timer_create",
352
+				"timer_delete",
353
+				"timer_getoverrun",
354
+				"timer_gettime",
355
+				"timer_gettime64",
356
+				"timer_settime",
357
+				"timer_settime64",
358
+				"timerfd_create",
359
+				"timerfd_gettime",
360
+				"timerfd_gettime64",
361
+				"timerfd_settime",
362
+				"timerfd_settime64",
363
+				"times",
364
+				"tkill",
365
+				"truncate",
366
+				"truncate64",
367
+				"ugetrlimit",
368
+				"umask",
369
+				"uname",
370
+				"unlink",
371
+				"unlinkat",
372
+				"utime",
373
+				"utimensat",
374
+				"utimensat_time64",
375
+				"utimes",
376
+				"vfork",
377
+				"vmsplice",
378
+				"wait4",
379
+				"waitid",
380
+				"waitpid",
381
+				"write",
382
+				"writev",
383
+			},
384
+			Action: types.ActAllow,
385
+			Args:   []*types.Arg{},
386
+		},
387
+		{
388
+			Names:  []string{"ptrace"},
389
+			Action: types.ActAllow,
390
+			Includes: types.Filter{
391
+				MinKernel: "4.8",
392
+			},
393
+		},
394
+		{
395
+			Names:  []string{"personality"},
396
+			Action: types.ActAllow,
397
+			Args: []*types.Arg{
398
+				{
399
+					Index: 0,
400
+					Value: 0x0,
401
+					Op:    types.OpEqualTo,
402
+				},
403
+			},
404
+		},
405
+		{
406
+			Names:  []string{"personality"},
407
+			Action: types.ActAllow,
408
+			Args: []*types.Arg{
409
+				{
410
+					Index: 0,
411
+					Value: 0x0008,
412
+					Op:    types.OpEqualTo,
413
+				},
414
+			},
415
+		},
416
+		{
417
+			Names:  []string{"personality"},
418
+			Action: types.ActAllow,
419
+			Args: []*types.Arg{
420
+				{
421
+					Index: 0,
422
+					Value: 0x20000,
423
+					Op:    types.OpEqualTo,
424
+				},
425
+			},
426
+		},
427
+		{
428
+			Names:  []string{"personality"},
429
+			Action: types.ActAllow,
430
+			Args: []*types.Arg{
431
+				{
432
+					Index: 0,
433
+					Value: 0x20008,
434
+					Op:    types.OpEqualTo,
435
+				},
436
+			},
437
+		},
438
+		{
439
+			Names:  []string{"personality"},
440
+			Action: types.ActAllow,
441
+			Args: []*types.Arg{
442
+				{
443
+					Index: 0,
444
+					Value: 0xffffffff,
445
+					Op:    types.OpEqualTo,
446
+				},
447
+			},
448
+		},
449
+		{
450
+			Names: []string{
451
+				"sync_file_range2",
452
+			},
453
+			Action: types.ActAllow,
454
+			Args:   []*types.Arg{},
455
+			Includes: types.Filter{
456
+				Arches: []string{"ppc64le"},
457
+			},
458
+		},
459
+		{
460
+			Names: []string{
461
+				"arm_fadvise64_64",
462
+				"arm_sync_file_range",
463
+				"sync_file_range2",
464
+				"breakpoint",
465
+				"cacheflush",
466
+				"set_tls",
467
+			},
468
+			Action: types.ActAllow,
469
+			Args:   []*types.Arg{},
470
+			Includes: types.Filter{
471
+				Arches: []string{"arm", "arm64"},
472
+			},
473
+		},
474
+		{
475
+			Names: []string{
476
+				"arch_prctl",
477
+			},
478
+			Action: types.ActAllow,
479
+			Args:   []*types.Arg{},
480
+			Includes: types.Filter{
481
+				Arches: []string{"amd64", "x32"},
482
+			},
483
+		},
484
+		{
485
+			Names: []string{
486
+				"modify_ldt",
487
+			},
488
+			Action: types.ActAllow,
489
+			Args:   []*types.Arg{},
490
+			Includes: types.Filter{
491
+				Arches: []string{"amd64", "x32", "x86"},
492
+			},
493
+		},
494
+		{
495
+			Names: []string{
496
+				"s390_pci_mmio_read",
497
+				"s390_pci_mmio_write",
498
+				"s390_runtime_instr",
499
+			},
500
+			Action: types.ActAllow,
501
+			Args:   []*types.Arg{},
502
+			Includes: types.Filter{
503
+				Arches: []string{"s390", "s390x"},
504
+			},
505
+		},
506
+		{
507
+			Names: []string{
508
+				"open_by_handle_at",
509
+			},
510
+			Action: types.ActAllow,
511
+			Args:   []*types.Arg{},
512
+			Includes: types.Filter{
513
+				Caps: []string{"CAP_DAC_READ_SEARCH"},
514
+			},
515
+		},
516
+		{
517
+			Names: []string{
518
+				"bpf",
519
+				"clone",
520
+				"fanotify_init",
521
+				"lookup_dcookie",
522
+				"mount",
523
+				"name_to_handle_at",
524
+				"perf_event_open",
525
+				"quotactl",
526
+				"setdomainname",
527
+				"sethostname",
528
+				"setns",
529
+				"syslog",
530
+				"umount",
531
+				"umount2",
532
+				"unshare",
533
+			},
534
+			Action: types.ActAllow,
535
+			Args:   []*types.Arg{},
536
+			Includes: types.Filter{
537
+				Caps: []string{"CAP_SYS_ADMIN"},
538
+			},
539
+		},
540
+		{
541
+			Names: []string{
542
+				"clone",
543
+			},
544
+			Action: types.ActAllow,
545
+			Args: []*types.Arg{
546
+				{
547
+					Index:    0,
548
+					Value:    unix.CLONE_NEWNS | unix.CLONE_NEWUTS | unix.CLONE_NEWIPC | unix.CLONE_NEWUSER | unix.CLONE_NEWPID | unix.CLONE_NEWNET | unix.CLONE_NEWCGROUP,
549
+					ValueTwo: 0,
550
+					Op:       types.OpMaskedEqual,
551
+				},
552
+			},
553
+			Excludes: types.Filter{
554
+				Caps:   []string{"CAP_SYS_ADMIN"},
555
+				Arches: []string{"s390", "s390x"},
556
+			},
557
+		},
558
+		{
559
+			Names: []string{
560
+				"clone",
561
+			},
562
+			Action: types.ActAllow,
563
+			Args: []*types.Arg{
564
+				{
565
+					Index:    1,
566
+					Value:    unix.CLONE_NEWNS | unix.CLONE_NEWUTS | unix.CLONE_NEWIPC | unix.CLONE_NEWUSER | unix.CLONE_NEWPID | unix.CLONE_NEWNET | unix.CLONE_NEWCGROUP,
567
+					ValueTwo: 0,
568
+					Op:       types.OpMaskedEqual,
569
+				},
570
+			},
571
+			Comment: "s390 parameter ordering for clone is different",
572
+			Includes: types.Filter{
573
+				Arches: []string{"s390", "s390x"},
574
+			},
575
+			Excludes: types.Filter{
576
+				Caps: []string{"CAP_SYS_ADMIN"},
577
+			},
578
+		},
579
+		{
580
+			Names: []string{
581
+				"reboot",
582
+			},
583
+			Action: types.ActAllow,
584
+			Args:   []*types.Arg{},
585
+			Includes: types.Filter{
586
+				Caps: []string{"CAP_SYS_BOOT"},
587
+			},
588
+		},
589
+		{
590
+			Names: []string{
591
+				"chroot",
592
+			},
593
+			Action: types.ActAllow,
594
+			Args:   []*types.Arg{},
595
+			Includes: types.Filter{
596
+				Caps: []string{"CAP_SYS_CHROOT"},
597
+			},
598
+		},
599
+		{
600
+			Names: []string{
601
+				"delete_module",
602
+				"init_module",
603
+				"finit_module",
604
+			},
605
+			Action: types.ActAllow,
606
+			Args:   []*types.Arg{},
607
+			Includes: types.Filter{
608
+				Caps: []string{"CAP_SYS_MODULE"},
609
+			},
610
+		},
611
+		{
612
+			Names: []string{
613
+				"acct",
614
+			},
615
+			Action: types.ActAllow,
616
+			Args:   []*types.Arg{},
617
+			Includes: types.Filter{
618
+				Caps: []string{"CAP_SYS_PACCT"},
619
+			},
620
+		},
621
+		{
622
+			Names: []string{
623
+				"kcmp",
624
+				"process_vm_readv",
625
+				"process_vm_writev",
626
+				"ptrace",
627
+			},
628
+			Action: types.ActAllow,
629
+			Args:   []*types.Arg{},
630
+			Includes: types.Filter{
631
+				Caps: []string{"CAP_SYS_PTRACE"},
632
+			},
633
+		},
634
+		{
635
+			Names: []string{
636
+				"iopl",
637
+				"ioperm",
638
+			},
639
+			Action: types.ActAllow,
640
+			Args:   []*types.Arg{},
641
+			Includes: types.Filter{
642
+				Caps: []string{"CAP_SYS_RAWIO"},
643
+			},
644
+		},
645
+		{
646
+			Names: []string{
647
+				"settimeofday",
648
+				"stime",
649
+				"clock_settime",
650
+			},
651
+			Action: types.ActAllow,
652
+			Args:   []*types.Arg{},
653
+			Includes: types.Filter{
654
+				Caps: []string{"CAP_SYS_TIME"},
655
+			},
656
+		},
657
+		{
658
+			Names: []string{
659
+				"vhangup",
660
+			},
661
+			Action: types.ActAllow,
662
+			Args:   []*types.Arg{},
663
+			Includes: types.Filter{
664
+				Caps: []string{"CAP_SYS_TTY_CONFIG"},
665
+			},
666
+		},
667
+		{
668
+			Names: []string{
669
+				"get_mempolicy",
670
+				"mbind",
671
+				"set_mempolicy",
672
+			},
673
+			Action: types.ActAllow,
674
+			Args:   []*types.Arg{},
675
+			Includes: types.Filter{
676
+				Caps: []string{"CAP_SYS_NICE"},
677
+			},
678
+		},
679
+		{
680
+			Names: []string{
681
+				"syslog",
682
+			},
683
+			Action: types.ActAllow,
684
+			Args:   []*types.Arg{},
685
+			Includes: types.Filter{
686
+				Caps: []string{"CAP_SYSLOG"},
687
+			},
688
+		},
689
+	}
690
+
691
+	return &types.Seccomp{
692
+		DefaultAction: types.ActErrno,
693
+		ArchMap:       arches(),
694
+		Syscalls:      syscalls,
695
+	}
696
+}
0 697
deleted file mode 100644
... ...
@@ -1,189 +0,0 @@
1
-// +build linux
2
-
3
-package seccomp // import "github.com/docker/docker/profiles/seccomp"
4
-
5
-import (
6
-	"encoding/json"
7
-	"errors"
8
-	"fmt"
9
-
10
-	"github.com/docker/docker/api/types"
11
-	"github.com/docker/docker/pkg/parsers/kernel"
12
-	specs "github.com/opencontainers/runtime-spec/specs-go"
13
-	libseccomp "github.com/seccomp/libseccomp-golang"
14
-)
15
-
16
-//go:generate go run -tags 'seccomp' generate.go
17
-
18
-// GetDefaultProfile returns the default seccomp profile.
19
-func GetDefaultProfile(rs *specs.Spec) (*specs.LinuxSeccomp, error) {
20
-	return setupSeccomp(DefaultProfile(), rs)
21
-}
22
-
23
-// LoadProfile takes a json string and decodes the seccomp profile.
24
-func LoadProfile(body string, rs *specs.Spec) (*specs.LinuxSeccomp, error) {
25
-	var config types.Seccomp
26
-	if err := json.Unmarshal([]byte(body), &config); err != nil {
27
-		return nil, fmt.Errorf("Decoding seccomp profile failed: %v", err)
28
-	}
29
-	return setupSeccomp(&config, rs)
30
-}
31
-
32
-var nativeToSeccomp = map[string]types.Arch{
33
-	"amd64":       types.ArchX86_64,
34
-	"arm64":       types.ArchAARCH64,
35
-	"mips64":      types.ArchMIPS64,
36
-	"mips64n32":   types.ArchMIPS64N32,
37
-	"mipsel64":    types.ArchMIPSEL64,
38
-	"mipsel64n32": types.ArchMIPSEL64N32,
39
-	"s390x":       types.ArchS390X,
40
-}
41
-
42
-// inSlice tests whether a string is contained in a slice of strings or not.
43
-// Comparison is case sensitive
44
-func inSlice(slice []string, s string) bool {
45
-	for _, ss := range slice {
46
-		if s == ss {
47
-			return true
48
-		}
49
-	}
50
-	return false
51
-}
52
-
53
-func setupSeccomp(config *types.Seccomp, rs *specs.Spec) (*specs.LinuxSeccomp, error) {
54
-	if config == nil {
55
-		return nil, nil
56
-	}
57
-
58
-	// No default action specified, no syscalls listed, assume seccomp disabled
59
-	if config.DefaultAction == "" && len(config.Syscalls) == 0 {
60
-		return nil, nil
61
-	}
62
-
63
-	newConfig := &specs.LinuxSeccomp{}
64
-
65
-	var arch string
66
-	var native, err = libseccomp.GetNativeArch()
67
-	if err == nil {
68
-		arch = native.String()
69
-	}
70
-
71
-	if len(config.Architectures) != 0 && len(config.ArchMap) != 0 {
72
-		return nil, errors.New("'architectures' and 'archMap' were specified in the seccomp profile, use either 'architectures' or 'archMap'")
73
-	}
74
-
75
-	// if config.Architectures == 0 then libseccomp will figure out the architecture to use
76
-	if len(config.Architectures) != 0 {
77
-		for _, a := range config.Architectures {
78
-			newConfig.Architectures = append(newConfig.Architectures, specs.Arch(a))
79
-		}
80
-	}
81
-
82
-	if len(config.ArchMap) != 0 {
83
-		for _, a := range config.ArchMap {
84
-			seccompArch, ok := nativeToSeccomp[arch]
85
-			if ok {
86
-				if a.Arch == seccompArch {
87
-					newConfig.Architectures = append(newConfig.Architectures, specs.Arch(a.Arch))
88
-					for _, sa := range a.SubArches {
89
-						newConfig.Architectures = append(newConfig.Architectures, specs.Arch(sa))
90
-					}
91
-					break
92
-				}
93
-			}
94
-		}
95
-	}
96
-
97
-	newConfig.DefaultAction = specs.LinuxSeccompAction(config.DefaultAction)
98
-
99
-Loop:
100
-	// Loop through all syscall blocks and convert them to libcontainer format after filtering them
101
-	for _, call := range config.Syscalls {
102
-		if len(call.Excludes.Arches) > 0 {
103
-			if inSlice(call.Excludes.Arches, arch) {
104
-				continue Loop
105
-			}
106
-		}
107
-		if len(call.Excludes.Caps) > 0 {
108
-			for _, c := range call.Excludes.Caps {
109
-				if inSlice(rs.Process.Capabilities.Bounding, c) {
110
-					continue Loop
111
-				}
112
-			}
113
-		}
114
-		if call.Excludes.MinKernel != "" {
115
-			if ok, err := kernelGreaterEqualThan(call.Excludes.MinKernel); err != nil {
116
-				return nil, err
117
-			} else if ok {
118
-				continue Loop
119
-			}
120
-		}
121
-		if len(call.Includes.Arches) > 0 {
122
-			if !inSlice(call.Includes.Arches, arch) {
123
-				continue Loop
124
-			}
125
-		}
126
-		if len(call.Includes.Caps) > 0 {
127
-			for _, c := range call.Includes.Caps {
128
-				if !inSlice(rs.Process.Capabilities.Bounding, c) {
129
-					continue Loop
130
-				}
131
-			}
132
-		}
133
-		if call.Includes.MinKernel != "" {
134
-			if ok, err := kernelGreaterEqualThan(call.Includes.MinKernel); err != nil {
135
-				return nil, err
136
-			} else if !ok {
137
-				continue Loop
138
-			}
139
-		}
140
-
141
-		if call.Name != "" && len(call.Names) != 0 {
142
-			return nil, errors.New("'name' and 'names' were specified in the seccomp profile, use either 'name' or 'names'")
143
-		}
144
-
145
-		if call.Name != "" {
146
-			newConfig.Syscalls = append(newConfig.Syscalls, createSpecsSyscall([]string{call.Name}, call.Action, call.Args))
147
-		} else {
148
-			newConfig.Syscalls = append(newConfig.Syscalls, createSpecsSyscall(call.Names, call.Action, call.Args))
149
-		}
150
-	}
151
-
152
-	return newConfig, nil
153
-}
154
-
155
-func createSpecsSyscall(names []string, action types.Action, args []*types.Arg) specs.LinuxSyscall {
156
-	newCall := specs.LinuxSyscall{
157
-		Names:  names,
158
-		Action: specs.LinuxSeccompAction(action),
159
-	}
160
-
161
-	// Loop through all the arguments of the syscall and convert them
162
-	for _, arg := range args {
163
-		newArg := specs.LinuxSeccompArg{
164
-			Index:    arg.Index,
165
-			Value:    arg.Value,
166
-			ValueTwo: arg.ValueTwo,
167
-			Op:       specs.LinuxSeccompOperator(arg.Op),
168
-		}
169
-
170
-		newCall.Args = append(newCall.Args, newArg)
171
-	}
172
-	return newCall
173
-}
174
-
175
-var currentKernelVersion *kernel.VersionInfo
176
-
177
-func kernelGreaterEqualThan(v string) (bool, error) {
178
-	version, err := kernel.ParseRelease(v)
179
-	if err != nil {
180
-		return false, err
181
-	}
182
-	if currentKernelVersion == nil {
183
-		currentKernelVersion, err = kernel.GetKernelVersion()
184
-		if err != nil {
185
-			return false, err
186
-		}
187
-	}
188
-	return kernel.CompareKernelVersion(*version, *currentKernelVersion) <= 0, nil
189
-}
190 1
deleted file mode 100644
... ...
@@ -1,697 +0,0 @@
1
-// +build linux,seccomp
2
-
3
-package seccomp // import "github.com/docker/docker/profiles/seccomp"
4
-
5
-import (
6
-	"github.com/docker/docker/api/types"
7
-	"golang.org/x/sys/unix"
8
-)
9
-
10
-func arches() []types.Architecture {
11
-	return []types.Architecture{
12
-		{
13
-			Arch:      types.ArchX86_64,
14
-			SubArches: []types.Arch{types.ArchX86, types.ArchX32},
15
-		},
16
-		{
17
-			Arch:      types.ArchAARCH64,
18
-			SubArches: []types.Arch{types.ArchARM},
19
-		},
20
-		{
21
-			Arch:      types.ArchMIPS64,
22
-			SubArches: []types.Arch{types.ArchMIPS, types.ArchMIPS64N32},
23
-		},
24
-		{
25
-			Arch:      types.ArchMIPS64N32,
26
-			SubArches: []types.Arch{types.ArchMIPS, types.ArchMIPS64},
27
-		},
28
-		{
29
-			Arch:      types.ArchMIPSEL64,
30
-			SubArches: []types.Arch{types.ArchMIPSEL, types.ArchMIPSEL64N32},
31
-		},
32
-		{
33
-			Arch:      types.ArchMIPSEL64N32,
34
-			SubArches: []types.Arch{types.ArchMIPSEL, types.ArchMIPSEL64},
35
-		},
36
-		{
37
-			Arch:      types.ArchS390X,
38
-			SubArches: []types.Arch{types.ArchS390},
39
-		},
40
-	}
41
-}
42
-
43
-// DefaultProfile defines the allowed syscalls for the default seccomp profile.
44
-func DefaultProfile() *types.Seccomp {
45
-	syscalls := []*types.Syscall{
46
-		{
47
-			Names: []string{
48
-				"accept",
49
-				"accept4",
50
-				"access",
51
-				"adjtimex",
52
-				"alarm",
53
-				"bind",
54
-				"brk",
55
-				"capget",
56
-				"capset",
57
-				"chdir",
58
-				"chmod",
59
-				"chown",
60
-				"chown32",
61
-				"clock_adjtime",
62
-				"clock_adjtime64",
63
-				"clock_getres",
64
-				"clock_getres_time64",
65
-				"clock_gettime",
66
-				"clock_gettime64",
67
-				"clock_nanosleep",
68
-				"clock_nanosleep_time64",
69
-				"close",
70
-				"connect",
71
-				"copy_file_range",
72
-				"creat",
73
-				"dup",
74
-				"dup2",
75
-				"dup3",
76
-				"epoll_create",
77
-				"epoll_create1",
78
-				"epoll_ctl",
79
-				"epoll_ctl_old",
80
-				"epoll_pwait",
81
-				"epoll_wait",
82
-				"epoll_wait_old",
83
-				"eventfd",
84
-				"eventfd2",
85
-				"execve",
86
-				"execveat",
87
-				"exit",
88
-				"exit_group",
89
-				"faccessat",
90
-				"faccessat2",
91
-				"fadvise64",
92
-				"fadvise64_64",
93
-				"fallocate",
94
-				"fanotify_mark",
95
-				"fchdir",
96
-				"fchmod",
97
-				"fchmodat",
98
-				"fchown",
99
-				"fchown32",
100
-				"fchownat",
101
-				"fcntl",
102
-				"fcntl64",
103
-				"fdatasync",
104
-				"fgetxattr",
105
-				"flistxattr",
106
-				"flock",
107
-				"fork",
108
-				"fremovexattr",
109
-				"fsetxattr",
110
-				"fstat",
111
-				"fstat64",
112
-				"fstatat64",
113
-				"fstatfs",
114
-				"fstatfs64",
115
-				"fsync",
116
-				"ftruncate",
117
-				"ftruncate64",
118
-				"futex",
119
-				"futex_time64",
120
-				"futimesat",
121
-				"getcpu",
122
-				"getcwd",
123
-				"getdents",
124
-				"getdents64",
125
-				"getegid",
126
-				"getegid32",
127
-				"geteuid",
128
-				"geteuid32",
129
-				"getgid",
130
-				"getgid32",
131
-				"getgroups",
132
-				"getgroups32",
133
-				"getitimer",
134
-				"getpeername",
135
-				"getpgid",
136
-				"getpgrp",
137
-				"getpid",
138
-				"getppid",
139
-				"getpriority",
140
-				"getrandom",
141
-				"getresgid",
142
-				"getresgid32",
143
-				"getresuid",
144
-				"getresuid32",
145
-				"getrlimit",
146
-				"get_robust_list",
147
-				"getrusage",
148
-				"getsid",
149
-				"getsockname",
150
-				"getsockopt",
151
-				"get_thread_area",
152
-				"gettid",
153
-				"gettimeofday",
154
-				"getuid",
155
-				"getuid32",
156
-				"getxattr",
157
-				"inotify_add_watch",
158
-				"inotify_init",
159
-				"inotify_init1",
160
-				"inotify_rm_watch",
161
-				"io_cancel",
162
-				"ioctl",
163
-				"io_destroy",
164
-				"io_getevents",
165
-				"io_pgetevents",
166
-				"io_pgetevents_time64",
167
-				"ioprio_get",
168
-				"ioprio_set",
169
-				"io_setup",
170
-				"io_submit",
171
-				"io_uring_enter",
172
-				"io_uring_register",
173
-				"io_uring_setup",
174
-				"ipc",
175
-				"kill",
176
-				"lchown",
177
-				"lchown32",
178
-				"lgetxattr",
179
-				"link",
180
-				"linkat",
181
-				"listen",
182
-				"listxattr",
183
-				"llistxattr",
184
-				"_llseek",
185
-				"lremovexattr",
186
-				"lseek",
187
-				"lsetxattr",
188
-				"lstat",
189
-				"lstat64",
190
-				"madvise",
191
-				"membarrier",
192
-				"memfd_create",
193
-				"mincore",
194
-				"mkdir",
195
-				"mkdirat",
196
-				"mknod",
197
-				"mknodat",
198
-				"mlock",
199
-				"mlock2",
200
-				"mlockall",
201
-				"mmap",
202
-				"mmap2",
203
-				"mprotect",
204
-				"mq_getsetattr",
205
-				"mq_notify",
206
-				"mq_open",
207
-				"mq_timedreceive",
208
-				"mq_timedreceive_time64",
209
-				"mq_timedsend",
210
-				"mq_timedsend_time64",
211
-				"mq_unlink",
212
-				"mremap",
213
-				"msgctl",
214
-				"msgget",
215
-				"msgrcv",
216
-				"msgsnd",
217
-				"msync",
218
-				"munlock",
219
-				"munlockall",
220
-				"munmap",
221
-				"nanosleep",
222
-				"newfstatat",
223
-				"_newselect",
224
-				"open",
225
-				"openat",
226
-				"openat2",
227
-				"pause",
228
-				"pipe",
229
-				"pipe2",
230
-				"poll",
231
-				"ppoll",
232
-				"ppoll_time64",
233
-				"prctl",
234
-				"pread64",
235
-				"preadv",
236
-				"preadv2",
237
-				"prlimit64",
238
-				"pselect6",
239
-				"pselect6_time64",
240
-				"pwrite64",
241
-				"pwritev",
242
-				"pwritev2",
243
-				"read",
244
-				"readahead",
245
-				"readlink",
246
-				"readlinkat",
247
-				"readv",
248
-				"recv",
249
-				"recvfrom",
250
-				"recvmmsg",
251
-				"recvmmsg_time64",
252
-				"recvmsg",
253
-				"remap_file_pages",
254
-				"removexattr",
255
-				"rename",
256
-				"renameat",
257
-				"renameat2",
258
-				"restart_syscall",
259
-				"rmdir",
260
-				"rseq",
261
-				"rt_sigaction",
262
-				"rt_sigpending",
263
-				"rt_sigprocmask",
264
-				"rt_sigqueueinfo",
265
-				"rt_sigreturn",
266
-				"rt_sigsuspend",
267
-				"rt_sigtimedwait",
268
-				"rt_sigtimedwait_time64",
269
-				"rt_tgsigqueueinfo",
270
-				"sched_getaffinity",
271
-				"sched_getattr",
272
-				"sched_getparam",
273
-				"sched_get_priority_max",
274
-				"sched_get_priority_min",
275
-				"sched_getscheduler",
276
-				"sched_rr_get_interval",
277
-				"sched_rr_get_interval_time64",
278
-				"sched_setaffinity",
279
-				"sched_setattr",
280
-				"sched_setparam",
281
-				"sched_setscheduler",
282
-				"sched_yield",
283
-				"seccomp",
284
-				"select",
285
-				"semctl",
286
-				"semget",
287
-				"semop",
288
-				"semtimedop",
289
-				"semtimedop_time64",
290
-				"send",
291
-				"sendfile",
292
-				"sendfile64",
293
-				"sendmmsg",
294
-				"sendmsg",
295
-				"sendto",
296
-				"setfsgid",
297
-				"setfsgid32",
298
-				"setfsuid",
299
-				"setfsuid32",
300
-				"setgid",
301
-				"setgid32",
302
-				"setgroups",
303
-				"setgroups32",
304
-				"setitimer",
305
-				"setpgid",
306
-				"setpriority",
307
-				"setregid",
308
-				"setregid32",
309
-				"setresgid",
310
-				"setresgid32",
311
-				"setresuid",
312
-				"setresuid32",
313
-				"setreuid",
314
-				"setreuid32",
315
-				"setrlimit",
316
-				"set_robust_list",
317
-				"setsid",
318
-				"setsockopt",
319
-				"set_thread_area",
320
-				"set_tid_address",
321
-				"setuid",
322
-				"setuid32",
323
-				"setxattr",
324
-				"shmat",
325
-				"shmctl",
326
-				"shmdt",
327
-				"shmget",
328
-				"shutdown",
329
-				"sigaltstack",
330
-				"signalfd",
331
-				"signalfd4",
332
-				"sigprocmask",
333
-				"sigreturn",
334
-				"socket",
335
-				"socketcall",
336
-				"socketpair",
337
-				"splice",
338
-				"stat",
339
-				"stat64",
340
-				"statfs",
341
-				"statfs64",
342
-				"statx",
343
-				"symlink",
344
-				"symlinkat",
345
-				"sync",
346
-				"sync_file_range",
347
-				"syncfs",
348
-				"sysinfo",
349
-				"tee",
350
-				"tgkill",
351
-				"time",
352
-				"timer_create",
353
-				"timer_delete",
354
-				"timer_getoverrun",
355
-				"timer_gettime",
356
-				"timer_gettime64",
357
-				"timer_settime",
358
-				"timer_settime64",
359
-				"timerfd_create",
360
-				"timerfd_gettime",
361
-				"timerfd_gettime64",
362
-				"timerfd_settime",
363
-				"timerfd_settime64",
364
-				"times",
365
-				"tkill",
366
-				"truncate",
367
-				"truncate64",
368
-				"ugetrlimit",
369
-				"umask",
370
-				"uname",
371
-				"unlink",
372
-				"unlinkat",
373
-				"utime",
374
-				"utimensat",
375
-				"utimensat_time64",
376
-				"utimes",
377
-				"vfork",
378
-				"vmsplice",
379
-				"wait4",
380
-				"waitid",
381
-				"waitpid",
382
-				"write",
383
-				"writev",
384
-			},
385
-			Action: types.ActAllow,
386
-			Args:   []*types.Arg{},
387
-		},
388
-		{
389
-			Names:  []string{"ptrace"},
390
-			Action: types.ActAllow,
391
-			Includes: types.Filter{
392
-				MinKernel: "4.8",
393
-			},
394
-		},
395
-		{
396
-			Names:  []string{"personality"},
397
-			Action: types.ActAllow,
398
-			Args: []*types.Arg{
399
-				{
400
-					Index: 0,
401
-					Value: 0x0,
402
-					Op:    types.OpEqualTo,
403
-				},
404
-			},
405
-		},
406
-		{
407
-			Names:  []string{"personality"},
408
-			Action: types.ActAllow,
409
-			Args: []*types.Arg{
410
-				{
411
-					Index: 0,
412
-					Value: 0x0008,
413
-					Op:    types.OpEqualTo,
414
-				},
415
-			},
416
-		},
417
-		{
418
-			Names:  []string{"personality"},
419
-			Action: types.ActAllow,
420
-			Args: []*types.Arg{
421
-				{
422
-					Index: 0,
423
-					Value: 0x20000,
424
-					Op:    types.OpEqualTo,
425
-				},
426
-			},
427
-		},
428
-		{
429
-			Names:  []string{"personality"},
430
-			Action: types.ActAllow,
431
-			Args: []*types.Arg{
432
-				{
433
-					Index: 0,
434
-					Value: 0x20008,
435
-					Op:    types.OpEqualTo,
436
-				},
437
-			},
438
-		},
439
-		{
440
-			Names:  []string{"personality"},
441
-			Action: types.ActAllow,
442
-			Args: []*types.Arg{
443
-				{
444
-					Index: 0,
445
-					Value: 0xffffffff,
446
-					Op:    types.OpEqualTo,
447
-				},
448
-			},
449
-		},
450
-		{
451
-			Names: []string{
452
-				"sync_file_range2",
453
-			},
454
-			Action: types.ActAllow,
455
-			Args:   []*types.Arg{},
456
-			Includes: types.Filter{
457
-				Arches: []string{"ppc64le"},
458
-			},
459
-		},
460
-		{
461
-			Names: []string{
462
-				"arm_fadvise64_64",
463
-				"arm_sync_file_range",
464
-				"sync_file_range2",
465
-				"breakpoint",
466
-				"cacheflush",
467
-				"set_tls",
468
-			},
469
-			Action: types.ActAllow,
470
-			Args:   []*types.Arg{},
471
-			Includes: types.Filter{
472
-				Arches: []string{"arm", "arm64"},
473
-			},
474
-		},
475
-		{
476
-			Names: []string{
477
-				"arch_prctl",
478
-			},
479
-			Action: types.ActAllow,
480
-			Args:   []*types.Arg{},
481
-			Includes: types.Filter{
482
-				Arches: []string{"amd64", "x32"},
483
-			},
484
-		},
485
-		{
486
-			Names: []string{
487
-				"modify_ldt",
488
-			},
489
-			Action: types.ActAllow,
490
-			Args:   []*types.Arg{},
491
-			Includes: types.Filter{
492
-				Arches: []string{"amd64", "x32", "x86"},
493
-			},
494
-		},
495
-		{
496
-			Names: []string{
497
-				"s390_pci_mmio_read",
498
-				"s390_pci_mmio_write",
499
-				"s390_runtime_instr",
500
-			},
501
-			Action: types.ActAllow,
502
-			Args:   []*types.Arg{},
503
-			Includes: types.Filter{
504
-				Arches: []string{"s390", "s390x"},
505
-			},
506
-		},
507
-		{
508
-			Names: []string{
509
-				"open_by_handle_at",
510
-			},
511
-			Action: types.ActAllow,
512
-			Args:   []*types.Arg{},
513
-			Includes: types.Filter{
514
-				Caps: []string{"CAP_DAC_READ_SEARCH"},
515
-			},
516
-		},
517
-		{
518
-			Names: []string{
519
-				"bpf",
520
-				"clone",
521
-				"fanotify_init",
522
-				"lookup_dcookie",
523
-				"mount",
524
-				"name_to_handle_at",
525
-				"perf_event_open",
526
-				"quotactl",
527
-				"setdomainname",
528
-				"sethostname",
529
-				"setns",
530
-				"syslog",
531
-				"umount",
532
-				"umount2",
533
-				"unshare",
534
-			},
535
-			Action: types.ActAllow,
536
-			Args:   []*types.Arg{},
537
-			Includes: types.Filter{
538
-				Caps: []string{"CAP_SYS_ADMIN"},
539
-			},
540
-		},
541
-		{
542
-			Names: []string{
543
-				"clone",
544
-			},
545
-			Action: types.ActAllow,
546
-			Args: []*types.Arg{
547
-				{
548
-					Index:    0,
549
-					Value:    unix.CLONE_NEWNS | unix.CLONE_NEWUTS | unix.CLONE_NEWIPC | unix.CLONE_NEWUSER | unix.CLONE_NEWPID | unix.CLONE_NEWNET | unix.CLONE_NEWCGROUP,
550
-					ValueTwo: 0,
551
-					Op:       types.OpMaskedEqual,
552
-				},
553
-			},
554
-			Excludes: types.Filter{
555
-				Caps:   []string{"CAP_SYS_ADMIN"},
556
-				Arches: []string{"s390", "s390x"},
557
-			},
558
-		},
559
-		{
560
-			Names: []string{
561
-				"clone",
562
-			},
563
-			Action: types.ActAllow,
564
-			Args: []*types.Arg{
565
-				{
566
-					Index:    1,
567
-					Value:    unix.CLONE_NEWNS | unix.CLONE_NEWUTS | unix.CLONE_NEWIPC | unix.CLONE_NEWUSER | unix.CLONE_NEWPID | unix.CLONE_NEWNET | unix.CLONE_NEWCGROUP,
568
-					ValueTwo: 0,
569
-					Op:       types.OpMaskedEqual,
570
-				},
571
-			},
572
-			Comment: "s390 parameter ordering for clone is different",
573
-			Includes: types.Filter{
574
-				Arches: []string{"s390", "s390x"},
575
-			},
576
-			Excludes: types.Filter{
577
-				Caps: []string{"CAP_SYS_ADMIN"},
578
-			},
579
-		},
580
-		{
581
-			Names: []string{
582
-				"reboot",
583
-			},
584
-			Action: types.ActAllow,
585
-			Args:   []*types.Arg{},
586
-			Includes: types.Filter{
587
-				Caps: []string{"CAP_SYS_BOOT"},
588
-			},
589
-		},
590
-		{
591
-			Names: []string{
592
-				"chroot",
593
-			},
594
-			Action: types.ActAllow,
595
-			Args:   []*types.Arg{},
596
-			Includes: types.Filter{
597
-				Caps: []string{"CAP_SYS_CHROOT"},
598
-			},
599
-		},
600
-		{
601
-			Names: []string{
602
-				"delete_module",
603
-				"init_module",
604
-				"finit_module",
605
-			},
606
-			Action: types.ActAllow,
607
-			Args:   []*types.Arg{},
608
-			Includes: types.Filter{
609
-				Caps: []string{"CAP_SYS_MODULE"},
610
-			},
611
-		},
612
-		{
613
-			Names: []string{
614
-				"acct",
615
-			},
616
-			Action: types.ActAllow,
617
-			Args:   []*types.Arg{},
618
-			Includes: types.Filter{
619
-				Caps: []string{"CAP_SYS_PACCT"},
620
-			},
621
-		},
622
-		{
623
-			Names: []string{
624
-				"kcmp",
625
-				"process_vm_readv",
626
-				"process_vm_writev",
627
-				"ptrace",
628
-			},
629
-			Action: types.ActAllow,
630
-			Args:   []*types.Arg{},
631
-			Includes: types.Filter{
632
-				Caps: []string{"CAP_SYS_PTRACE"},
633
-			},
634
-		},
635
-		{
636
-			Names: []string{
637
-				"iopl",
638
-				"ioperm",
639
-			},
640
-			Action: types.ActAllow,
641
-			Args:   []*types.Arg{},
642
-			Includes: types.Filter{
643
-				Caps: []string{"CAP_SYS_RAWIO"},
644
-			},
645
-		},
646
-		{
647
-			Names: []string{
648
-				"settimeofday",
649
-				"stime",
650
-				"clock_settime",
651
-			},
652
-			Action: types.ActAllow,
653
-			Args:   []*types.Arg{},
654
-			Includes: types.Filter{
655
-				Caps: []string{"CAP_SYS_TIME"},
656
-			},
657
-		},
658
-		{
659
-			Names: []string{
660
-				"vhangup",
661
-			},
662
-			Action: types.ActAllow,
663
-			Args:   []*types.Arg{},
664
-			Includes: types.Filter{
665
-				Caps: []string{"CAP_SYS_TTY_CONFIG"},
666
-			},
667
-		},
668
-		{
669
-			Names: []string{
670
-				"get_mempolicy",
671
-				"mbind",
672
-				"set_mempolicy",
673
-			},
674
-			Action: types.ActAllow,
675
-			Args:   []*types.Arg{},
676
-			Includes: types.Filter{
677
-				Caps: []string{"CAP_SYS_NICE"},
678
-			},
679
-		},
680
-		{
681
-			Names: []string{
682
-				"syslog",
683
-			},
684
-			Action: types.ActAllow,
685
-			Args:   []*types.Arg{},
686
-			Includes: types.Filter{
687
-				Caps: []string{"CAP_SYSLOG"},
688
-			},
689
-		},
690
-	}
691
-
692
-	return &types.Seccomp{
693
-		DefaultAction: types.ActErrno,
694
-		ArchMap:       arches(),
695
-		Syscalls:      syscalls,
696
-	}
697
-}
698 1
new file mode 100644
... ...
@@ -0,0 +1,207 @@
0
+//go:generate go run -tags 'seccomp' generate.go
1
+
2
+package seccomp // import "github.com/docker/docker/profiles/seccomp"
3
+
4
+import (
5
+	"encoding/json"
6
+	"errors"
7
+	"fmt"
8
+	"runtime"
9
+
10
+	"github.com/docker/docker/api/types"
11
+	"github.com/docker/docker/pkg/parsers/kernel"
12
+	specs "github.com/opencontainers/runtime-spec/specs-go"
13
+)
14
+
15
+// GetDefaultProfile returns the default seccomp profile.
16
+func GetDefaultProfile(rs *specs.Spec) (*specs.LinuxSeccomp, error) {
17
+	return setupSeccomp(DefaultProfile(), rs)
18
+}
19
+
20
+// LoadProfile takes a json string and decodes the seccomp profile.
21
+func LoadProfile(body string, rs *specs.Spec) (*specs.LinuxSeccomp, error) {
22
+	var config types.Seccomp
23
+	if err := json.Unmarshal([]byte(body), &config); err != nil {
24
+		return nil, fmt.Errorf("Decoding seccomp profile failed: %v", err)
25
+	}
26
+	return setupSeccomp(&config, rs)
27
+}
28
+
29
+// libseccomp string => seccomp arch
30
+var nativeToSeccomp = map[string]types.Arch{
31
+	"x86":         types.ArchX86,
32
+	"amd64":       types.ArchX86_64,
33
+	"arm":         types.ArchARM,
34
+	"arm64":       types.ArchAARCH64,
35
+	"mips64":      types.ArchMIPS64,
36
+	"mips64n32":   types.ArchMIPS64N32,
37
+	"mipsel64":    types.ArchMIPSEL64,
38
+	"mips3l64n32": types.ArchMIPSEL64N32,
39
+	"mipsle":      types.ArchMIPSEL,
40
+	"ppc":         types.ArchPPC,
41
+	"ppc64":       types.ArchPPC64,
42
+	"ppc64le":     types.ArchPPC64LE,
43
+	"s390":        types.ArchS390,
44
+	"s390x":       types.ArchS390X,
45
+}
46
+
47
+// GOARCH => libseccomp string
48
+var goToNative = map[string]string{
49
+	"386":         "x86",
50
+	"amd64":       "amd64",
51
+	"arm":         "arm",
52
+	"arm64":       "arm64",
53
+	"mips64":      "mips64",
54
+	"mips64p32":   "mips64n32",
55
+	"mips64le":    "mipsel64",
56
+	"mips64p32le": "mips3l64n32",
57
+	"mipsle":      "mipsel",
58
+	"ppc":         "ppc",
59
+	"ppc64":       "ppc64",
60
+	"ppc64le":     "ppc64le",
61
+	"s390":        "s390",
62
+	"s390x":       "s390x",
63
+}
64
+
65
+// inSlice tests whether a string is contained in a slice of strings or not.
66
+// Comparison is case sensitive
67
+func inSlice(slice []string, s string) bool {
68
+	for _, ss := range slice {
69
+		if s == ss {
70
+			return true
71
+		}
72
+	}
73
+	return false
74
+}
75
+
76
+func setupSeccomp(config *types.Seccomp, rs *specs.Spec) (*specs.LinuxSeccomp, error) {
77
+	if config == nil {
78
+		return nil, nil
79
+	}
80
+
81
+	// No default action specified, no syscalls listed, assume seccomp disabled
82
+	if config.DefaultAction == "" && len(config.Syscalls) == 0 {
83
+		return nil, nil
84
+	}
85
+
86
+	newConfig := &specs.LinuxSeccomp{}
87
+
88
+	if len(config.Architectures) != 0 && len(config.ArchMap) != 0 {
89
+		return nil, errors.New("'architectures' and 'archMap' were specified in the seccomp profile, use either 'architectures' or 'archMap'")
90
+	}
91
+
92
+	// if config.Architectures == 0 then libseccomp will figure out the architecture to use
93
+	if len(config.Architectures) != 0 {
94
+		for _, a := range config.Architectures {
95
+			newConfig.Architectures = append(newConfig.Architectures, specs.Arch(a))
96
+		}
97
+	}
98
+
99
+	arch := goToNative[runtime.GOARCH]
100
+	seccompArch, archExists := nativeToSeccomp[arch]
101
+
102
+	if len(config.ArchMap) != 0 && archExists {
103
+		for _, a := range config.ArchMap {
104
+			if a.Arch == seccompArch {
105
+				newConfig.Architectures = append(newConfig.Architectures, specs.Arch(a.Arch))
106
+				for _, sa := range a.SubArches {
107
+					newConfig.Architectures = append(newConfig.Architectures, specs.Arch(sa))
108
+				}
109
+				break
110
+			}
111
+		}
112
+	}
113
+
114
+	newConfig.DefaultAction = specs.LinuxSeccompAction(config.DefaultAction)
115
+
116
+Loop:
117
+	// Loop through all syscall blocks and convert them to libcontainer format after filtering them
118
+	for _, call := range config.Syscalls {
119
+		if len(call.Excludes.Arches) > 0 {
120
+			if inSlice(call.Excludes.Arches, arch) {
121
+				continue Loop
122
+			}
123
+		}
124
+		if len(call.Excludes.Caps) > 0 {
125
+			for _, c := range call.Excludes.Caps {
126
+				if inSlice(rs.Process.Capabilities.Bounding, c) {
127
+					continue Loop
128
+				}
129
+			}
130
+		}
131
+		if call.Excludes.MinKernel != "" {
132
+			if ok, err := kernelGreaterEqualThan(call.Excludes.MinKernel); err != nil {
133
+				return nil, err
134
+			} else if ok {
135
+				continue Loop
136
+			}
137
+		}
138
+		if len(call.Includes.Arches) > 0 {
139
+			if !inSlice(call.Includes.Arches, arch) {
140
+				continue Loop
141
+			}
142
+		}
143
+		if len(call.Includes.Caps) > 0 {
144
+			for _, c := range call.Includes.Caps {
145
+				if !inSlice(rs.Process.Capabilities.Bounding, c) {
146
+					continue Loop
147
+				}
148
+			}
149
+		}
150
+		if call.Includes.MinKernel != "" {
151
+			if ok, err := kernelGreaterEqualThan(call.Includes.MinKernel); err != nil {
152
+				return nil, err
153
+			} else if !ok {
154
+				continue Loop
155
+			}
156
+		}
157
+
158
+		if call.Name != "" && len(call.Names) != 0 {
159
+			return nil, errors.New("'name' and 'names' were specified in the seccomp profile, use either 'name' or 'names'")
160
+		}
161
+
162
+		if call.Name != "" {
163
+			newConfig.Syscalls = append(newConfig.Syscalls, createSpecsSyscall([]string{call.Name}, call.Action, call.Args))
164
+		} else {
165
+			newConfig.Syscalls = append(newConfig.Syscalls, createSpecsSyscall(call.Names, call.Action, call.Args))
166
+		}
167
+	}
168
+
169
+	return newConfig, nil
170
+}
171
+
172
+func createSpecsSyscall(names []string, action types.Action, args []*types.Arg) specs.LinuxSyscall {
173
+	newCall := specs.LinuxSyscall{
174
+		Names:  names,
175
+		Action: specs.LinuxSeccompAction(action),
176
+	}
177
+
178
+	// Loop through all the arguments of the syscall and convert them
179
+	for _, arg := range args {
180
+		newArg := specs.LinuxSeccompArg{
181
+			Index:    arg.Index,
182
+			Value:    arg.Value,
183
+			ValueTwo: arg.ValueTwo,
184
+			Op:       specs.LinuxSeccompOperator(arg.Op),
185
+		}
186
+
187
+		newCall.Args = append(newCall.Args, newArg)
188
+	}
189
+	return newCall
190
+}
191
+
192
+var currentKernelVersion *kernel.VersionInfo
193
+
194
+func kernelGreaterEqualThan(v string) (bool, error) {
195
+	version, err := kernel.ParseRelease(v)
196
+	if err != nil {
197
+		return false, err
198
+	}
199
+	if currentKernelVersion == nil {
200
+		currentKernelVersion, err = kernel.GetKernelVersion()
201
+		if err != nil {
202
+			return false, err
203
+		}
204
+	}
205
+	return kernel.CompareKernelVersion(*version, *currentKernelVersion) <= 0, nil
206
+}