Files
Konstantin BogomolovandgVisor bot cb3de545ca Close exposed race window in stub ThreadID setting.
github.com/google/gvisor/pull/14531 exposed a race window with stub threads
setting ThreadID and the sentry reading it. If the sentry attempted to interrupt
a stub that in the process of switching a context back, it could have read
an invalid thread ID along with a context state that indicated it was still
being worked on. This window has existed before #14531, but was relatively
benign; with that CL, the window became punishable by subprocess death.

The (mostly generated) test seems to reliably test the race-window in case
things get reordered in some future refactor.

Fixes #14531.

PiperOrigin-RevId: 974868738
2026-09-01 21:01:37 -07:00

27 lines
916 B
Go

// Copyright 2026 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build amd64
// +build amd64
// Package testutil provides common test utilities for systrap.
package testutil
// UserCode is the user program: for (;;) getpid();
var UserCode = []byte{
0x48, 0xc7, 0xc0, 0x27, 0x00, 0x00, 0x00, // movq $SYS_getpid, %rax
0x0f, 0x05, // syscall
0xeb, 0xf5, // jmp back to movq
}