forked from capeprivacy/capejail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seccomp.c
1366 lines (1101 loc) · 22.9 KB
/
seccomp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <seccomp.h>
#include <stdio.h>
#include "banned.h"
#include "logger.h"
#include "seccomp.h"
static const int ALLOWED_SYSCALLS[] = {
/*
* Check user's permissions for a file.
*/
SCMP_SYS(access),
/*
* Sends a SIGALRM signal to the calling process after a number of seconds.
* Sleep could possibly be implemented using alarm in some libraries.
*/
SCMP_SYS(alarm),
/*
* Set architecture-specific thread state. Used by numpy.
*/
SCMP_SYS(arch_prctl),
/*
* Bind an address to a socket.
*/
SCMP_SYS(bind),
/*
* Used to adjust the heap. Mostly obsoleted by mmap, but could be used by
* a malloc implementation.
*/
SCMP_SYS(brk),
/*
* Get capabilities of calling thread. Unlikely to be useful
*/
SCMP_SYS(capget),
/*
* Set permissions of file.
*/
SCMP_SYS(chmod),
/*
* Change ownership of a file.
*/
SCMP_SYS(chown),
/*
* Change directories. Pretty useful, and with the chroot jail along with
* seccomp filtering, it should be unlikely to be exploitable.
*/
SCMP_SYS(chdir),
/*
* Get the resolution (precision) of the system clock.
*/
SCMP_SYS(clock_getres),
/*
* Get the current time.
*/
SCMP_SYS(clock_gettime),
/*
* Put the thread to sleep with nanosecond precision.
*/
SCMP_SYS(clock_nanosleep),
/*
* The Linux way of doing [fork](#fork), but with more options and better
* performance.
*/
SCMP_SYS(clone),
/*
* See [clone](#clone).
*/
SCMP_SYS(clone3),
/*
* Close a file descriptor.
*/
SCMP_SYS(close),
/*
* Close all file descriptors from first to last.
*/
SCMP_SYS(close_range),
/*
* Initiate a socket connection. Used by a lot of programs, including `ls
* -l`.
*/
SCMP_SYS(connect),
/*
* Copy a range of data from one file to another
*/
SCMP_SYS(copy_file_range),
/*
* Create a file with given permissions.
*/
SCMP_SYS(creat),
/*
* Duplicate a file descriptor.
*/
SCMP_SYS(dup),
/*
* See [dup](#dup).
*/
SCMP_SYS(dup2),
/*
* See [dup](#dup).
*/
SCMP_SYS(dup3),
/*
* Create an epoll instance, used for monitoring files for IO.
*/
SCMP_SYS(epoll_create),
/*
* See [epoll_create](#epoll_create).
*/
SCMP_SYS(epoll_create1),
/*
* See [epoll_create](#epoll_create).
*/
SCMP_SYS(epoll_ctl),
/*
* See [epoll_create](#epoll_create).
*/
SCMP_SYS(epoll_ctl_old),
/*
* See [epoll_create](#epoll_create).
*/
SCMP_SYS(epoll_pwait),
/*
* See [epoll_create](#epoll_create).
*/
SCMP_SYS(epoll_wait),
/*
* See [epoll_create](#epoll_create).
*/
SCMP_SYS(epoll_wait_old),
/*
* Create a file descriptor for event notification.
*/
SCMP_SYS(eventfd),
/*
* See [eventfd](#eventfd).
*/
SCMP_SYS(eventfd2),
/*
* Execute a program.
*/
SCMP_SYS(execve),
/*
* See [execve](#execve).
*/
SCMP_SYS(execveat),
/*
* Terminate the calling process
*/
SCMP_SYS(exit),
/*
* See [exit](#exit).
*/
SCMP_SYS(exit_group),
/*
* Check the user's permissions for a file. See [access](#access).
*/
SCMP_SYS(faccessat),
/*
* See [faccessat](#faccessat).
*/
SCMP_SYS(faccessat2),
/*
* Declare an access pattern for data.
*/
SCMP_SYS(fadvise64),
/*
* Allocate space for a file.
*/
SCMP_SYS(fallocate),
/*
* Initialize an fanotify group.
*/
SCMP_SYS(fanotify_init),
/*
* See [fanotify_init](#fanotify_init)
*/
SCMP_SYS(fanotify_mark),
/*
* Change working directory. See [chdir](#chdir)
*/
SCMP_SYS(fchdir),
/*
* Toolbox for manipulating a file descriptor.
*/
SCMP_SYS(fcntl),
/*
* See [fsync](#fsync)
*/
SCMP_SYS(fdatasync),
/*
* Get extended attributes for file descriptor.
*/
SCMP_SYS(fgetxattr),
/*
* List extended attributes for file descriptor.
*/
SCMP_SYS(flistxattr),
/*
* Place or remove a lock on a file.
*/
SCMP_SYS(flock),
/*
* Create a child process. Mostly replaced by [clone](#clone).
*/
SCMP_SYS(fork),
/*
* Remove extended file attributes.
*/
SCMP_SYS(fremovexattr),
/*
* Set the value of extended file attributes.
*/
SCMP_SYS(fsetxattr),
/*
* Get file status.
*/
SCMP_SYS(fstat),
/*
* Get filesystem status.
*/
SCMP_SYS(fstatfs),
/*
* Sync data to disk (with caveats that disk vendors often lie about
* fsync).
*/
SCMP_SYS(fsync),
/*
* Shrink a file to the given size in bytes.
*/
SCMP_SYS(ftruncate),
/*
* User space lock.
*/
SCMP_SYS(futex),
/*
* Identify which CPU the thread is running on.
*/
SCMP_SYS(getcpu),
/*
* Get current working directory.
*/
SCMP_SYS(getcwd),
/*
* Get directory entries.
*/
SCMP_SYS(getdents),
/*
* See [getdents](#getdents)
*/
SCMP_SYS(getdents64),
/*
* Get effective user id
*/
SCMP_SYS(geteuid),
/*
* Get effective group id
*/
SCMP_SYS(getegid),
/*
* Get real group id
*/
SCMP_SYS(getgid),
/*
* Get groups
*/
SCMP_SYS(getgroups),
/*
* Get timer
*/
SCMP_SYS(getitimer),
/*
* Retrieve NUMA memory policy for a thread.
*/
SCMP_SYS(get_mempolicy),
/*
* Get name of connected peer socket.
*/
SCMP_SYS(getpeername),
/*
* Get process group.
*/
SCMP_SYS(getpgid),
/*
* See [getpgid](#getpgid)
*/
SCMP_SYS(getpgrp),
/*
* Get process ID.
*/
SCMP_SYS(getpid),
/*
* Get process ID of parent process.
*/
SCMP_SYS(getppid),
/*
* Get scheduling priority.
*/
SCMP_SYS(getpriority),
/*
* Fill a buffer with random bytes.
*/
SCMP_SYS(getrandom),
/*
* Get real, effective, and saved group IDs
*/
SCMP_SYS(getresuid),
/*
* Get real, effective, and saved user IDs
*/
SCMP_SYS(getresuid),
/*
* Get resource limits
*/
SCMP_SYS(getrlimit),
/*
* Get list of robust futexes.
*/
SCMP_SYS(get_robust_list),
/*
* Get resource usage.
*/
SCMP_SYS(getrusage),
/*
* Get session ID.
*/
SCMP_SYS(getsid),
/*
* Get the address that the socket file descriptor is bound to.
*/
SCMP_SYS(getsockname),
/*
* Get options on socket.
*/
SCMP_SYS(getsockopt),
/*
* Get thread local storage information.
*/
SCMP_SYS(get_thread_area),
/*
* Get thread ID.
*/
SCMP_SYS(gettid),
/*
* Get time of day.
*/
SCMP_SYS(gettimeofday),
/*
* Get User ID of process.
*/
SCMP_SYS(getuid),
/*
* Get extended attribute value.
*/
SCMP_SYS(getxattr),
/*
* Part of the inotify API to monitor files and directories.
*/
SCMP_SYS(inotify_add_watch),
/*
* See [inotify_add_watch](#inotify_add_watch)
*/
SCMP_SYS(inotify_init),
/*
* See [inotify_add_watch](#inotify_add_watch)
*/
SCMP_SYS(inotify_init1),
/*
* See [inotify_add_watch](#inotify_add_watch)
*/
SCMP_SYS(inotify_rm_watch),
/*
* Cancel an IO operation.
*/
SCMP_SYS(io_cancel),
/*
* Control an IO device.
*/
SCMP_SYS(ioctl),
/*
* Destroy an IO context.
*/
SCMP_SYS(io_destroy),
/*
* Read asynchronous I/O events from the completion queue
*/
SCMP_SYS(io_getevents),
/*
* Get IO scheduling priority.
*/
SCMP_SYS(ioprio_get),
/*
* Set the scheduling priority of the calling process.
*/
SCMP_SYS(ioprio_set),
/*
* Create an async IO context.
*/
SCMP_SYS(io_setup),
/*
* See [io_setup](#io_setup)
*/
SCMP_SYS(io_setup),
/*
* See [io_setup](#io_setup)
*/
SCMP_SYS(io_submit),
/*
* See [io_setup](#io_setup)
*/
SCMP_SYS(io_uring_enter),
/*
* See [io_setup](#io_setup)
*/
SCMP_SYS(io_uring_register),
/*
* See [io_setup](#io_setup)
*/
SCMP_SYS(io_uring_setup),
/*
* Send a signal to a process. We can't really get away from signaling
* processes, and even if the user program manages to get root, it couldn't
* leak private information by killing other processes, so there is little
* risk to allow the kill system call.
*/
SCMP_SYS(kill),
/*
* See [chown](#chown)
*/
SCMP_SYS(lchown),
/*
* See [getxattr](#getxattr)
*/
SCMP_SYS(lgetxattr),
/*
* List extended attributes
*/
SCMP_SYS(listxattr),
/*
* See [listxattr](#listxattr)
*/
SCMP_SYS(llistxattr),
/*
* Lookup path of directory entry.
*/
SCMP_SYS(lookup_dcookie),
/*
* Remove an extended attribute.
*/
SCMP_SYS(lremovexattr),
/*
* Seek to a location in a file.
*/
SCMP_SYS(lseek),
/*
* Set extended attributes.
*/
SCMP_SYS(lsetxattr),
/*
* Get file status.
*/
SCMP_SYS(lstat),
/*
* Inform the kernel of which address ranges the process will be used for
* performance improvements.
*/
SCMP_SYS(madvise),
/*
* Set NUMA policy, used by numpy
*/
SCMP_SYS(mbind),
/*
* Issue memory barriers on a set of threads
*/
SCMP_SYS(membarrier),
/*
* Create a memory backed file.
*/
SCMP_SYS(memfd_create),
/*
* Create a memory region only visible to the calling process.
* See the [Phoronix
* article](https://www.phoronix.com/news/Linux-5.14-memfd_secret) for
* details.
*/
SCMP_SYS(memfd_secret),
/*
* Determine whether pages are resident in memory.
*/
SCMP_SYS(mincore),
/*
* Create a directory.
*/
SCMP_SYS(mkdir),
/*
* See [mkdir](#mkdir)
*/
SCMP_SYS(mkdirat),
/*
* Lock pages in memory, and keep them from getting swapped out.
*/
SCMP_SYS(mlock),
/*
* See [mlock](#mlock)
*/
SCMP_SYS(mlock2),
/*
* See [mlock](#mlock)
*/
SCMP_SYS(mlockall),
/*
* Create a new mapping in virtual memory. Can map files into memory
* segments, or can be used to allocate physical memory to a virtual memory
* address space. Often malloc implementations use mmap.
*/
SCMP_SYS(mmap),
/*
* Modify the local descriptor table for the calling process.
*/
SCMP_SYS(modify_ldt),
/*
* Change the access protections for the calling process's memory at a
* given address range. Needed by many common programs.
*/
SCMP_SYS(mprotect),
/*
* See [mq_open](#mq-open)
*/
SCMP_SYS(mq_getsetattr),
/*
* See [mq_open](#mq-open)
*/
SCMP_SYS(mq_notify),
/*
* Open a message queue.
*/
SCMP_SYS(mq_open),
/*
* See [mq_open](#mq-open)
*/
SCMP_SYS(mq_timedreceive),
/*
* See [mq_open](#mq-open)
*/
SCMP_SYS(mq_timedsend),
/*
* Remove a message queue.
*/
SCMP_SYS(mq_unlink),
/*
* Expand or shrink an existing memory map. Possibly used by malloc.
*/
SCMP_SYS(mremap),
/*
* Perform control operation on message queue.
*/
SCMP_SYS(msgctl),
/*
* Get a message queue identifier.
*/
SCMP_SYS(msgget),
/*
* Receive message from a message queue.
*/
SCMP_SYS(msgrcv),
/*
* Send a message on a message queue.
*/
SCMP_SYS(msgsnd),
/*
* Synchronize a memory mapped file to disk.
*/
SCMP_SYS(msync),
/*
* See [mlock](#mlock)
*/
SCMP_SYS(munlock),
/*
* See [mlock](#mlock)
*/
SCMP_SYS(munlockall),
/*
* Unmap a region of memory.
*/
SCMP_SYS(munmap),
/*
* Get a handle for a pathname.
*/
SCMP_SYS(name_to_handle_at),
/*
* High resolution sleep.
*/
SCMP_SYS(nanosleep),
/*
* See [fstat](#fstat)
*/
SCMP_SYS(newfstatat),
/*
* Open and/or create a file.
*/
SCMP_SYS(open),
/*
* See [open](#open)
*/
SCMP_SYS(openat),
/*
* See [open](#open)
*/
SCMP_SYS(openat2),
/*
* Open a file via a handle.
*/
SCMP_SYS(open_by_handle_at),
/*
* Calling process waits for a signal.
*/
SCMP_SYS(pause),
/*
* Set which "personality" the process will use.
*/
SCMP_SYS(personality),
/*
* Get a file descriptor to refer to a process.
*/
SCMP_SYS(pidfd_open),
/*
* Send a signal to a process as a file descriptor.
*/
SCMP_SYS(pidfd_send_signal),
/*
* Create a unidirectional data channel.
*/
SCMP_SYS(pipe),
/*
* See [pipe](#pipe)
*/
SCMP_SYS(pipe2),
/*
* Allocate a protection key.
*/
SCMP_SYS(pkey_alloc),
/*
* Free a protection key.
*/
SCMP_SYS(pkey_free),
/*
* Set memory protection using pkeys(7).
*/
SCMP_SYS(pkey_mprotect),
/*
* Wait for an event on a file descriptor.
*/
SCMP_SYS(poll),
/*
* See [poll](poll)
*/
SCMP_SYS(ppoll),
/*
* Manipulate the calling thread/process.
*/
SCMP_SYS(prctl),
/*
* Read from an fd at a given offset.
*/
SCMP_SYS(pread64),
/*
* Read data into multiple buffers.
*/
SCMP_SYS(preadv),
/*
* Set resource limits.
*/
SCMP_SYS(prlimit64),
/*
* Give advice about use of memory to a process
*/
SCMP_SYS(process_madvise),
/*
* IO multiplexing.
*/
SCMP_SYS(pselect6),
/*
* Write to an fd at a given offset.
*/
SCMP_SYS(pwrite64),
/*
* Write data into multiple buffers.
*/
SCMP_SYS(pwritev),
/*
* See [pwritev](#pwritev)
*/
SCMP_SYS(pwritev2),
/*
* Read from a file descriptor.
*/
SCMP_SYS(read),
/*
* Initiate file readahead into page cache.
*/
SCMP_SYS(readahead),
/*
* Read the value of a symbolic link.
*/
SCMP_SYS(readlink),
/*
* See [readlink](#readlink)
*/
SCMP_SYS(readlinkat),
/*
* Read data into multiple buffers.
*/
SCMP_SYS(readv),
/*
* Receive a message from a socket.
*/
SCMP_SYS(recvfrom),
/*
* Receive multiple messages from a socket.
*/
SCMP_SYS(recvmmsg),
/*
* Receive a message from a socket.
*/
SCMP_SYS(recvmsg),
/*
* Deprecated, but not harmful. Create a nonlinear file mapping.
*/
SCMP_SYS(remap_file_pages),
/*
* Remove an extended attribute
*/
SCMP_SYS(removexattr),
/*
* Change the name or location of a file.
*/
SCMP_SYS(rename),
/*
* See [rename](#rename)
*/
SCMP_SYS(renameat),
/*
* See [rename](#rename)
*/
SCMP_SYS(renameat2),
/*
* Restart a system call after interruption by a stop signal.
*/
SCMP_SYS(restart_syscall),
/*
* Remove directory.
*/
SCMP_SYS(rmdir),
/*
* Restartable sequence, see:
* https://www.phoronix.com/news/Restartable-Sequences-Speed
*/
SCMP_SYS(rseq),
/*
* Change the behavior of a signal action.
*/
SCMP_SYS(rt_sigaction),
/*
* See [rt_sigaction](#rt-sigaction)
*/
SCMP_SYS(rt_sigpending),
/*
* See [rt_sigaction](#rt-sigaction)
*/
SCMP_SYS(rt_sigprocmask),
/*
* See [rt_sigaction](#rt-sigaction)
*/
SCMP_SYS(rt_sigqueueinfo),
/*
* See [rt_sigaction](#rt-sigaction)
*/
SCMP_SYS(rt_sigreturn),
/*
* See [rt_sigaction](#rt-sigaction)
*/
SCMP_SYS(rt_sigsuspend),
/*
* See [rt_sigaction](#rt-sigaction)
*/
SCMP_SYS(rt_sigtimedwait),
/*
* See [rt_sigaction](#rt-sigaction)
*/
SCMP_SYS(rt_tgsigqueueinfo),
/*
* Numpy looks up scheduling configuration for process.
*/
SCMP_SYS(sched_getaffinity),
SCMP_SYS(sched_getattr),
SCMP_SYS(sched_getparam),
SCMP_SYS(sched_get_priority_max),
SCMP_SYS(sched_get_priority_min),
SCMP_SYS(sched_getscheduler),
SCMP_SYS(sched_rr_get_interval),
SCMP_SYS(sched_yield),
SCMP_SYS(sched_setaffinity),
/*
* Monitor multiple file descriptors.
*/
SCMP_SYS(select),
/*