Skip to content

Commit d949e71

Browse files
nlacassegvisor-bot
authored andcommitted
taskCopyContext should not require holding task.mu.
The primary existing user (ptrace) does not do this, and it leads to lock inversion with MemoryManager.mappingMu. PiperOrigin-RevId: 725353311
1 parent e161bec commit d949e71

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

pkg/sentry/kernel/task_usermem.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ func (cc *taskCopyContext) CopyScratchBuffer(size int) []byte {
349349
}
350350

351351
func (cc *taskCopyContext) getMemoryManager() (*mm.MemoryManager, error) {
352+
cc.t.mu.Lock()
353+
defer cc.t.mu.Unlock()
352354
tmm := cc.t.MemoryManager()
353355
if tmm == nil {
354356
return nil, linuxerr.ESRCH
@@ -360,10 +362,6 @@ func (cc *taskCopyContext) getMemoryManager() (*mm.MemoryManager, error) {
360362
}
361363

362364
// CopyInBytes implements marshal.CopyContext.CopyInBytes.
363-
//
364-
// Preconditions: Same as usermem.IO.CopyIn, plus:
365-
// - The caller must be running on the task goroutine or hold the cc.t.mu
366-
// - t's AddressSpace must be active.
367365
func (cc *taskCopyContext) CopyInBytes(addr hostarch.Addr, dst []byte) (int, error) {
368366
tmm, err := cc.getMemoryManager()
369367
if err != nil {
@@ -374,10 +372,6 @@ func (cc *taskCopyContext) CopyInBytes(addr hostarch.Addr, dst []byte) (int, err
374372
}
375373

376374
// CopyOutBytes implements marshal.CopyContext.CopyOutBytes.
377-
//
378-
// Preconditions: Same as usermem.IO.CopyOut, plus:
379-
// - The caller must be running on the task goroutine or hold the cc.t.mu
380-
// - t's AddressSpace must be active.
381375
func (cc *taskCopyContext) CopyOutBytes(addr hostarch.Addr, src []byte) (int, error) {
382376
tmm, err := cc.getMemoryManager()
383377
if err != nil {

0 commit comments

Comments
 (0)