Systrap: Wrap initSysmsgThreadPriority in sync.Once.

As `sysmsgThreadPriority` is used as a variable in Systrap's seccomp-bpf
filter, `systrapSeccomp.Variables` is called concurrently for each variant
of the seccomp config that uses Systrap.
This causes `initSysmsgThreadPriority` to be called concurrently, which
means racing writes to `sysmsgThreadPriority`.

This change wraps `initSysmsgThreadPriority` in `sync.Once` to ensure it is
only modified once.

PiperOrigin-RevId: 584107041
This commit is contained in:
Etienne Perot
2023-11-20 13:04:08 -08:00
committed by gVisor bot
parent 704543b8f3
commit 9c6f50d59e
+14 -7
View File
@@ -948,15 +948,22 @@ func (s *subprocess) PullFullState(c *context, ac *arch.Context64) error {
return nil
}
var sysmsgThreadPriority int
var (
sysmsgThreadPriorityOnce sync.Once
sysmsgThreadPriority int
)
// initSysmsgThreadPriority looks at the current priority of the process
// and updates `sysmsgThreadPriority` accordingly.
func initSysmsgThreadPriority() {
prio, err := unix.Getpriority(unix.PRIO_PROCESS, 0)
if err != nil {
panic("unable to get current scheduling priority")
}
// Sysmsg threads are executed with a priority one lower than the Sentry.
sysmsgThreadPriority = 20 - prio + 1
sysmsgThreadPriorityOnce.Do(func() {
prio, err := unix.Getpriority(unix.PRIO_PROCESS, 0)
if err != nil {
panic("unable to get current scheduling priority")
}
// Sysmsg threads are executed with a priority one lower than the Sentry.
sysmsgThreadPriority = 20 - prio + 1
})
}
// createSysmsgThread creates a new sysmsg thread.