From ba828233b9e934992ac024232e5018ce9971f334 Mon Sep 17 00:00:00 2001 From: Ian Gudger Date: Thu, 21 Mar 2019 13:18:00 -0700 Subject: Clear msghdr flags on successful recvmsg. .net sets these flags to -1 and then uses their result, especting it to be zero. Does not set actual flags (e.g. MSG_TRUNC), but setting to zero is more correct than what we did before. PiperOrigin-RevId: 239657951 Change-Id: I89c5f84bc9b94a2cd8ff84e8ecfea09e01142030 --- pkg/sentry/syscalls/linux/sys_socket.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'pkg/sentry/syscalls') diff --git a/pkg/sentry/syscalls/linux/sys_socket.go b/pkg/sentry/syscalls/linux/sys_socket.go index 1513f28e7..564357bac 100644 --- a/pkg/sentry/syscalls/linux/sys_socket.go +++ b/pkg/sentry/syscalls/linux/sys_socket.go @@ -57,6 +57,10 @@ const nameLenOffset = 8 // to the ControlLen field. const controlLenOffset = 40 +// flagsOffset is the offset form the start of the MessageHeader64 struct +// to the Flags field. +const flagsOffset = 48 + // messageHeader64Len is the length of a MessageHeader64 struct. var messageHeader64Len = uint64(binary.Size(MessageHeader64{})) @@ -743,6 +747,16 @@ func recvSingleMsg(t *kernel.Task, s socket.Socket, msgPtr usermem.Addr, flags i return 0, syserror.ConvertIntr(err.ToError(), kernel.ERESTARTSYS) } cms.Unix.Release() + + if msg.Flags != 0 { + // Copy out the flags to the caller. + // + // TODO: Plumb through actual flags. + if _, err := t.CopyOut(msgPtr+flagsOffset, int32(0)); err != nil { + return 0, err + } + } + return uintptr(n), nil } @@ -787,6 +801,13 @@ 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 { + return 0, err + } + return uintptr(n), nil } -- cgit v1.2.3