diff options
author | Jamie Liu <jamieliu@google.com> | 2020-11-12 18:20:30 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-11-12 18:22:40 -0800 |
commit | 62db1fad2cb7d2249720e157aa79c84b7531a2e9 (patch) | |
tree | 2485dc460f965096836f9ccfe128e81f5c82f576 /pkg/sentry/kernel/task_log.go | |
parent | f01f623879e87412e4d2340d37ff4d0fccdb6c2b (diff) |
Fix misuses of kernel.Task as context.Context.
kernel.Task can only be used as context.Context by that Task's task goroutine.
This is violated in at least two places:
- In any case where one thread accesses the /proc/[tid] of any other thread,
passing the kernel.Task for [tid] as the context.Context is incorrect.
- Task.rebuildTraceContext() may be called by Kernel.RebuildTraceContexts()
outside the scope of any task goroutine.
Fix these (as well as a data race on Task.traceContext discovered during the
course of finding the latter).
PiperOrigin-RevId: 342174404
Diffstat (limited to 'pkg/sentry/kernel/task_log.go')
-rw-r--r-- | pkg/sentry/kernel/task_log.go | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/pkg/sentry/kernel/task_log.go b/pkg/sentry/kernel/task_log.go index 7591eaace..c70e5e6ce 100644 --- a/pkg/sentry/kernel/task_log.go +++ b/pkg/sentry/kernel/task_log.go @@ -19,6 +19,7 @@ import ( "runtime/trace" "sort" + "gvisor.dev/gvisor/pkg/context" "gvisor.dev/gvisor/pkg/log" "gvisor.dev/gvisor/pkg/usermem" ) @@ -215,7 +216,7 @@ func (t *Task) rebuildTraceContext(tid ThreadID) { // arbitrarily large (in general it won't be, especially for cases // where we're collecting a brief profile), so using the TID is a // reasonable compromise in this case. - t.traceContext, t.traceTask = trace.NewTask(t, fmt.Sprintf("tid:%d", tid)) + t.traceContext, t.traceTask = trace.NewTask(context.Background(), fmt.Sprintf("tid:%d", tid)) } // traceCloneEvent is called when a new task is spawned. |