Skip to content

Commit df1b4ba

Browse files
committed
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: Deepa Dinamani <[email protected]> Signed-off-by: Arnd Bergmann <[email protected]>
1 parent 0309f98 commit df1b4ba

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

include/linux/skbuff.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3656,9 +3656,12 @@ static inline void skb_get_new_timestamp(const struct sk_buff *skb,
36563656
}
36573657

36583658
static inline void skb_get_timestampns(const struct sk_buff *skb,
3659-
struct timespec *stamp)
3659+
struct __kernel_old_timespec *stamp)
36603660
{
3661-
*stamp = ktime_to_timespec(skb->tstamp);
3661+
struct timespec64 ts = ktime_to_timespec64(skb->tstamp);
3662+
3663+
stamp->tv_sec = ts.tv_sec;
3664+
stamp->tv_nsec = ts.tv_nsec;
36623665
}
36633666

36643667
static inline void skb_get_new_timestampns(const struct sk_buff *skb,

net/compat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
232232
(type == SO_TIMESTAMPNS_OLD || type == SO_TIMESTAMPING_OLD)) {
233233
int count = type == SO_TIMESTAMPNS_OLD ? 1 : 3;
234234
int i;
235-
struct timespec *ts = (struct timespec *)data;
235+
struct __kernel_old_timespec *ts = data;
236236
for (i = 0; i < count; i++) {
237237
cts[i].tv_sec = ts[i].tv_sec;
238238
cts[i].tv_nsec = ts[i].tv_nsec;

net/ipv4/tcp.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,29 +1864,33 @@ static void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk,
18641864
if (sock_flag(sk, SOCK_RCVTSTAMP)) {
18651865
if (sock_flag(sk, SOCK_RCVTSTAMPNS)) {
18661866
if (new_tstamp) {
1867-
struct __kernel_timespec kts = {tss->ts[0].tv_sec, tss->ts[0].tv_nsec};
1868-
1867+
struct __kernel_timespec kts = {
1868+
.tv_sec = tss->ts[0].tv_sec,
1869+
.tv_nsec = tss->ts[0].tv_nsec,
1870+
};
18691871
put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_NEW,
18701872
sizeof(kts), &kts);
18711873
} else {
1872-
struct timespec ts_old = timespec64_to_timespec(tss->ts[0]);
1873-
1874+
struct __kernel_old_timespec ts_old = {
1875+
.tv_sec = tss->ts[0].tv_sec,
1876+
.tv_nsec = tss->ts[0].tv_nsec,
1877+
};
18741878
put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_OLD,
18751879
sizeof(ts_old), &ts_old);
18761880
}
18771881
} else {
18781882
if (new_tstamp) {
1879-
struct __kernel_sock_timeval stv;
1880-
1881-
stv.tv_sec = tss->ts[0].tv_sec;
1882-
stv.tv_usec = tss->ts[0].tv_nsec / 1000;
1883+
struct __kernel_sock_timeval stv = {
1884+
.tv_sec = tss->ts[0].tv_sec,
1885+
.tv_usec = tss->ts[0].tv_nsec / 1000,
1886+
};
18831887
put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP_NEW,
18841888
sizeof(stv), &stv);
18851889
} else {
1886-
struct __kernel_old_timeval tv;
1887-
1888-
tv.tv_sec = tss->ts[0].tv_sec;
1889-
tv.tv_usec = tss->ts[0].tv_nsec / 1000;
1890+
struct __kernel_old_timeval tv = {
1891+
.tv_sec = tss->ts[0].tv_sec,
1892+
.tv_usec = tss->ts[0].tv_nsec / 1000,
1893+
};
18901894
put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP_OLD,
18911895
sizeof(tv), &tv);
18921896
}

net/socket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
793793
put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_NEW,
794794
sizeof(ts), &ts);
795795
} else {
796-
struct timespec ts;
796+
struct __kernel_old_timespec ts;
797797

798798
skb_get_timestampns(skb, &ts);
799799
put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMPNS_OLD,

0 commit comments

Comments
 (0)