summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/inotify.go
diff options
context:
space:
mode:
authorRahat Mahmood <rahat@google.com>2018-07-03 14:07:43 -0700
committerShentubot <shentubot@google.com>2018-07-03 14:08:51 -0700
commit34af9a61741f26be403231ec302b4e0795147906 (patch)
tree4906a74738e8d29dbb143db1967a37eb36534f15 /pkg/sentry/fs/inotify.go
parent660f1203ff1949a7b7869b801f4aa2133d30b91f (diff)
Fix data race on inotify.Watch.mask.
PiperOrigin-RevId: 203180463 Change-Id: Ief50988c1c028f81ec07a26e704d893e86985bf0
Diffstat (limited to 'pkg/sentry/fs/inotify.go')
-rw-r--r--pkg/sentry/fs/inotify.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/pkg/sentry/fs/inotify.go b/pkg/sentry/fs/inotify.go
index a87be8590..6f5e8ce5e 100644
--- a/pkg/sentry/fs/inotify.go
+++ b/pkg/sentry/fs/inotify.go
@@ -16,6 +16,7 @@ package fs
import (
"sync"
+ "sync/atomic"
"gvisor.googlesource.com/gvisor/pkg/abi/linux"
"gvisor.googlesource.com/gvisor/pkg/ilist"
@@ -279,13 +280,13 @@ func (i *Inotify) AddWatch(target *Dirent, mask uint32) int32 {
// same inode. Obtain an extra reference if necessary.
existing.Pin(target)
+ newmask := mask
if mergeMask := mask&linux.IN_MASK_ADD != 0; mergeMask {
// "Add (OR) events to watch mask for this pathname if it already
// exists (instead of replacing mask)." -- inotify(7)
- existing.mask |= mask
- } else {
- existing.mask = mask
+ newmask |= atomic.LoadUint32(&existing.mask)
}
+ atomic.StoreUint32(&existing.mask, newmask)
return existing.wd
}