From 358eb52a76ebd41baf52972f901af0ff398e131b Mon Sep 17 00:00:00 2001 From: Ian Gudger Date: Fri, 19 Apr 2019 16:15:37 -0700 Subject: Add support for the MSG_TRUNC msghdr flag. The MSG_TRUNC flag is set in the msghdr when a message is truncated. Fixes google/gvisor#200 PiperOrigin-RevId: 244440486 Change-Id: I03c7d5e7f5935c0c6b8d69b012db1780ac5b8456 --- pkg/sentry/syscalls/linux/sys_socket.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'pkg/sentry/syscalls') diff --git a/pkg/sentry/syscalls/linux/sys_socket.go b/pkg/sentry/syscalls/linux/sys_socket.go index 49e6f4aeb..30ccc3f66 100644 --- a/pkg/sentry/syscalls/linux/sys_socket.go +++ b/pkg/sentry/syscalls/linux/sys_socket.go @@ -742,17 +742,15 @@ func recvSingleMsg(t *kernel.Task, s socket.Socket, msgPtr usermem.Addr, flags i // Fast path when no control message nor name buffers are provided. if msg.ControlLen == 0 && msg.NameLen == 0 { - n, _, _, cms, err := s.RecvMsg(t, dst, int(flags), haveDeadline, deadline, false, 0) + n, mflags, _, _, cms, err := s.RecvMsg(t, dst, int(flags), haveDeadline, deadline, false, 0) if err != nil { return 0, syserror.ConvertIntr(err.ToError(), kernel.ERESTARTSYS) } cms.Unix.Release() - if msg.Flags != 0 { + if int(msg.Flags) != mflags { // Copy out the flags to the caller. - // - // TODO: Plumb through actual flags. - if _, err := t.CopyOut(msgPtr+flagsOffset, int32(0)); err != nil { + if _, err := t.CopyOut(msgPtr+flagsOffset, int32(mflags)); err != nil { return 0, err } } @@ -763,7 +761,7 @@ func recvSingleMsg(t *kernel.Task, s socket.Socket, msgPtr usermem.Addr, flags i if msg.ControlLen > maxControlLen { return 0, syscall.ENOBUFS } - n, sender, senderLen, cms, e := s.RecvMsg(t, dst, int(flags), haveDeadline, deadline, msg.NameLen != 0, msg.ControlLen) + n, mflags, sender, senderLen, cms, e := s.RecvMsg(t, dst, int(flags), haveDeadline, deadline, msg.NameLen != 0, msg.ControlLen) if e != nil { return 0, syserror.ConvertIntr(e.ToError(), kernel.ERESTARTSYS) } @@ -802,9 +800,7 @@ func recvSingleMsg(t *kernel.Task, s socket.Socket, msgPtr usermem.Addr, flags i } // Copy out the flags to the caller. - // - // TODO: Plumb through actual flags. - if _, err := t.CopyOut(msgPtr+flagsOffset, int32(0)); err != nil { + if _, err := t.CopyOut(msgPtr+flagsOffset, int32(mflags)); err != nil { return 0, err } @@ -856,7 +852,7 @@ func recvFrom(t *kernel.Task, fd kdefs.FD, bufPtr usermem.Addr, bufLen uint64, f flags |= linux.MSG_DONTWAIT } - n, sender, senderLen, cm, e := s.RecvMsg(t, dst, int(flags), haveDeadline, deadline, nameLenPtr != 0, 0) + n, _, sender, senderLen, cm, e := s.RecvMsg(t, dst, int(flags), haveDeadline, deadline, nameLenPtr != 0, 0) cm.Unix.Release() if e != nil { return 0, syserror.ConvertIntr(e.ToError(), kernel.ERESTARTSYS) -- cgit v1.2.3