--- sys/compat/freebsd32/freebsd32_misc.c.orig +++ sys/compat/freebsd32/freebsd32_misc.c @@ -1455,9 +1455,9 @@ static int freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control) { - struct cmsghdr *cm; + struct cmsghdr *cm, cm_out; void *data; - socklen_t clen, datalen, datalen_out, oldclen; + socklen_t clen, datalen, datalen_out; int error; caddr_t ctlbuf; int len, copylen; @@ -1483,9 +1483,10 @@ datalen_out = freebsd32_cmsg_convert(cm, data, datalen); /* - * Copy out the message header. Preserve the native - * message size in case we need to inspect the message - * contents later. + * Copy out the message header. Adjust it first to + * satisfy the 32-bit ABI's alignment requirements. + * Note that the underlying storage may still be + * resident in the socket buffer. */ copylen = sizeof(struct cmsghdr); if (len < copylen) { @@ -1493,11 +1494,11 @@ m_dispose_extcontrolm(m); goto exit; } - oldclen = cm->cmsg_len; - cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + + memcpy(&cm_out, cm, copylen); + cm_out.cmsg_len = + FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + datalen_out; - error = copyout(cm, ctlbuf, copylen); - cm->cmsg_len = oldclen; + error = copyout(&cm_out, ctlbuf, copylen); if (error != 0) goto exit;