github.com/MerlinKodo/gvisor@v0.0.0-20231110090155-957f62ecf90e/runsc/fsgofer/filter/filter.go (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package filter defines all syscalls the gofer is allowed to make, and 16 // installs seccomp filters to prevent prohibited syscalls in case it's 17 // compromised. 18 package filter 19 20 import ( 21 "github.com/MerlinKodo/gvisor/pkg/log" 22 "github.com/MerlinKodo/gvisor/pkg/seccomp" 23 ) 24 25 // Options are seccomp filter related options. 26 type Options struct { 27 UDSOpenEnabled bool 28 UDSCreateEnabled bool 29 ProfileEnabled bool 30 } 31 32 // Install installs seccomp filters. 33 func Install(opt Options) error { 34 s := allowedSyscalls 35 36 if opt.ProfileEnabled { 37 report("profile enabled: syscall filters less restrictive!") 38 s.Merge(profileFilters) 39 } 40 41 if opt.UDSOpenEnabled || opt.UDSCreateEnabled { 42 report("host UDS enabled: syscall filters less restrictive!") 43 s.Merge(udsCommonSyscalls) 44 if opt.UDSOpenEnabled { 45 s.Merge(udsOpenSyscalls) 46 } 47 if opt.UDSCreateEnabled { 48 s.Merge(udsCreateSyscalls) 49 } 50 } 51 52 // Set of additional filters used by -race and -msan. Returns empty 53 // when not enabled. 54 s.Merge(instrumentationFilters()) 55 56 return seccomp.Install(s, seccomp.DenyNewExecMappings) 57 } 58 59 // report writes a warning message to the log. 60 func report(msg string) { 61 log.Warningf("*** SECCOMP WARNING: %s", msg) 62 }