y2038: socket: use __kernel_old_timespec instead of timespec
authorArnd Bergmann <arnd@arndb.de>
Fri, 25 Oct 2019 20:04:46 +0000 (22:04 +0200)
committerArnd Bergmann <arnd@arndb.de>
Fri, 15 Nov 2019 13:38:29 +0000 (14:38 +0100)
The 'timespec' type definition and helpers like ktime_to_timespec()
or timespec64_to_timespec() should no longer be used in the kernel so
we can remove them and avoid introducing y2038 issues in new code.

Change the socket code that needs to pass a timespec to user space for
backward compatibility to use __kernel_old_timespec instead.  This type
has the same layout but with a clearer defined name.

Slightly reformat tcp_recv_timestamp() for consistency after the removal
of timespec64_to_timespec().

Acked-by: Deepa Dinamani <deepa.kernel@gmail.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
include/linux/skbuff.h
net/compat.c
net/ipv4/tcp.c
net/socket.c

index 64a395c7f6895ce4dc439571de2eec8673b393e4..6d64ffe92867c4de9c2a9175f9c2b95f34a0c484 100644 (file)
@@ -3656,9 +3656,12 @@ static inline void skb_get_new_timestamp(const struct sk_buff *skb,
 }
 
 static inline void skb_get_timestampns(const struct sk_buff *skb,
-                                      struct timespec *stamp)
+                                      struct __kernel_old_timespec *stamp)
 {
-       *stamp = ktime_to_timespec(skb->tstamp);
+       struct timespec64 ts = ktime_to_timespec64(skb->tstamp);
+
+       stamp->tv_sec = ts.tv_sec;
+       stamp->tv_nsec = ts.tv_nsec;
 }
 
 static inline void skb_get_new_timestampns(const struct sk_buff *skb,
index 0f7ded26059ec6261e704d37948f736b1f1c7778..47d99c784947c910bbe1b85d9539b3a07b023246 100644 (file)
@@ -232,7 +232,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
                    (type == SO_TIMESTAMPNS_OLD || type == SO_TIMESTAMPING_OLD)) {
                        int count = type == SO_TIMESTAMPNS_OLD ? 1 : 3;
                        int i;
-                       struct timespec *ts = (struct timespec *)data;
+                       struct __kernel_old_timespec *ts = data;
                        for (i = 0; i < count; i++) {
                                cts[i].tv_sec = ts[i].tv_sec;
                                cts[i].tv_nsec = ts[i].tv_nsec;
index d8876f0e9672718b4e02bc7aaaac30ecfd4903cb..013f635db19cd27e08310623d4539f0c33e0e6b7 100644 (file)
@@ -1864,29 +1864,33 @@ static void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk,
                if (sock_flag(sk, SOCK_RCVTSTAMP)) {
                        if (sock_flag(sk, SOCK_RCVTSTAMPNS)) {
                                if (new_tstamp) {
-                                       struct __kernel_timespec kts = {tss->ts[0].tv_sec, tss->ts[0].tv_nsec};
-
+                                       struct __kernel_timespec kts = {
+                                               .tv_sec = tss->ts[0].tv_sec,
+                                               .tv_nsec = tss->ts[0].tv_nsec,
+                                       };
                                        put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_NEW,
                                                 sizeof(kts), &kts);
                                } else {
-                                       struct timespec ts_old = timespec64_to_timespec(tss->ts[0]);
-
+                                       struct __kernel_old_timespec ts_old = {
+                                               .tv_sec = tss->ts[0].tv_sec,
+                                               .tv_nsec = tss->ts[0].tv_nsec,
+                                       };
                                        put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_OLD,
                                                 sizeof(ts_old), &ts_old);
                                }
                        } else {
                                if (new_tstamp) {
-                                       struct __kernel_sock_timeval stv;
-
-                                       stv.tv_sec = tss->ts[0].tv_sec;
-                                       stv.tv_usec = tss->ts[0].tv_nsec / 1000;
+                                       struct __kernel_sock_timeval stv = {
+                                               .tv_sec = tss->ts[0].tv_sec,
+                                               .tv_usec = tss->ts[0].tv_nsec / 1000,
+                                       };
                                        put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP_NEW,
                                                 sizeof(stv), &stv);
                                } else {
-                                       struct __kernel_old_timeval tv;
-
-                                       tv.tv_sec = tss->ts[0].tv_sec;
-                                       tv.tv_usec = tss->ts[0].tv_nsec / 1000;
+                                       struct __kernel_old_timeval tv = {
+                                               .tv_sec = tss->ts[0].tv_sec,
+                                               .tv_usec = tss->ts[0].tv_nsec / 1000,
+                                       };
                                        put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP_OLD,
                                                 sizeof(tv), &tv);
                                }
index 98f6544b0096aecc9e9dce58069aedd532321570..9ab00a080760829ced6d1a6bc1423b6565fdf223 100644 (file)
@@ -793,7 +793,7 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
                                put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_NEW,
                                         sizeof(ts), &ts);
                        } else {
-                               struct timespec ts;
+                               struct __kernel_old_timespec ts;
 
                                skb_get_timestampns(skb, &ts);
                                put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_OLD,