gvisor/pkg/sentry
Ian Gudger 0a5ee6f7b2 Fix deadlock in fasync.
The deadlock can occur when both ends of a connected Unix socket which has
FIOASYNC enabled on at least one end are closed at the same time. One end
notifies that it is closing, calling (*waiter.Queue).Notify which takes
waiter.Queue.mu (as a read lock) and then calls (*FileAsync).Callback, which
takes FileAsync.mu. The other end tries to unregister for notifications by
calling (*FileAsync).Unregister, which takes FileAsync.mu and calls
(*waiter.Queue).EventUnregister which takes waiter.Queue.mu.

This is fixed by moving the calls to waiter.Waitable.EventRegister and
waiter.Waitable.EventUnregister outside of the protection of any mutex used
in (*FileAsync).Callback.

The new test is related, but does not cover this particular situation.

Also fix a data race on FileAsync.e.Callback. (*FileAsync).Callback checked
FileAsync.e.Callback under the protection of FileAsync.mu, but the waiter
calling (*FileAsync).Callback could not and did not. This is fixed by making
FileAsync.e.Callback immutable before passing it to the waiter for the first
time.

Fixes #346

PiperOrigin-RevId: 253138340
2019-06-13 17:26:22 -07:00
..
arch Update canonical repository. 2019-06-13 16:50:15 -07:00
context Update canonical repository. 2019-06-13 16:50:15 -07:00
control Update canonical repository. 2019-06-13 16:50:15 -07:00
device Update canonical repository. 2019-06-13 16:50:15 -07:00
fs Update canonical repository. 2019-06-13 16:50:15 -07:00
hostcpu Update canonical repository. 2019-06-13 16:50:15 -07:00
hostmm Update canonical repository. 2019-06-13 16:50:15 -07:00
inet Update canonical repository. 2019-06-13 16:50:15 -07:00
kernel Fix deadlock in fasync. 2019-06-13 17:26:22 -07:00
limits Update canonical repository. 2019-06-13 16:50:15 -07:00
loader Update canonical repository. 2019-06-13 16:50:15 -07:00
memmap Update canonical repository. 2019-06-13 16:50:15 -07:00
mm Update canonical repository. 2019-06-13 16:50:15 -07:00
pgalloc Update canonical repository. 2019-06-13 16:50:15 -07:00
platform Update canonical repository. 2019-06-13 16:50:15 -07:00
safemem Update canonical repository. 2019-06-13 16:50:15 -07:00
sighandling Update canonical repository. 2019-06-13 16:50:15 -07:00
socket Implement getsockopt() SO_DOMAIN, SO_PROTOCOL and SO_TYPE. 2019-06-13 17:24:51 -07:00
state Update canonical repository. 2019-06-13 16:50:15 -07:00
strace Update canonical repository. 2019-06-13 16:50:15 -07:00
syscalls Implement getsockopt() SO_DOMAIN, SO_PROTOCOL and SO_TYPE. 2019-06-13 17:24:51 -07:00
time Update canonical repository. 2019-06-13 16:50:15 -07:00
unimpl Update canonical repository. 2019-06-13 16:50:15 -07:00
uniqueid Update canonical repository. 2019-06-13 16:50:15 -07:00
usage Update canonical repository. 2019-06-13 16:50:15 -07:00
usermem Update canonical repository. 2019-06-13 16:50:15 -07:00
watchdog Update canonical repository. 2019-06-13 16:50:15 -07:00
BUILD Remove license comments 2019-01-31 11:12:53 -08:00