diff --git a/runsc/cmd/gofer.go b/runsc/cmd/gofer.go index 75598bf3a..36ebd0dc4 100644 --- a/runsc/cmd/gofer.go +++ b/runsc/cmd/gofer.go @@ -244,6 +244,7 @@ func (g *Gofer) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcomm UDSOpenEnabled: conf.GetHostUDS().AllowOpen(), UDSCreateEnabled: conf.GetHostUDS().AllowCreate(), ProfileEnabled: len(profileOpts) > 0, + DirectFS: conf.DirectFS, } if err := filter.Install(opts); err != nil { util.Fatalf("installing seccomp filters: %v", err) diff --git a/runsc/fsgofer/filter/config.go b/runsc/fsgofer/filter/config.go index 8eada32d7..bd718a2cc 100644 --- a/runsc/fsgofer/filter/config.go +++ b/runsc/fsgofer/filter/config.go @@ -42,13 +42,8 @@ var allowedSyscalls = seccomp.MakeSyscallRules(map[uintptr]seccomp.SyscallRule{ }, unix.SYS_EXIT: seccomp.MatchAll{}, unix.SYS_EXIT_GROUP: seccomp.MatchAll{}, - unix.SYS_FALLOCATE: seccomp.PerArg{ - seccomp.AnyValue{}, - seccomp.EqualTo(0), - }, - unix.SYS_FCHMOD: seccomp.MatchAll{}, - unix.SYS_FCHMODAT: seccomp.MatchAll{}, - unix.SYS_FCHOWNAT: seccomp.MatchAll{}, + unix.SYS_FCHMOD: seccomp.MatchAll{}, + unix.SYS_FCHOWNAT: seccomp.MatchAll{}, unix.SYS_FCNTL: seccomp.Or{ seccomp.PerArg{ seccomp.AnyValue{}, @@ -68,10 +63,8 @@ var allowedSyscalls = seccomp.MakeSyscallRules(map[uintptr]seccomp.SyscallRule{ seccomp.EqualTo(unix.F_ADD_SEALS), }, }, - unix.SYS_FSTAT: seccomp.MatchAll{}, - unix.SYS_FSTATFS: seccomp.MatchAll{}, - unix.SYS_FSYNC: seccomp.MatchAll{}, - unix.SYS_FTRUNCATE: seccomp.MatchAll{}, + unix.SYS_FSTAT: seccomp.MatchAll{}, + unix.SYS_FSYNC: seccomp.MatchAll{}, unix.SYS_FUTEX: seccomp.Or{ seccomp.PerArg{ seccomp.AnyValue{}, @@ -108,17 +101,13 @@ var allowedSyscalls = seccomp.MakeSyscallRules(map[uintptr]seccomp.SyscallRule{ seccomp.EqualTo(0), seccomp.EqualTo(0), }, - unix.SYS_GETDENTS64: seccomp.MatchAll{}, unix.SYS_GETPID: seccomp.MatchAll{}, unix.SYS_GETRANDOM: seccomp.MatchAll{}, unix.SYS_GETTID: seccomp.MatchAll{}, unix.SYS_GETTIMEOFDAY: seccomp.MatchAll{}, - unix.SYS_LINKAT: seccomp.MatchAll{}, unix.SYS_LSEEK: seccomp.MatchAll{}, unix.SYS_MADVISE: seccomp.MatchAll{}, unix.SYS_MEMFD_CREATE: seccomp.MatchAll{}, // Used by flipcall.PacketWindowAllocator.Init(). - unix.SYS_MKDIRAT: seccomp.MatchAll{}, - unix.SYS_MKNODAT: seccomp.MatchAll{}, unix.SYS_MMAP: seccomp.Or{ seccomp.PerArg{ seccomp.AnyValue{}, @@ -139,15 +128,14 @@ var allowedSyscalls = seccomp.MakeSyscallRules(map[uintptr]seccomp.SyscallRule{ seccomp.EqualTo(unix.MAP_PRIVATE | unix.MAP_ANONYMOUS | unix.MAP_FIXED), }, }, - unix.SYS_MPROTECT: seccomp.MatchAll{}, - unix.SYS_MUNMAP: seccomp.MatchAll{}, - unix.SYS_NANOSLEEP: seccomp.MatchAll{}, - unix.SYS_OPENAT: seccomp.MatchAll{}, - unix.SYS_PPOLL: seccomp.MatchAll{}, - unix.SYS_PREAD64: seccomp.MatchAll{}, - unix.SYS_PWRITE64: seccomp.MatchAll{}, - unix.SYS_READ: seccomp.MatchAll{}, - unix.SYS_READLINKAT: seccomp.MatchAll{}, + unix.SYS_MPROTECT: seccomp.MatchAll{}, + unix.SYS_MUNMAP: seccomp.MatchAll{}, + unix.SYS_NANOSLEEP: seccomp.MatchAll{}, + unix.SYS_OPENAT: seccomp.MatchAll{}, + unix.SYS_PPOLL: seccomp.MatchAll{}, + unix.SYS_PREAD64: seccomp.MatchAll{}, + unix.SYS_PWRITE64: seccomp.MatchAll{}, + unix.SYS_READ: seccomp.MatchAll{}, unix.SYS_RECVMSG: seccomp.Or{ seccomp.PerArg{ seccomp.AnyValue{}, @@ -160,7 +148,6 @@ var allowedSyscalls = seccomp.MakeSyscallRules(map[uintptr]seccomp.SyscallRule{ seccomp.EqualTo(unix.MSG_DONTWAIT | unix.MSG_TRUNC | unix.MSG_PEEK), }, }, - unix.SYS_RENAMEAT: seccomp.MatchAll{}, unix.SYS_RESTART_SYSCALL: seccomp.MatchAll{}, // May be used by the runtime during panic(). unix.SYS_RT_SIGACTION: seccomp.MatchAll{}, @@ -192,13 +179,10 @@ var allowedSyscalls = seccomp.MakeSyscallRules(map[uintptr]seccomp.SyscallRule{ seccomp.EqualTo(unix.SOCK_SEQPACKET | unix.SOCK_CLOEXEC), seccomp.EqualTo(0), }, - unix.SYS_SYMLINKAT: seccomp.MatchAll{}, unix.SYS_TGKILL: seccomp.PerArg{ seccomp.EqualTo(uint64(os.Getpid())), }, - unix.SYS_UNLINKAT: seccomp.MatchAll{}, - unix.SYS_UTIMENSAT: seccomp.MatchAll{}, - unix.SYS_WRITE: seccomp.MatchAll{}, + unix.SYS_WRITE: seccomp.MatchAll{}, }) var udsCommonSyscalls = seccomp.MakeSyscallRules(map[uintptr]seccomp.SyscallRule{ @@ -231,6 +215,28 @@ var udsCreateSyscalls = seccomp.MakeSyscallRules(map[uintptr]seccomp.SyscallRule unix.SYS_LISTEN: seccomp.MatchAll{}, }) -var xattrSyscalls = seccomp.MakeSyscallRules(map[uintptr]seccomp.SyscallRule{ - unix.SYS_FGETXATTR: seccomp.MatchAll{}, +var lisafsFilters = seccomp.MakeSyscallRules(map[uintptr]seccomp.SyscallRule{ + unix.SYS_FALLOCATE: seccomp.PerArg{ + seccomp.AnyValue{}, + seccomp.EqualTo(0), + }, + unix.SYS_FCHMODAT: seccomp.MatchAll{}, + unix.SYS_FGETXATTR: seccomp.MatchAll{}, + unix.SYS_FSTATFS: seccomp.MatchAll{}, + unix.SYS_GETDENTS64: seccomp.MatchAll{}, + unix.SYS_LINKAT: seccomp.PerArg{ + seccomp.NonNegativeFD{}, + seccomp.AnyValue{}, + seccomp.NonNegativeFD{}, + seccomp.AnyValue{}, + seccomp.EqualTo(0), + }, + unix.SYS_MKDIRAT: seccomp.MatchAll{}, + unix.SYS_MKNODAT: seccomp.MatchAll{}, + unix.SYS_READLINKAT: seccomp.MatchAll{}, + unix.SYS_RENAMEAT: seccomp.MatchAll{}, + unix.SYS_SYMLINKAT: seccomp.MatchAll{}, + unix.SYS_FTRUNCATE: seccomp.MatchAll{}, + unix.SYS_UNLINKAT: seccomp.MatchAll{}, + unix.SYS_UTIMENSAT: seccomp.MatchAll{}, }) diff --git a/runsc/fsgofer/filter/filter.go b/runsc/fsgofer/filter/filter.go index d5b856391..bafdfeb4a 100644 --- a/runsc/fsgofer/filter/filter.go +++ b/runsc/fsgofer/filter/filter.go @@ -27,6 +27,7 @@ type Options struct { UDSOpenEnabled bool UDSCreateEnabled bool ProfileEnabled bool + DirectFS bool } // Install installs seccomp filters. @@ -53,8 +54,10 @@ func Install(opt Options) error { // when not enabled. s.Merge(instrumentationFilters()) - // TODO(b/317993245): add HostFilesystem to Options. - s.Merge(xattrSyscalls) + // When DirectFS is not enabled, filters for LisaFS are installed. + if !opt.DirectFS { + s.Merge(lisafsFilters) + } return seccomp.Install(s, seccomp.DenyNewExecMappings, seccomp.DefaultProgramOptions()) }