From 81ecd8b6eab7457b331762626f8c210fec3504e6 Mon Sep 17 00:00:00 2001 From: Ian Gudger Date: Mon, 29 Apr 2019 21:20:05 -0700 Subject: Implement the MSG_CTRUNC msghdr flag for Unix sockets. Updates google/gvisor#206 PiperOrigin-RevId: 245880573 Change-Id: Ifa715e98d47f64b8a32b04ae9378d6cd6bd4025e --- pkg/sentry/syscalls/linux/sys_socket.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'pkg/sentry/syscalls/linux') diff --git a/pkg/sentry/syscalls/linux/sys_socket.go b/pkg/sentry/syscalls/linux/sys_socket.go index 69862f110..8f4dbf3bc 100644 --- a/pkg/sentry/syscalls/linux/sys_socket.go +++ b/pkg/sentry/syscalls/linux/sys_socket.go @@ -746,7 +746,10 @@ func recvSingleMsg(t *kernel.Task, s socket.Socket, msgPtr usermem.Addr, flags i if err != nil { return 0, syserror.ConvertIntr(err.ToError(), kernel.ERESTARTSYS) } - cms.Unix.Release() + if !cms.Unix.Empty() { + mflags |= linux.MSG_CTRUNC + cms.Unix.Release() + } if int(msg.Flags) != mflags { // Copy out the flags to the caller. @@ -771,7 +774,7 @@ func recvSingleMsg(t *kernel.Task, s socket.Socket, msgPtr usermem.Addr, flags i if cr, ok := s.(transport.Credentialer); ok && cr.Passcred() { creds, _ := cms.Unix.Credentials.(control.SCMCredentials) - controlData = control.PackCredentials(t, creds, controlData) + controlData, mflags = control.PackCredentials(t, creds, controlData, mflags) } if cms.IP.HasTimestamp { @@ -779,7 +782,7 @@ func recvSingleMsg(t *kernel.Task, s socket.Socket, msgPtr usermem.Addr, flags i } if cms.Unix.Rights != nil { - controlData = control.PackRights(t, cms.Unix.Rights.(control.SCMRights), flags&linux.MSG_CMSG_CLOEXEC != 0, controlData) + controlData, mflags = control.PackRights(t, cms.Unix.Rights.(control.SCMRights), flags&linux.MSG_CMSG_CLOEXEC != 0, controlData, mflags) } // Copy the address to the caller. -- cgit v1.2.3