diff options
author | Michael Pratt <mpratt@google.com> | 2018-06-25 16:45:31 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-06-25 16:46:29 -0700 |
commit | 4ac79312b093f2831079d0d71846747a4996d9ad (patch) | |
tree | 5452cdc0c073d26c96e0dbb872b0c3543c792848 /pkg | |
parent | 1a9917d14d66250fdc9a3781ef65df4413340a2f (diff) |
Don't read cwd or root without holding mu
PiperOrigin-RevId: 202043090
Change-Id: I3c47fb3413ca8615d50d8a0503d72fcce9b09421
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/sentry/kernel/fs_context.go | 14 |
1 files 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() |