Commit df1b4ba9 authored by Arnd Bergmann's avatar Arnd Bergmann

y2038: socket: use __kernel_old_timespec instead of timespec

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: default avatarDeepa Dinamani <deepa.kernel@gmail.com>
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
parent 0309f98f
...@@ -3656,9 +3656,12 @@ static inline void skb_get_new_timestamp(const struct sk_buff *skb, ...@@ -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, 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, static inline void skb_get_new_timestampns(const struct sk_buff *skb,
......
...@@ -232,7 +232,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat ...@@ -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)) { (type == SO_TIMESTAMPNS_OLD || type == SO_TIMESTAMPING_OLD)) {
int count = type == SO_TIMESTAMPNS_OLD ? 1 : 3; int count = type == SO_TIMESTAMPNS_OLD ? 1 : 3;
int i; int i;
struct timespec *ts = (struct timespec *)data; struct __kernel_old_timespec *ts = data;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
cts[i].tv_sec = ts[i].tv_sec; cts[i].tv_sec = ts[i].tv_sec;
cts[i].tv_nsec = ts[i].tv_nsec; cts[i].tv_nsec = ts[i].tv_nsec;
......
...@@ -1864,29 +1864,33 @@ static void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk, ...@@ -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_RCVTSTAMP)) {
if (sock_flag(sk, SOCK_RCVTSTAMPNS)) { if (sock_flag(sk, SOCK_RCVTSTAMPNS)) {
if (new_tstamp) { 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, put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_NEW,
sizeof(kts), &kts); sizeof(kts), &kts);
} else { } 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, put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_OLD,
sizeof(ts_old), &ts_old); sizeof(ts_old), &ts_old);
} }
} else { } else {
if (new_tstamp) { if (new_tstamp) {
struct __kernel_sock_timeval stv; struct __kernel_sock_timeval stv = {
.tv_sec = tss->ts[0].tv_sec,
stv.tv_sec = tss->ts[0].tv_sec; .tv_usec = tss->ts[0].tv_nsec / 1000,
stv.tv_usec = tss->ts[0].tv_nsec / 1000; };
put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP_NEW, put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP_NEW,
sizeof(stv), &stv); sizeof(stv), &stv);
} else { } else {
struct __kernel_old_timeval tv; struct __kernel_old_timeval tv = {
.tv_sec = tss->ts[0].tv_sec,
tv.tv_sec = tss->ts[0].tv_sec; .tv_usec = tss->ts[0].tv_nsec / 1000,
tv.tv_usec = tss->ts[0].tv_nsec / 1000; };
put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP_OLD, put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP_OLD,
sizeof(tv), &tv); sizeof(tv), &tv);
} }
......
...@@ -793,7 +793,7 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk, ...@@ -793,7 +793,7 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_NEW, put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_NEW,
sizeof(ts), &ts); sizeof(ts), &ts);
} else { } else {
struct timespec ts; struct __kernel_old_timespec ts;
skb_get_timestampns(skb, &ts); skb_get_timestampns(skb, &ts);
put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_OLD, put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_OLD,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment