github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/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/SagerNet/gvisor/pkg/seccomp"
    22  )
    23  
    24  // Install installs seccomp filters.
    25  func Install() error {
    26  	// Set of additional filters used by -race and -msan. Returns empty
    27  	// when not enabled.
    28  	allowedSyscalls.Merge(instrumentationFilters())
    29  
    30  	return seccomp.Install(allowedSyscalls)
    31  }
    32  
    33  // InstallUDSFilters extends the allowed syscalls to include those necessary for
    34  // connecting to a host UDS.
    35  func InstallUDSFilters() {
    36  	// Add additional filters required for connecting to the host's sockets.
    37  	allowedSyscalls.Merge(udsSyscalls)
    38  }
    39  
    40  // InstallXattrFilters extends the allowed syscalls to include xattr calls that
    41  // are necessary for Verity enabled file systems.
    42  func InstallXattrFilters() {
    43  	allowedSyscalls.Merge(xattrSyscalls)
    44  }