diff options
author | Bhasker Hariharan <bhaskerh@google.com> | 2019-07-17 13:55:32 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-07-17 13:56:49 -0700 |
commit | 542fbd01a7ed38baca941f88c0b254adef691188 (patch) | |
tree | 6353bd87df4e5215bc8cc1ed73c6db05b77c7dcb /pkg/sentry/kernel/fd_table.go | |
parent | 9f1189130ed8c9172700a76fd5796b7319fbb8b9 (diff) |
Fix race in FDTable.GetFDs().
PiperOrigin-RevId: 258635459
Diffstat (limited to 'pkg/sentry/kernel/fd_table.go')
-rw-r--r-- | pkg/sentry/kernel/fd_table.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/pkg/sentry/kernel/fd_table.go b/pkg/sentry/kernel/fd_table.go index 1f3a57dc1..cc3f43a45 100644 --- a/pkg/sentry/kernel/fd_table.go +++ b/pkg/sentry/kernel/fd_table.go @@ -81,7 +81,9 @@ type FDTable struct { // mu protects below. mu sync.Mutex `state:"nosave"` - // used contains the number of non-nil entries. + // used contains the number of non-nil entries. It must be accessed + // atomically. It may be read atomically without holding mu (but not + // written). used int32 // descriptorTable holds descriptors. @@ -317,7 +319,7 @@ func (f *FDTable) Get(fd int32) (*fs.File, FDFlags) { // GetFDs returns a list of valid fds. func (f *FDTable) GetFDs() []int32 { - fds := make([]int32, 0, f.used) + fds := make([]int32, 0, int(atomic.LoadInt32(&f.used))) f.forEach(func(fd int32, file *fs.File, flags FDFlags) { fds = append(fds, fd) }) |