public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/azanella/y2038] linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS}
@ 2021-06-08 20:48 Adhemerval Zanella
  0 siblings, 0 replies; 10+ messages in thread
From: Adhemerval Zanella @ 2021-06-08 20:48 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=110e6fa7e56a68050792c56bd1f055ffab4edb1c

commit 110e6fa7e56a68050792c56bd1f055ffab4edb1c
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).
    
    Reviewed-by: Lukasz Majewski <lukma@denx.de>
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
    Tested-by: Carlos O'Donell <carlos@redhat.com>

Diff:
---
 sysdeps/unix/sysv/linux/recvmmsg.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

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;
 }


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [glibc/azanella/y2038] linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS}
@ 2021-05-26 16:24 Adhemerval Zanella
  0 siblings, 0 replies; 10+ messages in thread
From: Adhemerval Zanella @ 2021-05-26 16:24 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=678a7a2660d815ab5b30db5b4640475868b0d3be

commit 678a7a2660d815ab5b30db5b4640475868b0d3be
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/recvmmsg.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

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;
 }


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [glibc/azanella/y2038] linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS}
@ 2021-03-05 19:20 Adhemerval Zanella
  0 siblings, 0 replies; 10+ messages in thread
From: Adhemerval Zanella @ 2021-03-05 19:20 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=7b07cf7df5d94a17302384c01d1d7a1e580b5e0f

commit 7b07cf7df5d94a17302384c01d1d7a1e580b5e0f
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/recvmmsg.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

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;
 }


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [glibc/azanella/y2038] linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS}
@ 2021-03-04 17:36 Adhemerval Zanella
  0 siblings, 0 replies; 10+ messages in thread
From: Adhemerval Zanella @ 2021-03-04 17:36 UTC (permalink / raw)
  To: glibc-cvs

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;
 }


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [glibc/azanella/y2038] linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS}
@ 2021-03-04 11:29 Adhemerval Zanella
  0 siblings, 0 replies; 10+ messages in thread
From: Adhemerval Zanella @ 2021-03-04 11:29 UTC (permalink / raw)
  To: glibc-cvs

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;
 }


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [glibc/azanella/y2038] linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS}
@ 2021-03-02 12:30 Adhemerval Zanella
  0 siblings, 0 replies; 10+ messages in thread
From: Adhemerval Zanella @ 2021-03-02 12:30 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=19f7cfc65f39e126bb83542a89d62b889857092f

commit 19f7cfc65f39e126bb83542a89d62b889857092f
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/recvmmsg.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

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;
 }


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [glibc/azanella/y2038] linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS}
@ 2021-03-01 17:35 Adhemerval Zanella
  0 siblings, 0 replies; 10+ messages in thread
From: Adhemerval Zanella @ 2021-03-01 17:35 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=0e76aa956f99d7d766c60a2035a4954496e677f1

commit 0e76aa956f99d7d766c60a2035a4954496e677f1
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/recvmmsg.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

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;
 }


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [glibc/azanella/y2038] linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS}
@ 2021-02-26 20:41 Adhemerval Zanella
  0 siblings, 0 replies; 10+ messages in thread
From: Adhemerval Zanella @ 2021-02-26 20:41 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=8366abd741d8fb2c55d7074f4941386b59a03deb

commit 8366abd741d8fb2c55d7074f4941386b59a03deb
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/recvmmsg.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

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;
 }


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [glibc/azanella/y2038] linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS}
@ 2021-02-23 20:38 Adhemerval Zanella
  0 siblings, 0 replies; 10+ messages in thread
From: Adhemerval Zanella @ 2021-02-23 20:38 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9c0cb07bc4dec05f4f24377770af85269139aeeb

commit 9c0cb07bc4dec05f4f24377770af85269139aeeb
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/recvmmsg.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

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;
 }


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [glibc/azanella/y2038] linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS}
@ 2021-02-23 12:36 Adhemerval Zanella
  0 siblings, 0 replies; 10+ messages in thread
From: Adhemerval Zanella @ 2021-02-23 12:36 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=57d7367ded8bba42138bfd3fddc1c52fce045aaa

commit 57d7367ded8bba42138bfd3fddc1c52fce045aaa
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:
---
 include/sys/socket.h               |  3 +++
 sysdeps/unix/sysv/linux/recvmmsg.c | 17 +++++++++++++++--
 sysdeps/unix/sysv/linux/recvmsg.c  |  6 +++---
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/include/sys/socket.h b/include/sys/socket.h
index c551c8fa87..171440ab14 100644
--- a/include/sys/socket.h
+++ b/include/sys/socket.h
@@ -171,6 +171,9 @@ libc_hidden_proto (__libc_sa_len)
 #define SCM_TIMESTAMPNS_NEW   SO_TIMESTAMPNS_NEW
 #define SCM_TIMESTAMPING_NEW  SO_TIMESTAMPING_NEW
 
+extern void __convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize)
+  attribute_hidden;
+
 libc_hidden_proto (__cmsg_nxthdr)
 
 #endif
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;
 }
diff --git a/sysdeps/unix/sysv/linux/recvmsg.c b/sysdeps/unix/sysv/linux/recvmsg.c
index c01a9009c7..f802e85971 100644
--- a/sysdeps/unix/sysv/linux/recvmsg.c
+++ b/sysdeps/unix/sysv/linux/recvmsg.c
@@ -32,8 +32,8 @@
    original message as a spurious control ones of unknown typ while running
    on kernel with native 64-bit time support will only see the time64 version
    of the control message.  */
-static void
-convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize)
+void
+__convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize)
 {
   if (msg->msg_control == NULL || msg->msg_controllen == 0)
     return;
@@ -108,7 +108,7 @@ __libc_recvmsg (int fd, struct msghdr *msg, int flags)
 
 #ifndef __ASSUME_TIME64_SYSCALLS
   if (r >= 0)
-    convert_scm_timestamps (msg, orig_controllen);
+    __convert_scm_timestamps (msg, orig_controllen);
 #endif
 
   return r;


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-06-08 20:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-08 20:48 [glibc/azanella/y2038] linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS} Adhemerval Zanella
  -- strict thread matches above, loose matches on Subject: below --
2021-05-26 16:24 Adhemerval Zanella
2021-03-05 19:20 Adhemerval Zanella
2021-03-04 17:36 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

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).