From d5f20209cc34a5357486a2f495bfe30b5d6e2056 Mon Sep 17 00:00:00 2001 From: Tiwei Bie Date: Tue, 1 Sep 2020 16:01:22 +0800 Subject: fsimpl/host: fix the order of removing FD notifier FD notifier should be removed before we close the FD, otherwise there will be race condition that another FD which has the same value is opened and added before the existing FD notifier is removed. Fixes: #3823 Signed-off-by: Tiwei Bie --- pkg/sentry/fsimpl/host/socket.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pkg/sentry') diff --git a/pkg/sentry/fsimpl/host/socket.go b/pkg/sentry/fsimpl/host/socket.go index 131145b85..8a447e29f 100644 --- a/pkg/sentry/fsimpl/host/socket.go +++ b/pkg/sentry/fsimpl/host/socket.go @@ -348,10 +348,10 @@ func (e *SCMConnectedEndpoint) Init() error { func (e *SCMConnectedEndpoint) Release(ctx context.Context) { e.DecRef(func() { e.mu.Lock() + fdnotifier.RemoveFD(int32(e.fd)) if err := syscall.Close(e.fd); err != nil { log.Warningf("Failed to close host fd %d: %v", err) } - fdnotifier.RemoveFD(int32(e.fd)) e.destroyLocked() e.mu.Unlock() }) -- cgit v1.2.3