From e2d79480f57d96ea90bb73b241f248573c2a33fc Mon Sep 17 00:00:00 2001 From: Nicolas Lacasse Date: Thu, 13 Sep 2018 09:49:17 -0700 Subject: initArgs must hold a reference on the Root if it is not nil. The contract in ExecArgs says that a reference on ExecArgs.Root must be held for the lifetime of the struct, but the caller is free to drop the ref after that. As a result, proc.Exec must take an additional ref on Root when it constructs the CreateProcessArgs, since that holds a pointer to Root as well. That ref is dropped in CreateProcess. PiperOrigin-RevId: 212828348 Change-Id: I7f44a612f337ff51a02b873b8a845d3119408707 --- pkg/sentry/control/proc.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'pkg/sentry') diff --git a/pkg/sentry/control/proc.go b/pkg/sentry/control/proc.go index 1623ed19a..19bc76f5c 100644 --- a/pkg/sentry/control/proc.go +++ b/pkg/sentry/control/proc.go @@ -132,6 +132,11 @@ func (proc *Proc) execAsync(args *ExecArgs) (*kernel.ThreadGroup, error) { IPCNamespace: proc.Kernel.RootIPCNamespace(), AbstractSocketNamespace: proc.Kernel.RootAbstractSocketNamespace(), } + if initArgs.Root != nil { + // initArgs must hold a reference on Root. This ref is dropped + // in CreateProcess. + initArgs.Root.IncRef() + } ctx := initArgs.NewContext(proc.Kernel) if initArgs.Filename == "" { -- cgit v1.2.3