github.com/metacubex/gvisor@v0.0.0-20240320004321-933faba989ec/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/metacubex/gvisor/pkg/log" 22 "github.com/metacubex/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 DirectFS bool 31 } 32 33 // Install installs seccomp filters. 34 func Install(opt Options) error { 35 s := allowedSyscalls 36 37 if opt.ProfileEnabled { 38 report("profile enabled: syscall filters less restrictive!") 39 s.Merge(profileFilters) 40 } 41 42 if opt.UDSOpenEnabled || opt.UDSCreateEnabled { 43 report("host UDS enabled: syscall filters less restrictive!") 44 s.Merge(udsCommonSyscalls) 45 if opt.UDSOpenEnabled { 46 s.Merge(udsOpenSyscalls) 47 } 48 if opt.UDSCreateEnabled { 49 s.Merge(udsCreateSyscalls) 50 } 51 } 52 53 // Set of additional filters used by -race and -msan. Returns empty 54 // when not enabled. 55 s.Merge(instrumentationFilters()) 56 57 // When DirectFS is not enabled, filters for LisaFS are installed. 58 if !opt.DirectFS { 59 s.Merge(lisafsFilters) 60 } 61 62 return seccomp.Install(s, seccomp.DenyNewExecMappings, seccomp.DefaultProgramOptions()) 63 } 64 65 // report writes a warning message to the log. 66 func report(msg string) { 67 log.Warningf("*** SECCOMP WARNING: %s", msg) 68 }