Bug 222039 - Incorrect 32-bit emulation of SCM_BINTIME and SCM_TIMESTAMP
Summary: Incorrect 32-bit emulation of SCM_BINTIME and SCM_TIMESTAMP
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: amd64 Any
: --- Affects Some People
Assignee: Maxim Sobolev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-09-04 00:21 UTC by Alan Somers
Modified: 2018-09-17 17:22 UTC (History)
3 users (show)

See Also:
asomers: mfc-stable11?


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Somers freebsd_committer 2017-09-04 00:21:24 UTC
I have seen two examples of programs that use SCM_TIMESTAMP and/or SCM_BINTIME that work correctly on amd64 or i386, but fail when the i386 binaries are executed on an amd64 kernel.  The easiest way to reproduce this problem is:

i386_host $ cd /usr/src/tools/regression/sockets/unix_cmsg
i386_host $ make
i386_host $ ./unix_cmsg
i386_host $ # Observe that everything passes
i386_host $ # somehow transfer the unix_cmsg binary to an amd64 system
amd64_host $ ./unix_cmsg
Running tests for SOCK_STREAM sockets:
  1: Sending, receiving cmsgcred
  2: Receiving sockcred (listening socket)
  3: Receiving sockcred (accepted socket)
  4: Sending cmsgcred, receiving sockcred
  5: Sending, receiving timeval
SERVER: msghdr.msg_flags has MSG_CTRUNC
  6: Sending, receiving bintime
SERVER: msghdr.msg_flags has MSG_CTRUNC
  7: Check cmsghdr.cmsg_len
  8: Check LOCAL_PEERCRED socket option
-- 2 tests failed!
Running tests for SOCK_DGRAM sockets:
  1: Sending, receiving cmsgcred
  2: Receiving sockcred
  3: Sending cmsgcred, receiving sockcred
  4: Sending, receiving timeval
SERVER: msghdr.msg_flags has MSG_CTRUNC
  5: Sending, receiving bintime
SERVER: msghdr.msg_flags has MSG_CTRUNC
  6: Check cmsghdr.cmsg_len
-- 2 tests failed!
Comment 1 commit-hook freebsd_committer 2017-09-07 04:31:00 UTC
A commit references this bug:

Author: sobomax
Date: Thu Sep  7 04:29:57 UTC 2017
New revision: 323254
URL: https://svnweb.freebsd.org/changeset/base/323254

Log:
  In the recvmsg32() system call iterate over returned structure(s)
  and convert any messages of types SCM_BINTIME, SCM_TIMESTAMP,
  SCM_REALTIME and SCM_MONOTONIC from 64-bit to its 32-bit
  representation. Otherwise we either run out of user-supplied
  buffer to copy those out resulting in the MSG_CTRUNC or simply
  return values that the userland 32-bit code is not going
  to parse correctly. This fixes at least two regression tests
  failing to function properly in 32-bit compat mode:

      tools/regression/sockets/udp_pingpong
      tools/regression/sockets/unix_cmsg

  PR:             kern/222039
  MFC after:	30 days

Changes:
  head/sys/compat/freebsd32/freebsd32.h
  head/sys/compat/freebsd32/freebsd32_misc.c
Comment 2 Alan Somers freebsd_committer 2017-09-07 04:35:26 UTC
Hooray!  Thanks Sobomax.
Comment 3 Eitan Adler freebsd_committer freebsd_triage 2018-05-28 19:46:39 UTC
batch change:

For bugs that match the following
-  Status Is In progress 
AND
- Untouched since 2018-01-01.
AND
- Affects Base System OR Documentation

DO:

Reset to open status.


Note:
I did a quick pass but if you are getting this email it might be worthwhile to double check to see if this bug ought to be closed.
Comment 4 Alan Somers freebsd_committer 2018-05-28 20:30:08 UTC
Resetting the MFC flag, because this never got MFCed.
Comment 5 Mark Johnston freebsd_committer 2018-07-25 20:51:52 UTC
Any plans to MFC this?
Comment 6 Maxim Sobolev freebsd_committer 2018-09-17 17:21:41 UTC
MFC is done.