[PATCH 1/3] socket: Use old_timeval types for socket timeouts

From: Deepa Dinamani
Date: Tue Jan 08 2019 - 00:23:38 EST


As part of y2038 solution, all internal uses of
struct timeval are replaced by struct __kernel_old_timeval
and struct compat_timeval by struct old_timeval32.
Make socket timeouts use these new types.

This is mainly to be able to verify that the kernel build
is y2038 safe when such non y2038 safe types are not
supported anymore.

Signed-off-by: Deepa Dinamani <deepa.kernel@xxxxxxxxx>
---
net/compat.c | 10 +++++-----
net/core/sock.c | 8 ++++----
net/vmw_vsock/af_vsock.c | 4 ++--
3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/net/compat.c b/net/compat.c
index b6ff0899e424..cbc15f65033c 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -351,8 +351,8 @@ static int do_set_attach_filter(struct socket *sock, int level, int optname,
static int do_set_sock_timeout(struct socket *sock, int level,
int optname, char __user *optval, unsigned int optlen)
{
- struct compat_timeval __user *up = (struct compat_timeval __user *)optval;
- struct timeval ktime;
+ struct old_timeval32 __user *up = (struct old_timeval32 __user *)optval;
+ struct __kernel_old_timeval ktime;
mm_segment_t old_fs;
int err;

@@ -420,12 +420,12 @@ COMPAT_SYSCALL_DEFINE5(setsockopt, int, fd, int, level, int, optname,
static int do_get_sock_timeout(struct socket *sock, int level, int optname,
char __user *optval, int __user *optlen)
{
- struct compat_timeval __user *up;
- struct timeval ktime;
+ struct old_timeval32 __user *up;
+ struct __kernel_old_timeval ktime;
mm_segment_t old_fs;
int len, err;

- up = (struct compat_timeval __user *)optval;
+ up = (struct old_timeval32 __user *)optval;
if (get_user(len, optlen))
return -EFAULT;
if (len < sizeof(*up))
diff --git a/net/core/sock.c b/net/core/sock.c
index 78df5228ffbd..af0fb33624e2 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -337,7 +337,7 @@ EXPORT_SYMBOL(__sk_backlog_rcv);

static int sock_set_timeout(long *timeo_p, char __user *optval, int optlen)
{
- struct timeval tv;
+ struct __kernel_old_timeval tv;

if (optlen < sizeof(tv))
return -EINVAL;
@@ -1113,7 +1113,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
int val;
u64 val64;
struct linger ling;
- struct timeval tm;
+ struct __kernel_old_timeval tm;
struct sock_txtime txtime;
} v;

@@ -1223,7 +1223,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
break;

case SO_RCVTIMEO:
- lv = sizeof(struct timeval);
+ lv = sizeof(struct __kernel_old_timeval);
if (sk->sk_rcvtimeo == MAX_SCHEDULE_TIMEOUT) {
v.tm.tv_sec = 0;
v.tm.tv_usec = 0;
@@ -1234,7 +1234,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
break;

case SO_SNDTIMEO:
- lv = sizeof(struct timeval);
+ lv = sizeof(struct __kernel_old_timeval);
if (sk->sk_sndtimeo == MAX_SCHEDULE_TIMEOUT) {
v.tm.tv_sec = 0;
v.tm.tv_usec = 0;
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 43a1dec08825..e1149bf1b57b 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -1439,7 +1439,7 @@ static int vsock_stream_setsockopt(struct socket *sock,
break;

case SO_VM_SOCKETS_CONNECT_TIMEOUT: {
- struct timeval tv;
+ struct __kernel_old_timeval tv;
COPY_IN(tv);
if (tv.tv_sec >= 0 && tv.tv_usec < USEC_PER_SEC &&
tv.tv_sec < (MAX_SCHEDULE_TIMEOUT / HZ - 1)) {
@@ -1517,7 +1517,7 @@ static int vsock_stream_getsockopt(struct socket *sock,
break;

case SO_VM_SOCKETS_CONNECT_TIMEOUT: {
- struct timeval tv;
+ struct __kernel_old_timeval tv;
tv.tv_sec = vsk->connect_timeout / HZ;
tv.tv_usec =
(vsk->connect_timeout -
--
2.17.1