From 34af9a61741f26be403231ec302b4e0795147906 Mon Sep 17 00:00:00 2001 From: Rahat Mahmood Date: Tue, 3 Jul 2018 14:07:43 -0700 Subject: Fix data race on inotify.Watch.mask. PiperOrigin-RevId: 203180463 Change-Id: Ief50988c1c028f81ec07a26e704d893e86985bf0 --- pkg/sentry/fs/inotify.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'pkg/sentry/fs/inotify.go') 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 } -- cgit v1.2.3