summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorBrian Geffon <bgeffon@google.com>2018-06-19 17:28:19 -0700
committerShentubot <shentubot@google.com>2018-06-19 17:29:11 -0700
commitdb66e383c33228c43efbe16ad3b14ae9833879dc (patch)
treee2d13d1e28d4d0dec5d03b0dc6b27e3cee75aa16 /pkg
parent3ebd0e35f43d9ca282886aabce52fbb7fc7e1fc5 (diff)
Epsocket has incorrect recv(2) behavior after SHUT_RD.
After shutdown(SHUT_RD) calls to recv /w MSG_DONTWAIT or with O_NONBLOCK should result in a EAGAIN and not 0. Blocking sockets should return 0 as they would have otherwise blocked indefinitely. PiperOrigin-RevId: 201271123 Change-Id: If589b69c17fa5b9ff05bcf9e44024da9588c8876
Diffstat (limited to 'pkg')
-rw-r--r--pkg/sentry/socket/epsocket/epsocket.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/pkg/sentry/socket/epsocket/epsocket.go b/pkg/sentry/socket/epsocket/epsocket.go
index 9ff9af0bc..a1bb265c0 100644
--- a/pkg/sentry/socket/epsocket/epsocket.go
+++ b/pkg/sentry/socket/epsocket/epsocket.go
@@ -952,6 +952,12 @@ func (s *SocketOperations) RecvMsg(t *kernel.Task, dst usermem.IOSequence, flags
senderRequested = false
}
n, senderAddr, senderAddrLen, controlMessages, err = s.nonBlockingRead(t, dst, peek, trunc, senderRequested)
+
+ if err == syserr.ErrClosedForReceive && flags&linux.MSG_DONTWAIT != 0 {
+ // In this situation we should return EAGAIN.
+ return 0, nil, 0, socket.ControlMessages{}, syserr.ErrTryAgain
+ }
+
if err != syserr.ErrWouldBlock || flags&linux.MSG_DONTWAIT != 0 {
return
}