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

136 lines
3.5 KiB
Python

load("//tools:defs.bzl", "go_library", "go_test")
load("//tools/go_generics:defs.bzl", "go_template_instance")
package(
default_applicable_licenses = ["//:license"],
licenses = ["notice"],
)
go_template_instance(
name = "context_list",
out = "context_list.go",
package = "systrap",
prefix = "context",
template = "//pkg/ilist:generic_list",
types = {
"Element": "*sharedContext",
"Linker": "*sharedContext",
},
)
go_template_instance(
name = "subprocess_refs",
out = "subprocess_refs.go",
package = "systrap",
prefix = "subprocess",
template = "//pkg/refs:refs_template",
types = {
"T": "subprocess",
},
)
go_library(
name = "systrap",
srcs = [
"context_list.go",
"context_queue.go",
"context_queue_unsafe.go",
"filters.go",
"filters_amd64.go",
"filters_arm64.go",
"lib_amd64.s",
"lib_arm64.s",
"metrics.go",
"shared_context.go",
"shared_context_norace.go",
"shared_context_race.go",
"stub_amd64.s",
"stub_arm64.s",
"stub_defs.go",
"stub_unsafe.go",
"subprocess.go",
"subprocess_amd64.go",
"subprocess_arm64.go",
"subprocess_linux.go",
"subprocess_linux_unsafe.go",
"subprocess_pool.go",
"subprocess_refs.go",
"subprocess_unsafe.go",
"syscall_thread.go",
"syscall_thread_amd64.go",
"syscall_thread_arm64.go",
"syscall_thread_defs.go",
"syscall_thread_unsafe.go",
"sysmsg_thread.go",
"sysmsg_thread_amd64.go",
"sysmsg_thread_arm64.go",
"sysmsg_thread_unsafe.go",
"systrap.go",
"systrap_amd64.go",
"systrap_arm64.go",
"systrap_arm64_unsafe.go",
"systrap_profiling.go",
"systrap_profiling_fake.go",
"systrap_unsafe.go",
],
visibility = ["//:sandbox"],
deps = [
"//pkg/abi/linux",
"//pkg/atomicbitops",
"//pkg/bpf",
"//pkg/context",
"//pkg/cpuid",
"//pkg/fd",
"//pkg/hostarch",
"//pkg/hostsyscall",
"//pkg/log",
"//pkg/memutil",
"//pkg/metric",
"//pkg/pool",
"//pkg/rand",
"//pkg/refs",
"//pkg/safecopy",
"//pkg/seccomp",
"//pkg/seccomp/precompiledseccomp",
"//pkg/sentry/arch",
"//pkg/sentry/hostmm",
"//pkg/sentry/memmap",
"//pkg/sentry/pgalloc",
"//pkg/sentry/platform",
"//pkg/sentry/platform/interrupt",
"//pkg/sentry/platform/systrap/sysmsg",
"//pkg/sentry/platform/systrap/usertrap",
"//pkg/sentry/usage",
"//pkg/sighandling",
"//pkg/sync",
"//pkg/syncevent",
"@org_golang_x_sys//unix:go_default_library",
],
)
go_test(
name = "systrap_test",
size = "small",
srcs = [
"context_queue_test.go",
"shared_context_test.go",
"systrap_test.go",
],
library = ":systrap",
deps = [
"//pkg/context",
"//pkg/cpuid",
"//pkg/hostarch",
"//pkg/safemem",
"//pkg/sentry/arch",
"//pkg/sentry/memmap",
"//pkg/sentry/pgalloc",
"//pkg/sentry/platform",
"//pkg/sentry/platform/systrap/sysmsg",
"//pkg/sentry/platform/systrap/testutil",
"//pkg/sentry/usage",
"//pkg/usermem",
"@org_golang_x_sys//unix:go_default_library",
],
)