From ff32cb8b2555fa1384e220e917588b056fd0d0d6 Mon Sep 17 00:00:00 2001 From: Nicolas Lacasse Date: Sat, 18 Feb 2023 13:09:05 -0800 Subject: [PATCH] Hold t.mu while accessing t.image. We copy t.image with t.mu held, to avoid holding the lock while calling t.image.Fork. PiperOrigin-RevId: 510698814 --- pkg/sentry/kernel/task_clone.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/sentry/kernel/task_clone.go b/pkg/sentry/kernel/task_clone.go index 70540f44b..3fe8ff193 100644 --- a/pkg/sentry/kernel/task_clone.go +++ b/pkg/sentry/kernel/task_clone.go @@ -136,7 +136,12 @@ func (t *Task) Clone(args *linux.CloneArgs) (ThreadID, *SyscallControl, error) { }) } - image, err := t.image.Fork(t, t.k, args.Flags&linux.CLONE_VM != 0) + // We must hold t.mu to access t.image, but want to avoid holding the lock + // during Fork() call, so we make a copy. + t.mu.Lock() + curImage := t.image + t.mu.Unlock() + image, err := curImage.Fork(t, t.k, args.Flags&linux.CLONE_VM != 0) if err != nil { return 0, nil, err }