From 4ac79312b093f2831079d0d71846747a4996d9ad Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Mon, 25 Jun 2018 16:45:31 -0700 Subject: Don't read cwd or root without holding mu PiperOrigin-RevId: 202043090 Change-Id: I3c47fb3413ca8615d50d8a0503d72fcce9b09421 --- pkg/sentry/kernel/fs_context.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/sentry/kernel/fs_context.go b/pkg/sentry/kernel/fs_context.go index 9aa6fa951..d1ca9c09d 100644 --- a/pkg/sentry/kernel/fs_context.go +++ b/pkg/sentry/kernel/fs_context.go @@ -114,11 +114,14 @@ func (f *FSContext) SetWorkingDirectory(d *fs.Dirent) { if d == nil { panic("FSContext.SetWorkingDirectory called with nil dirent") } + + f.mu.Lock() + defer f.mu.Unlock() + if f.cwd == nil { panic(fmt.Sprintf("FSContext.SetWorkingDirectory(%v)) called after destroy", d)) } - f.mu.Lock() - defer f.mu.Unlock() + old := f.cwd f.cwd = d d.IncRef() @@ -144,11 +147,14 @@ func (f *FSContext) SetRootDirectory(d *fs.Dirent) { if d == nil { panic("FSContext.SetRootDirectory called with nil dirent") } + + f.mu.Lock() + defer f.mu.Unlock() + if f.root == nil { panic(fmt.Sprintf("FSContext.SetRootDirectory(%v)) called after destroy", d)) } - f.mu.Lock() - defer f.mu.Unlock() + old := f.root f.root = d d.IncRef() -- cgit v1.2.3