gvisor/pkg/sentry
Jianfeng Tan 96f78e2466 unix: return zero if peer is closed
Previously, recvmsg() on a unix stream socket with its peer closed will
never return, with goroutine call trace like this:

  ...
  2  in gvisor.dev/gvisor/pkg/sentry/kernel.(*Task).block
     at pkg/sentry/kernel/task_block.go:124
  3  in gvisor.dev/gvisor/pkg/sentry/kernel.(*Task).BlockWithDeadline
     at pkg/sentry/kernel/task_block.go:69
  4  in gvisor.dev/gvisor/pkg/sentry/socket/unix.(*SocketOperations).RecvMsg
     at pkg/sentry/socket/unix/unix.go:612
  5  in gvisor.dev/gvisor/pkg/sentry/syscalls/linux.recvFrom
     at pkg/sentry/syscalls/linux/sys_socket.go:885
  6  in gvisor.dev/gvisor/pkg/sentry/syscalls/linux.RecvFrom
     at pkg/sentry/syscalls/linux/sys_socket.go:910
  ...

The issue is caused by that ErrClosedForReceive returned by
unix/transport.queue is turned into nil in
unix.(*EndpointReader).ReadToBlocks():

  err.ToError()

As a result, in unix.(*SocketOperations).RecvMsg():

  n == 0 and err == nil

We shall differentiate it from another case - no data to read where
ErrWouldBlock shall be returned; and return 0 immediately.

Fixes: #734

Reported-by: chenglang.hy <chenglang.hy@antfin.com>
Signed-off-by: Jianfeng Tan <henry.tjf@antfin.com>
2019-08-22 15:25:38 +00:00
..
arch Add ARM64 support to pkg/sentry/loader 2019-07-21 19:30:18 -07:00
context Preallocate auth.NewAnonymousCredentials() in contexttest.TestContext. 2019-06-20 13:36:14 -07:00
control Remove kernel.mounts. 2019-08-02 11:23:11 -07:00
device Update canonical repository. 2019-06-13 16:50:15 -07:00
fs Replace uinptr with int64 when returning lengths 2019-08-14 16:05:56 -07:00
fsimpl procfs: Migrate seqfile implementations. 2019-08-16 17:36:42 -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 netstack: Don't start endpoint goroutines too soon on restore. 2019-08-08 12:33:11 -07:00
kernel netstack: Don't start endpoint goroutines too soon on restore. 2019-08-08 12:33:11 -07:00
limits Update canonical repository. 2019-06-13 16:50:15 -07:00
loader Add feature to launch Sentry from an open host FD. 2019-07-30 11:20:40 -07:00
memmap Fix various spelling issues in the documentation 2019-06-27 14:25:50 -07:00
mm procfs: Migrate seqfile implementations. 2019-08-16 17:36:42 -07:00
pgalloc Cache pages in CachingInodeOperations.Read when memory evictions are delayed. 2019-07-30 20:32:29 -07:00
platform ptrace: detect if a stub process exited unexpectedly 2019-08-16 17:33:28 -07:00
safemem ext: vfs.FileDescriptionImpl and vfs.FilesystemImpl implementations. 2019-08-07 14:23:42 -07:00
sighandling Update canonical repository. 2019-06-13 16:50:15 -07:00
socket unix: return zero if peer is closed 2019-08-22 15:25:38 +00:00
state netstack: Don't start endpoint goroutines too soon on restore. 2019-08-08 12:33:11 -07:00
strace netstack: disconnect an unix socket only if the address family is AF_UNSPEC 2019-08-16 19:32:14 -07:00
syscalls Document RWF_HIPRI not implemented for preadv2/pwritev2. 2019-08-19 14:07:44 -07:00
time build: add nogo for static validation 2019-07-09 16:44:06 -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
vfs vfs: Remove vfs.DefaultDirectoryFD from embedding vfs.DefaultFD. 2019-08-16 10:20:11 -07:00
watchdog Add list of stuck tasks to panic message 2019-06-21 12:46:53 -07:00
BUILD Remove license comments 2019-01-31 11:12:53 -08:00