Skip to content

Commit 33d4ca3

Browse files
prattmicgvisor-bot
authored andcommitted
Allow sched_getaffinity in syscall filters
Go 1.25's automatic GOMAXPROCS background updates will periodically call sched_getaffinity (for total CPU count) and pread64 (for cgroup quota limit). The latter is already allowed by the filters, but the former is not. In the sentry, the explicit runtime.GOMAXPROCS call at startup disables the runtime's automatic updates. In theory this makes the filter unnecessary, however the runtime only actually guarantees it won't change the value of GOMAXPROCS after runtime.GOMAXPROCS. It does not guarantee that a concurrent update run won't call the syscalls after runtime.GOMAXPROCS returns (when this happens, the runtime by definition must later discard any change it finds). That means it is theoretically possible for a background sched_getaffinity call to occur after filters are installed. This lack of guarantee makes the feature difficult to work with, so I intend to change the runtime to provide a stronger guarantee, but until then I don't think it hurts to allow this system call. I haven't actually seen a failure due to a concurrent update yet, this is precautionary. Note that the gofer does not explicitly set GOMAXPROCS, so it will continue to need the filter unless that changes. PiperOrigin-RevId: 764381364
1 parent 96ca35d commit 33d4ca3

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

runsc/boot/filter/config/config_main.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,22 @@ var allowedSyscalls = seccomp.MakeSyscallRules(map[uintptr]seccomp.SyscallRule{
253253
unix.SYS_RT_SIGACTION: seccomp.MatchAll{},
254254
unix.SYS_RT_SIGPROCMASK: seccomp.MatchAll{},
255255
unix.SYS_RT_SIGRETURN: seccomp.MatchAll{},
256-
unix.SYS_SCHED_YIELD: seccomp.MatchAll{},
256+
// TODO(go.dev/issue/73193): sched_getaffinity is used by Go's
257+
// automatic GOMAXPROCS updater. The runtime.GOMAXPROCS call in
258+
// boot.New explicitly disables this updater. Currently
259+
// runtime.GOMAXPROCS guarantees that the updater will not change
260+
// GOMAXPROCS after runtime.GOMAXPROCS return. However, it does not
261+
// guarantee that a concurrent update run will not perform the system
262+
// call after runtime.GOMAXPROCS returns. So there is a tiny probability
263+
// that we will manage to install filters before such a concurrent run
264+
// calls sched_getaffinity.
265+
//
266+
// The Go runtime should make a stronger guarantee. Until then, allow the
267+
// syscall.
268+
unix.SYS_SCHED_GETAFFINITY: seccomp.PerArg{
269+
seccomp.EqualTo(0),
270+
},
271+
unix.SYS_SCHED_YIELD: seccomp.MatchAll{},
257272
unix.SYS_SENDMSG: seccomp.PerArg{
258273
seccomp.AnyValue{},
259274
seccomp.AnyValue{},

runsc/fsgofer/filter/config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ var allowedSyscalls = seccomp.MakeSyscallRules(map[uintptr]seccomp.SyscallRule{
162162
unix.SYS_RT_SIGACTION: seccomp.MatchAll{},
163163
unix.SYS_RT_SIGPROCMASK: seccomp.MatchAll{},
164164
unix.SYS_RT_SIGRETURN: seccomp.MatchAll{},
165-
unix.SYS_SCHED_YIELD: seccomp.MatchAll{},
165+
// Used by Go's automatic GOMAXPROCS updater.
166+
unix.SYS_SCHED_GETAFFINITY: seccomp.PerArg{
167+
seccomp.EqualTo(0),
168+
},
169+
unix.SYS_SCHED_YIELD: seccomp.MatchAll{},
166170
unix.SYS_SENDMSG: seccomp.Or{
167171
// Used by fdchannel.Endpoint.SendFD().
168172
seccomp.PerArg{

0 commit comments

Comments
 (0)