summaryrefslogtreecommitdiffhomepage
path: root/pkg/seccomp/seccomp_test_victim.go
blob: fe3f9690155b2c8667c21fbcdb7ba21aa1964aec (plain)
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
// Copyright 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Test binary used to test that seccomp filters are properly constructed and
// indeed kill the process on violation.
package main

import (
	"flag"
	"fmt"
	"os"
	"syscall"

	"gvisor.googlesource.com/gvisor/pkg/seccomp"
)

func main() {
	dieFlag := flag.Bool("die", false, "trips over the filter if true")
	flag.Parse()

	syscalls := []uintptr{
		syscall.SYS_ACCEPT,
		syscall.SYS_ARCH_PRCTL,
		syscall.SYS_BIND,
		syscall.SYS_BRK,
		syscall.SYS_CLOCK_GETTIME,
		syscall.SYS_CLONE,
		syscall.SYS_CLOSE,
		syscall.SYS_DUP,
		syscall.SYS_DUP2,
		syscall.SYS_EPOLL_CREATE1,
		syscall.SYS_EPOLL_CTL,
		syscall.SYS_EPOLL_WAIT,
		syscall.SYS_EXIT,
		syscall.SYS_EXIT_GROUP,
		syscall.SYS_FALLOCATE,
		syscall.SYS_FCHMOD,
		syscall.SYS_FCNTL,
		syscall.SYS_FSTAT,
		syscall.SYS_FSYNC,
		syscall.SYS_FTRUNCATE,
		syscall.SYS_FUTEX,
		syscall.SYS_GETDENTS64,
		syscall.SYS_GETPEERNAME,
		syscall.SYS_GETPID,
		syscall.SYS_GETSOCKNAME,
		syscall.SYS_GETSOCKOPT,
		syscall.SYS_GETTID,
		syscall.SYS_GETTIMEOFDAY,
		syscall.SYS_LISTEN,
		syscall.SYS_LSEEK,
		syscall.SYS_MADVISE,
		syscall.SYS_MINCORE,
		syscall.SYS_MMAP,
		syscall.SYS_MPROTECT,
		syscall.SYS_MUNLOCK,
		syscall.SYS_MUNMAP,
		syscall.SYS_NANOSLEEP,
		syscall.SYS_NEWFSTATAT,
		syscall.SYS_OPEN,
		syscall.SYS_POLL,
		syscall.SYS_PREAD64,
		syscall.SYS_PSELECT6,
		syscall.SYS_PWRITE64,
		syscall.SYS_READ,
		syscall.SYS_READLINKAT,
		syscall.SYS_READV,
		syscall.SYS_RECVMSG,
		syscall.SYS_RENAMEAT,
		syscall.SYS_RESTART_SYSCALL,
		syscall.SYS_RT_SIGACTION,
		syscall.SYS_RT_SIGPROCMASK,
		syscall.SYS_RT_SIGRETURN,
		syscall.SYS_SCHED_YIELD,
		syscall.SYS_SENDMSG,
		syscall.SYS_SETITIMER,
		syscall.SYS_SET_ROBUST_LIST,
		syscall.SYS_SETSOCKOPT,
		syscall.SYS_SHUTDOWN,
		syscall.SYS_SIGALTSTACK,
		syscall.SYS_SOCKET,
		syscall.SYS_SYNC_FILE_RANGE,
		syscall.SYS_TGKILL,
		syscall.SYS_UTIMENSAT,
		syscall.SYS_WRITE,
		syscall.SYS_WRITEV,
	}
	die := *dieFlag
	if !die {
		syscalls = append(syscalls, syscall.SYS_OPENAT)
	}

	if err := seccomp.Install(syscalls, false); err != nil {
		fmt.Printf("Failed to install seccomp: %v", err)
		os.Exit(1)
	}
	fmt.Printf("Filters installed\n")

	syscall.RawSyscall(syscall.SYS_OPENAT, 0, 0, 0)
	fmt.Printf("Syscall was allowed!!!\n")
}