From patchwork Wed Aug 29 13:11:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 145425 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp661698ljw; Wed, 29 Aug 2018 06:11:48 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZvz0/txb2Ivf2Vd5Hb27MjFbSl9l5R7vvgKiOBKP+drfc9IYSPOV9r90IxL//Cx1F8EfhQ X-Received: by 2002:a17:902:850c:: with SMTP id bj12-v6mr6067539plb.330.1535548308472; Wed, 29 Aug 2018 06:11:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535548308; cv=none; d=google.com; s=arc-20160816; b=a2oMl4Oyued7yXLU9qDOcQGo22GlvzFDfWQPfyV6Sw3rBYDJLPWY7+BxwT2GcRoOQy tE89XoSBzouJWHT4aJwnZ6Vj5axPLYjavHEofQOsBdUXZ+ExiAOjUNMCIJpTXBoBR/Jy V7WJZcReiSc3xTLdq695H7XA1XaebmanxndSM3nfSRiRBRcRohTCFp8XZgc4wlvZuzWN ygHIG5G1WCLwqC0MJ8xwowjiKN10Zn/2wNFSjwqQvRyykj5LdqV8k25gBm+uCDnk7Tjo SuDzcZTTWSW7yKe6QfoHj4vDjEf/LQI5pIn61QS1xqZY/JCMPChSsLbACn2GAQtG/kTz XvGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=dwq14egpn9xA8gaAiRkKZz1/9IXbVz+6cE+KTAW+JbU=; b=TXcP4+9V4nhkA1tjjQcWzHhRSdCHnK7/CeQQYhAgxjZvSS/QbIAXxl0kr1qYX07dEA YgVWkcGvXSTirxmwTJCrHZ5yqLDL4kc6ux5URoSI8cXWJW6G7xpWcmKEUamU1OEtkspQ MQOWJqQ0SPCV8ZvqGyGWh3rQYAm/ipbrU4PncGEb9wo9UgRkwZVlJ/sE32ldMkYUhmZl vsWaq9V+0cnwZIYBQTHcyMSXZYtzV1Oiyd1D+eOxlWw4qODZmuBSyD4L9bZ/MnmsV3it 8TfUinypapB0eHoMK1y27+U56dFwPktEOvD/iIKTh5raLijKbGUjJeC8bTyDsmLxyngf TrQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f89-v6si3620966plf.20.2018.08.29.06.11.48; Wed, 29 Aug 2018 06:11:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728365AbeH2RIk (ORCPT + 10 others); Wed, 29 Aug 2018 13:08:40 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:40881 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727204AbeH2RIj (ORCPT ); Wed, 29 Aug 2018 13:08:39 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.145]) with ESMTPA (Nemesis) id 0Lutsn-1fmRXB3jsn-0107VC; Wed, 29 Aug 2018 15:11:33 +0200 From: Arnd Bergmann To: netdev@vger.kernel.org, "David S . Miller" Cc: linux-arch@vger.kernel.org, y2038@lists.linaro.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@linux-mips.org, linux-sh@vger.kernel.org, viro@zeniv.linux.org.uk, tglx@linutronix.de, edumazet@google.com, Arnd Bergmann Subject: [PATCH net-next 3/3] net: socket: implement 64-bit timestamps Date: Wed, 29 Aug 2018 15:11:23 +0200 Message-Id: <20180829131123.3866959-1-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180829130308.3504560-1-arnd@arndb.de> References: <20180829130308.3504560-1-arnd@arndb.de> X-Provags-ID: V03:K1:b1U0VM3nN7jE7+NdbSu+AtFcHqE96sDDi89lEJSUmYMGzXptDTS i59dVytgCTqcyYT40EhNyPfbR5g2R5CeBwfu6lPrtYheP4AGmlXWkEVg25isBsX74wSHnGw b5k+faTgbVQ5EV9FMVy9S6BqGA7ALihzgXjj26ufaC3AA+84AcJtjygyQp0L69h1CxZTOrp 0azFUPiK7Blg0MKzTWhZw== X-UI-Out-Filterresults: notjunk:1; V01:K0:ZC369g1H0S8=:M6hYtpUabmEPQc0VdwgN1W gfxjYnleJ3wFp5BIlphc4b/G7y61Xeozhh9CjUlEl4sgAFBnmzqJCZAl2OfZ4YcxG/NbGn4KD 0II/r89pjN9EJxcMB3nI+4h7VwhSg7WKo2I2qZJLfG2+pWGIrgK7B6QKSptpxEfGy7DoC9ibS dFhEVqVcJSauuMNU45RI16GmkwphJC8pRiB7RdsaCmHo87hnMvuFwvNr2ellnAl1C+maPl36M WR03bxvsYi1vtP4UGlVMFtc3sD2UyQGLgvgAQVQagZJRJH8/PbXZIfL6biV+BRDPJ+Sj3Nnzo 71I+Q4+Fn3EdLxKQJB2bnYqAkZf2Ggi+c7nanTlzk/4aBFZWw7zgCcNZRCVGhpcPWYNLkV6eZ TWUL0jDPF1EJ7BZ753+sOcA2UQ/1BHdp8Jy0GKuY5FKI2ENA/QDy4mulI639XWs/XmIYtxdOe 7SB/Jxsolunv84fVmIIXianmHDiIgKKVFjDOl5E9PiJeEnFqOpw/DxIy7tX9hx8V12dx0XODo N0Hp/bf9JsLfL/ODcIttd+KI6KM7jLkcqD+24ILfBEm5i0n9YGPMc+5Lo8+fdZtomwcNY4HNf HucXZZcBHRqSqDNo6Cxtj7oqKOGvV3aqDYs15i7dzkBSlKVMbFNi6Un6Hmmxf6ZUCtt9Ht18n 3Sczb0L0XzegSQnymzT6wFz47glOb1Ug8YXmRNkes6ad99oIIB2rwivfGu2eqh6FFCUI= Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The 'timeval' and 'timespec' data structures used for socket timestamps are going to be redefined in user space based on 64-bit time_t in future versions of the C library to deal with the y2038 overflow problem, which breaks the ABI definition. Unlike many modern ioctl commands, SIOCGSTAMP and SIOCGSTAMPNS do not use the _IOR() macro to encode the size of the transferred data, so it remains ambiguous whether the application uses the old or new layout. The best workaround I could find is rather ugly: we redefine the command code based on the size of the respective data structure with a ternary operator. This lets it get evaluated as late as possible, hopefully after that structure is visible to the caller. We cannot use an #ifdef here, because inux/sockios.h might have been included before any libc header that could determine the size of time_t. The ioctl implementation now interprets the new command codes as always referring to the 64-bit structure on all architectures, while the old architecture specific command code still refers to the old architecture specific layout. The new command number is only used when they are actually different. Signed-off-by: Arnd Bergmann --- arch/alpha/include/uapi/asm/sockios.h | 4 ++-- arch/mips/include/uapi/asm/sockios.h | 4 ++-- arch/sh/include/uapi/asm/sockios.h | 5 +++-- arch/xtensa/include/uapi/asm/sockios.h | 4 ++-- include/uapi/asm-generic/sockios.h | 4 ++-- include/uapi/linux/sockios.h | 21 +++++++++++++++++++++ net/socket.c | 22 +++++++++++++++++----- 7 files changed, 49 insertions(+), 15 deletions(-) -- 2.18.0 diff --git a/arch/alpha/include/uapi/asm/sockios.h b/arch/alpha/include/uapi/asm/sockios.h index ba287e4b01bf..af92bc27c3be 100644 --- a/arch/alpha/include/uapi/asm/sockios.h +++ b/arch/alpha/include/uapi/asm/sockios.h @@ -11,7 +11,7 @@ #define SIOCSPGRP _IOW('s', 8, pid_t) #define SIOCGPGRP _IOR('s', 9, pid_t) -#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */ -#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */ +#define SIOCGSTAMP_OLD 0x8906 /* Get stamp (timeval) */ +#define SIOCGSTAMPNS_OLD 0x8907 /* Get stamp (timespec) */ #endif /* _ASM_ALPHA_SOCKIOS_H */ diff --git a/arch/mips/include/uapi/asm/sockios.h b/arch/mips/include/uapi/asm/sockios.h index 5b40a88593fa..66f60234f290 100644 --- a/arch/mips/include/uapi/asm/sockios.h +++ b/arch/mips/include/uapi/asm/sockios.h @@ -21,7 +21,7 @@ #define SIOCSPGRP _IOW('s', 8, pid_t) #define SIOCGPGRP _IOR('s', 9, pid_t) -#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */ -#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */ +#define SIOCGSTAMP_OLD 0x8906 /* Get stamp (timeval) */ +#define SIOCGSTAMPNS_OLD 0x8907 /* Get stamp (timespec) */ #endif /* _ASM_SOCKIOS_H */ diff --git a/arch/sh/include/uapi/asm/sockios.h b/arch/sh/include/uapi/asm/sockios.h index 17313d2c3527..ef18a668456d 100644 --- a/arch/sh/include/uapi/asm/sockios.h +++ b/arch/sh/include/uapi/asm/sockios.h @@ -10,6 +10,7 @@ #define SIOCSPGRP _IOW('s', 8, pid_t) #define SIOCGPGRP _IOR('s', 9, pid_t) -#define SIOCGSTAMP _IOR('s', 100, struct timeval) /* Get stamp (timeval) */ -#define SIOCGSTAMPNS _IOR('s', 101, struct timespec) /* Get stamp (timespec) */ +#define SIOCGSTAMP_OLD _IOR('s', 100, struct timeval) /* Get stamp (timeval) */ +#define SIOCGSTAMPNS_OLD _IOR('s', 101, struct timespec) /* Get stamp (timespec) */ + #endif /* __ASM_SH_SOCKIOS_H */ diff --git a/arch/xtensa/include/uapi/asm/sockios.h b/arch/xtensa/include/uapi/asm/sockios.h index fb8ac3607189..1a1f58f4b75a 100644 --- a/arch/xtensa/include/uapi/asm/sockios.h +++ b/arch/xtensa/include/uapi/asm/sockios.h @@ -26,7 +26,7 @@ #define SIOCSPGRP _IOW('s', 8, pid_t) #define SIOCGPGRP _IOR('s', 9, pid_t) -#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */ -#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */ +#define SIOCGSTAMP_OLD 0x8906 /* Get stamp (timeval) */ +#define SIOCGSTAMPNS_OLD 0x8907 /* Get stamp (timespec) */ #endif /* _XTENSA_SOCKIOS_H */ diff --git a/include/uapi/asm-generic/sockios.h b/include/uapi/asm-generic/sockios.h index 64f658c7cec2..44fa3ed70483 100644 --- a/include/uapi/asm-generic/sockios.h +++ b/include/uapi/asm-generic/sockios.h @@ -8,7 +8,7 @@ #define FIOGETOWN 0x8903 #define SIOCGPGRP 0x8904 #define SIOCATMARK 0x8905 -#define SIOCGSTAMP 0x8906 /* Get stamp (timeval) */ -#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */ +#define SIOCGSTAMP_OLD 0x8906 /* Get stamp (timeval) */ +#define SIOCGSTAMPNS_OLD 0x8907 /* Get stamp (timespec) */ #endif /* __ASM_GENERIC_SOCKIOS_H */ diff --git a/include/uapi/linux/sockios.h b/include/uapi/linux/sockios.h index d393e9ed3964..7d1bccbbef78 100644 --- a/include/uapi/linux/sockios.h +++ b/include/uapi/linux/sockios.h @@ -19,6 +19,7 @@ #ifndef _LINUX_SOCKIOS_H #define _LINUX_SOCKIOS_H +#include #include /* Linux-specific socket ioctls */ @@ -27,6 +28,26 @@ #define SOCK_IOC_TYPE 0x89 +/* + * the timeval/timespec data structure layout is defined by libc, + * so we need to cover both possible versions on 32-bit. + */ +/* Get stamp (timeval) */ +#define SIOCGSTAMP_NEW _IOR(SOCK_IOC_TYPE, 0x06, long long[2]) +/* Get stamp (timespec) */ +#define SIOCGSTAMPNS_NEW _IOR(SOCK_IOC_TYPE, 0x07, long long[2]) + +#if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__)) +/* on 64-bit and x32, avoid the ?: operator */ +#define SIOCGSTAMP SIOCGSTAMP_OLD +#define SIOCGSTAMPNS SIOCGSTAMPNS_OLD +#else +#define SIOCGSTAMP ((sizeof(struct timeval)) == 8 ? \ + SIOCGSTAMP_OLD : SIOCGSTAMP_NEW) +#define SIOCGSTAMPNS ((sizeof(struct timespec)) == 8 ? \ + SIOCGSTAMPNS_OLD : SIOCGSTAMPNS_NEW) +#endif + /* Routing table calls. */ #define SIOCADDRT 0x890B /* add routing table entry */ #define SIOCDELRT 0x890C /* delete routing table entry */ diff --git a/net/socket.c b/net/socket.c index 6814e8dc8af1..9762e7d5378b 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1069,14 +1069,24 @@ static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg) err = open_related_ns(&net->ns, get_net_ns); break; - case SIOCGSTAMP: - case SIOCGSTAMPNS: + case SIOCGSTAMP_OLD: + case SIOCGSTAMPNS_OLD: if (!sock->ops->gettstamp) { err = -ENOIOCTLCMD; break; } err = sock->ops->gettstamp(sock, argp, - cmd == SIOCGSTAMP, false); + cmd == SIOCGSTAMP_OLD, + !IS_ENABLED(CONFIG_64BIT)); + case SIOCGSTAMP_NEW: + case SIOCGSTAMPNS_NEW: + if (!sock->ops->gettstamp) { + err = -ENOIOCTLCMD; + break; + } + err = sock->ops->gettstamp(sock, argp, + cmd == SIOCGSTAMP_NEW, + false); break; default: err = sock_do_ioctl(net, sock, cmd, arg); @@ -3095,8 +3105,8 @@ static int compat_sock_ioctl_trans(struct file *file, struct socket *sock, case SIOCADDRT: case SIOCDELRT: return routing_ioctl(net, sock, cmd, argp); - case SIOCGSTAMP: - case SIOCGSTAMPNS: + case SIOCGSTAMP_OLD: + case SIOCGSTAMPNS_OLD: if (!sock->ops->gettstamp) return -ENOIOCTLCMD; return sock->ops->gettstamp(sock, argp, cmd == SIOCGSTAMP, @@ -3119,6 +3129,8 @@ static int compat_sock_ioctl_trans(struct file *file, struct socket *sock, case SIOCADDDLCI: case SIOCDELDLCI: case SIOCGSKNS: + case SIOCGSTAMP_NEW: + case SIOCGSTAMPNS_NEW: return sock_ioctl(file, cmd, arg); case SIOCGIFFLAGS: