public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Adhemerval Zanella <azanella@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc/azanella/y2038] linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS}
Date: Thu,  4 Mar 2021 17:36:23 +0000 (GMT)	[thread overview]
Message-ID: <20210304173623.6C667386102B@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=90d6962279b7e63c7da5bb481afb79d9c26be077

commit 90d6962279b7e63c7da5bb481afb79d9c26be077
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Sep 8 09:08:10 2020 -0300

    linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS}
    
    Handle the SO_TIMESTAMP{NS} similar to recvmsg: for
    !__ASSUME_TIME64_SYSCALLS it converts the first 32-bit time SO_TIMESTAMP
    or SO_TIMESTAMPNS and appends it to the control buffer if has extra
    space or returns MSG_CTRUNC otherwise.  The 32-bit time field is kept
    as-is.
    
    Also for !__ASSUME_TIME64_SYSCALLS it limits the maximum number of
    'struct mmsghdr *' to IOV_MAX (and also increases the stack size
    requirement to IOV_MAX times sizeof (socklen_t)).  The Linux imposes
    a similar limit to sendmmsg, so bound the array size on recvmmsg is not
    unreasonable.  And this will be used only on older when building with
    32-bit time support.
    
    Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15
    kernel).

Diff:
---
 sysdeps/unix/sysv/linux/convert_scm_timestamps.c | 22 ++++++++--------------
 sysdeps/unix/sysv/linux/recvmmsg.c               | 17 +++++++++++++++--
 2 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/convert_scm_timestamps.c b/sysdeps/unix/sysv/linux/convert_scm_timestamps.c
index 3c7fda26ee..3c123c28ce 100644
--- a/sysdeps/unix/sysv/linux/convert_scm_timestamps.c
+++ b/sysdeps/unix/sysv/linux/convert_scm_timestamps.c
@@ -22,13 +22,7 @@
 # include <stdint.h>
 # include <string.h>
 # include <sys/socket.h>
-/* The kernel header with SO_* constants is used as default for _GNU_SOURCE,
-   however the new constants that describe 64-bit time support were added
-   only on v5.1.  */
-# if !defined(SO_TIMESTAMP_OLD) || !defined(SO_TIMESTAMP_NEW) \
-    || !defined(SO_TIMESTAMPNS_OLD) || !defined(SO_TIMESTAMPNS_NEW)
-#  include <bits/socket-constants.h>
-# endif
+# include <socket-constants-time64.h>
 
 /* It converts the first SO_TIMESTAMP or SO_TIMESTAMPNS with 32-bit time and
    appends it to the control buffer.  The 32-bit time field is kept as-is.
@@ -46,10 +40,10 @@ __convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize)
   if (msg->msg_control == NULL || msg->msg_controllen == 0)
     return;
 
-  /* The returnted control message format for SO_TIMESTAMP_NEW is a
+  /* The returned control message format for SO_TIMESTAMP_NEW is a
      'struct __kernel_sock_timeval' while for SO_TIMESTAMPNS_NEW is a
-     'struct __kernel_timespec'.  In both case it is essentially two
-     uint64_t members.  */
+     'struct __kernel_timespec'.  In either case it is two uint64_t
+     members.  */
   uint64_t tvts[2];
 
   struct cmsghdr *cmsg, *last = NULL;
@@ -64,14 +58,14 @@ __convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize)
 
       switch (cmsg->cmsg_type)
 	{
-	case SO_TIMESTAMP_OLD:
+	case COMPAT_SO_TIMESTAMP_OLD:
 	  if (type != 0)
 	    break;
-	  type = SO_TIMESTAMP_NEW;
+	  type = COMPAT_SO_TIMESTAMP_NEW;
 	  goto common;
 
-	case SO_TIMESTAMPNS_OLD:
-	  type = SO_TIMESTAMPNS_NEW;
+	case COMPAT_SO_TIMESTAMPNS_OLD:
+	  type = COMPAT_SO_TIMESTAMPNS_NEW;
 
 	/* fallthrough  */
 	common:
diff --git a/sysdeps/unix/sysv/linux/recvmmsg.c b/sysdeps/unix/sysv/linux/recvmmsg.c
index 672ba20332..5cd107ffa9 100644
--- a/sysdeps/unix/sysv/linux/recvmmsg.c
+++ b/sysdeps/unix/sysv/linux/recvmmsg.c
@@ -44,13 +44,26 @@ __recvmmsg64 (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags,
       ts32 = valid_timespec64_to_timespec (*timeout);
       pts32 = &ts32;
     }
+
+  socklen_t csize[IOV_MAX];
+  if (vlen > IOV_MAX)
+    vlen = IOV_MAX;
+  for (int i = 0; i < vlen; i++)
+    csize[i] = vmessages[i].msg_hdr.msg_controllen;
+
 # ifdef __ASSUME_RECVMMSG_SYSCALL
   r = SYSCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, pts32);
 # else
   r = SOCKETCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, pts32);
 # endif
-  if (r >= 0 && timeout != NULL)
-    *timeout = valid_timespec_to_timespec64 (ts32);
+  if (r >= 0)
+    {
+      if (timeout != NULL)
+        *timeout = valid_timespec_to_timespec64 (ts32);
+
+      for (int i=0; i < r; i++)
+        __convert_scm_timestamps (&vmessages[i].msg_hdr, csize[i]);
+    }
 #endif /* __ASSUME_TIME64_SYSCALLS  */
   return r;
 }


             reply	other threads:[~2021-03-04 17:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-04 17:36 Adhemerval Zanella [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-06-08 20:48 Adhemerval Zanella
2021-05-26 16:24 Adhemerval Zanella
2021-03-05 19:20 Adhemerval Zanella
2021-03-04 11:29 Adhemerval Zanella
2021-03-02 12:30 Adhemerval Zanella
2021-03-01 17:35 Adhemerval Zanella
2021-02-26 20:41 Adhemerval Zanella
2021-02-23 20:38 Adhemerval Zanella
2021-02-23 12:36 Adhemerval Zanella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210304173623.6C667386102B@sourceware.org \
    --to=azanella@sourceware.org \
    --cc=glibc-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).