From patchwork Mon Nov 27 17:00:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 119758 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp539675qgn; Mon, 27 Nov 2017 09:01:52 -0800 (PST) X-Google-Smtp-Source: AGs4zMbyF+6IPvD0qw64QkK2BLVyRoxxoLXUmcbeoA+g09ZJ+m0VvSn1u+ZxSLdnTNAuyJL8r8Mz X-Received: by 10.98.29.83 with SMTP id d80mr37048408pfd.156.1511802112842; Mon, 27 Nov 2017 09:01:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511802112; cv=none; d=google.com; s=arc-20160816; b=NLXBhXPMCkISxAnlgcgxz1GBTS1sRItz4dESkEp1AePkCZi1vRuoXV94LD1n90c1fD rCwYipwVC1E59QFOmJpi1A7d29gUSJS0YWAso1R/TI8vVMENbLQ2AqNfvHkKedjafm75 JqSz3Ccl7cQ249CcU1XsX9ktuE0NLED7bqybswkUn8brwYTq+n5h+t7M43q8O3+r3Q+5 aySWXIhogf9FazYZm4koqrbgFahzNcfDI4iHW/rMcFU5SGcUkZG81aGdmzo3+zhjRVH5 ou79aGSwQEc3ooLJzb106TNYPW3EVCbrnHkELk1cEnFVSmuGS73VIubFY3PRQk6MQ6To h8pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=e/YqFAm15TGszX/P31cH6DwYxzrDYM2vkcMOWx9A5Dw=; b=uFVGe29+P+7Y1DQFFplQN0ySoyny//OkAxz7uP1IIJuJERpzMda9zTUuxyPsey2oVu AOXg4fDuR5AdqinY2vyo7wMsDd4eiTYBlwAjMxH/fdMS+LBgg2DJ64CYG24DoJt5ipe+ y64xmzKWrmxv9UmXf6Ztt2t1cgJy9iVEXDCSGVYpoZ2NhSa+GngKRnPgiu5l1wFk5hVC MQF5ua8R8FsrCdRAA6XvwwSvq+ZR1YFenX7ZBugx9cLOP9+W0fgRJiGyGb/Ot12Uiu44 jTolKSYVQAuf3+dT9OTEcBVJy+cyy1TeVlOumUxgK44J7XpRF0z67dosikYdsviaGf0B 9D0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 l30si23494222plg.363.2017.11.27.09.01.52; Mon, 27 Nov 2017 09:01:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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 linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932417AbdK0RBv (ORCPT + 28 others); Mon, 27 Nov 2017 12:01:51 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:53173 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932086AbdK0RBs (ORCPT ); Mon, 27 Nov 2017 12:01:48 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.145]) with ESMTPA (Nemesis) id 0MSJh5-1eiMoJ2bG7-00TWqX; Mon, 27 Nov 2017 18:01:32 +0100 From: Arnd Bergmann To: John Stultz , Thomas Gleixner Cc: y2038@lists.linaro.org, libc-alpha@sourceware.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Albert ARIBAUD , Arnd Bergmann , Stephen Boyd , Al Viro , Deepa Dinamani , Ingo Molnar , Andreas Dilger Subject: [PATCH 1/3] y2038: introduce struct __kernel_old_timeval Date: Mon, 27 Nov 2017 18:00:45 +0100 Message-Id: <20171127170121.634826-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:IsWBwuBpWKh7GIHHNi1d8o90Zj1SmouhvF0Yn2AcjZP/aTMDoN/ ybnF25l/Hyvnwl4fdsQFH4QOG0P1BT7GeoRvkK2y4RwwcMfPi/H2z3NaMJ5cjP2x1v4EEzM mUejm/hvZG9xdqtIwSFsBKampxdZS1PP/R3oX8u6bbfpgOEvK52ebEx3U3cFgvAZ+RbuSkh LvuaAuiPkQL678fdIdXjA== X-UI-Out-Filterresults: notjunk:1; V01:K0:A/taIUiopR0=:SicKl16WFJbQeZNfzE+4YR L6BmqMp3AMtsUfXLXsinyREQAGvv2QMXwNdgQI7Fl1n4wprIwfZm9cOG50gtwJ/1bm9/1X1rg 6dRbr6H+QeTlUmobGeDI5b5IF9bQXv+SZhrzL4aJqtLJTRPJ7I5L04XAaqHxD8vBVBp3sZx5C mw5nfB2kM+PI1+QPEsvg7IuurLXGhU21mjxTxLpik1swkPYeu9yu0NeeO4gDa0skXJjvdFRgU S9Y2G0xExgee0z0WggQ2oBk9GgTU+hv6XH+H9dzXxrOGs7s4+1Qk+XDzh4BXFKZnSxWHjzMgw 7akwjoH7G+e5n8Q8VI08TkpkV0LeVnuHQ4vp7JkY6hIfC6gLXHa6mtRus/c0FctwGe9JajfsZ +NTCKCpEZ2ptbJ1/vpU4WH/Dwpb4Ehvu4IkcpZgNa82FdFee29SKp0lJGDP+srGjxI6WLyeIz 3n7I4P+4nzEbn0hm3MwLycsA1j6newK6/qNYfJpmiXnktTU9UbNjLWbhOdXTe3dvPf3l8I/XU T5orgeKygeJjOqrXemSPgg3azAy2r7jZr1spVIN0qMgp5lpcDaQadsB2zEvANG31lwqprxjTR JWNwoetlIAH0xGSU/BgTOghaFBjwzA0fpTs3FRjrCsSlUnLgF8AgJfuRvhvkSyJrJ/QpC1Hgj ilCs+Sb3SWntgjtQMZySRojZkcrDrRyB8fAVFGIBgOys3EHd9b6GhnqwakUlRjIZSWzs+9Xeu H/PKJxVwKz6AvT9kl+ZH01XtCBcMVyVMS4GG2w== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dealing with 'struct timeval' users in the y2038 series is a bit tricky: We have two definitions of timeval that are visible to user space, one comes from glibc (or some other C library), the other comes from linux/time.h. The kernel copy is what we want to be used for a number of structures defined by the kernel itself, e.g. elf_prstatus (used it core dumps), sysinfo and rusage (used in system calls). These generally tend to be used for passing time intervals rather than absolute (epoch-based) times, so they do not suffer from the y2038 overflow. Some of them could be changed to use 64-bit timestamps by creating new system calls, others like the core files cannot easily be changed. An application using these interfaces likely also uses gettimeofday() or other interfaces that use absolute times, and pass 'struct timeval' pointers directly into kernel interfaces, so glibc must redefine their timeval based on a 64-bit time_t when they introduce their y2038-safe interfaces. The only reasonable way forward I see is to remove the 'timeval' definion from the kernel's uapi headers, and change the interfaces that we do not want to (or cannot) duplicate for 64-bit times to use a new __kernel_old_timeval definition instead. This type should be avoided for all new interfaces (those can use 64-bit nanoseconds, or the 64-bit version of timespec instead), and should be used with great care when converting existing interfaces from timeval, to be sure they don't suffer from the y2038 overflow, and only with consensus for the particular user that using __kernel_old_timeval is better than moving to a 64-bit based interface. The structure name is intentionally chosen to not conflict with user space types, and to be ugly enough to discourage its use. Note that ioctl based interfaces that pass a bare 'timeval' pointer cannot change to '__kernel_old_timeval' because the user space source code refers to 'timeval' instead, and we don't want to modify the user space sources if possible. However, any application that relies on a structure to contain an embedded 'timeval' (e.g. by passing a pointer to the member into a function call that expects a timeval pointer) is broken when that structure gets converted to __kernel_old_timeval. I don't see any way around that, and we have to rely on the compiler to produce a warning or compile failure that will alert users when they recompile their sources against a new libc. Signed-off-by: Arnd Bergmann --- include/linux/time32.h | 1 + include/uapi/linux/time.h | 12 ++++++++++++ kernel/time/time.c | 12 ++++++++++++ 3 files changed, 25 insertions(+) -- 2.9.0 diff --git a/include/linux/time32.h b/include/linux/time32.h index 100411c979be..378c75d9a83c 100644 --- a/include/linux/time32.h +++ b/include/linux/time32.h @@ -205,5 +205,6 @@ static inline s64 timeval_to_ns(const struct timeval *tv) * Returns the timeval representation of the nsec parameter. */ extern struct timeval ns_to_timeval(const s64 nsec); +extern struct __kernel_old_timeval ns_to_kernel_old_timeval(const s64 nsec); #endif diff --git a/include/uapi/linux/time.h b/include/uapi/linux/time.h index 0ad4510884b0..30aa734135ad 100644 --- a/include/uapi/linux/time.h +++ b/include/uapi/linux/time.h @@ -50,6 +50,18 @@ struct __kernel_timespec { #endif /* + * legacy timeval structure, only embedded in structures that + * traditionally used 'timeval' to pass time intervals (not absolute + * times). Do not add new users. If user space fails to compile + * here, this is probably because it is not y2038 safe and needs to + * be changed to use another interface. + */ +struct __kernel_old_timeval { + __kernel_long_t tv_sec; /* seconds */ + __kernel_long_t tv_usec; /* seconds */ +}; + +/* * The IDs of the various system clocks (for POSIX.1b interval timers): */ #define CLOCK_REALTIME 0 diff --git a/kernel/time/time.c b/kernel/time/time.c index 518b56b17147..92002257f083 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -486,6 +486,18 @@ struct timeval ns_to_timeval(const s64 nsec) } EXPORT_SYMBOL(ns_to_timeval); +struct __kernel_old_timeval ns_to_kernel_old_timeval(const s64 nsec) +{ + struct timespec64 ts = ns_to_timespec64(nsec); + struct __kernel_old_timeval tv; + + tv.tv_sec = ts.tv_sec; + tv.tv_usec = (suseconds_t) ts.tv_nsec / 1000; + + return tv; +} +EXPORT_SYMBOL(ns_to_kernel_old_timeval); + /** * set_normalized_timespec - set timespec sec and nsec parts and normalize * From patchwork Mon Nov 27 17:00:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 119759 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp542017qgn; Mon, 27 Nov 2017 09:03:17 -0800 (PST) X-Google-Smtp-Source: AGs4zMawRJUxfO1eXTdcmcB4kSUHVw5ch4XMzGTjZdEz9z8u2EwQiz+MYOQVsktcBlqe/5wBSHKi X-Received: by 10.99.176.76 with SMTP id z12mr25250232pgo.358.1511802197203; Mon, 27 Nov 2017 09:03:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511802197; cv=none; d=google.com; s=arc-20160816; b=pElTq2mndUmxWpD2FEMjP1HO39v8YQHdPYRUtzncMJym7lFhlyDMqOGaEILnCFpCgR iOwVkLYiWdTteRonGoocT2r7N6JhizDlnQm10j//Oio7MOjIFVMFZScgZgxnd4IdIPEE c9YmJTk+jepgLynijPYKdOMGcyPXaOh7baaMYpnv5bfFoKBZunAyiXji2ZdXBnK5AFKX vp4CjGNT+9oTZAk5sjhYbRKoP3giBtSoFfiFybR8Exc/Zz1yto0AHFK36wIxLwUuJu5J L4L3VXCs1h7wqwRstsEbAHZvQ2Q4KKJjCkkeHI5j7hF9E894NNyknVFEpdjkkyEXSCgk P/7Q== 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=OamG+/8DqpFByS+ZYldSJf9u4UiWq7bNdzEV8BMxISM=; b=kXWCHTySC/7eS25FnRwMZTClOdbw1J24OWgqhBhy7/BSct19l7BLeVGgWjlWZpWNrT yBvEdQPxm0tnOqnXUm8uYgabYf3tGoY3K+urFuSQ2FuS8yKA+z7GbqEo+HXPTSx8MLBk FNe5Z/+rZSi4waocmPj+KF5nnilzhcocW/xBOGMJOMWPkRvoNJbfBTnZ4HIUYhjipDWe apSa6DvXaPuaPqSZ7neH/qS/4hdnxqBkfvthVqiPwx1tTTWCj7lkvTPQ+EOrBqMEKjRj z8KGfoYJ4foNWdWrmfVS2j3g1CeoKfo8xmQZLwz3T8atfrIOyZFNam2Z1quW+aeSBTgU KYeA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 60si24017390plb.732.2017.11.27.09.03.16; Mon, 27 Nov 2017 09:03:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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 linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753888AbdK0RDP (ORCPT + 28 others); Mon, 27 Nov 2017 12:03:15 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:57889 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753024AbdK0RDL (ORCPT ); Mon, 27 Nov 2017 12:03:11 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.145]) with ESMTPA (Nemesis) id 0MWjXP-1edz0n0oqR-00Xwgr; Mon, 27 Nov 2017 18:02:46 +0100 From: Arnd Bergmann To: John Stultz , Thomas Gleixner Cc: y2038@lists.linaro.org, libc-alpha@sourceware.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Albert ARIBAUD , Arnd Bergmann , Ralf Baechle , "James E.J. Bottomley" , Helge Deller , Alexander Viro , Greg Kroah-Hartman , Ingo Molnar , Frederic Weisbecker , Andrew Morton , Denys Vlasenko , Nicolas Pitre , Dave Martin , Mickael GUENE , linux-mips@linux-mips.org, linux-parisc@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 2/3] y2038: elfcore: use __kernel_old_timeval for process times Date: Mon, 27 Nov 2017 18:00:46 +0100 Message-Id: <20171127170121.634826-2-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171127170121.634826-1-arnd@arndb.de> References: <20171127170121.634826-1-arnd@arndb.de> X-Provags-ID: V03:K0:rpEDa9aUmmfvYKqaSMaHQ23NvD93GuXx5hKnCwcIpI23kBVnIR5 +o8BM4pjhYnGJMJWsoyqajQsO1ocI2pR1n7dTqmhqwtCgJL4Rxzc+ONJhSra0R0gn0LR9hU zZ1Nl80/JJLz3a3/vvso6J7wvuNA4ksZE+R3n98xPbZgm0PH3l9uOlnNOvznf9+2B35fcWB VPX8w5GmjaK06+cGnk7Yg== X-UI-Out-Filterresults: notjunk:1; V01:K0:qH/KOm9gvzw=:QYo8qV/MTbJZln0IAvo1c6 FdzDJEcoXMviuW6oEo9Pp97Jlo8B9LXjjf/ETBLMjo7DgUdTZzzJFRDWpm8Xl7lx7FH/CquJR 451MtsTlsSWobjvk7xsu8UzevFmZGO6pSiKeaRcECUEEwiiIIBqufZE9D/xRKIiFzHXDpWEPY nWOKxulexjHZL4WhxYzskVRMb5T8qMLAGeTXCWtZQOMRQ9I18XY6+VDhD5SFGSOj3I/7i58x8 eeH6Y27M+xwB5ZBZmP9cCDOktHFMMkdSdz0XlwVBrHk3V0rfFPcObp1Esbib6tPW9eDU+qta3 8uyhoS+y46b2LBDzqXR9B9gM5eSJAcEeBxZrG9WuO9SxlX0pX5qG+l4fGWOXlMR2AMjoCDb5n bmr5cwErEbaymcfxCbvywcQAk35c+ehqpSROsULaqoU8QNvqgZ1lv6e9epnTqhApPdiqBt2cB fXVpLD8afRGC8IQGZlcum/3CzO2u9AntpvXN7cu2n/suQYHeYAsFIDOVQlQT29NDKV9edl7NE wui5OI/3Z22sFfWMpPOQLZXpvmxV7ThaetlzYkCxKdqz3AuxAACI/lc3ge43xj4v6DCp4sTnR aTppKaAcZgA5qj7t3TGBsLKC5q/87uUKCFMEbcGjYtJC0RSoM0U3nLMD4vyuGDBEcPMrrVrgZ P7knRxZsN0qZCmDCCQ5HUeyFkNNSS3lOb7TT7B5nngCA3SEsTjMA7pyALt+i/yaTajSLoiATX weQysAZTnf2uA94nQc19aIq6DPAtnEnlkNPejw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We store elapsed time for a crashed process in struct elf_prstatus using 'timeval' structures. Once glibc starts using 64-bit time_t, this becomes incompatible with the kernel's idea of timeval since the structure layout no longer matches on 32-bit architectures. This changes the definition of the elf_prstatus structure to use __kernel_old_timeval instead, which is hardcoded to the currently used binary layout. There is no risk of overflow in y2038 though, because the time values are all relative times, and can store up to 68 years of process elapsed time. There is a risk of applications breaking at build time when they use the new kernel headers and expect the type to be exactly 'timeval' rather than a structure that has the same fields as before. Those applications have to be modified to deal with 64-bit time_t anyway. Signed-off-by: Arnd Bergmann --- arch/mips/kernel/binfmt_elfn32.c | 4 ++-- arch/mips/kernel/binfmt_elfo32.c | 4 ++-- arch/parisc/kernel/binfmt_elf32.c | 4 ++-- fs/binfmt_elf.c | 12 ++++++------ fs/binfmt_elf_fdpic.c | 12 ++++++------ fs/compat_binfmt_elf.c | 4 ++-- include/uapi/linux/elfcore.h | 8 ++++---- 7 files changed, 24 insertions(+), 24 deletions(-) -- 2.9.0 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c index 89b234844534..2fe2d5573289 100644 --- a/arch/mips/kernel/binfmt_elfn32.c +++ b/arch/mips/kernel/binfmt_elfn32.c @@ -100,7 +100,7 @@ jiffies_to_compat_timeval(unsigned long jiffies, struct compat_timeval *value) #undef TASK_SIZE #define TASK_SIZE TASK_SIZE32 -#undef ns_to_timeval -#define ns_to_timeval ns_to_compat_timeval +#undef ns_to_kernel_old_timeval +#define ns_to_kernel_old_timeval ns_to_compat_timeval #include "../../../fs/binfmt_elf.c" diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c index a88c59db3d48..d3c37583ef91 100644 --- a/arch/mips/kernel/binfmt_elfo32.c +++ b/arch/mips/kernel/binfmt_elfo32.c @@ -103,7 +103,7 @@ jiffies_to_compat_timeval(unsigned long jiffies, struct compat_timeval *value) #undef TASK_SIZE #define TASK_SIZE TASK_SIZE32 -#undef ns_to_timeval -#define ns_to_timeval ns_to_compat_timeval +#undef ns_to_kernel_old_timeval +#define ns_to_kernel_old_timeval ns_to_compat_timeval #include "../../../fs/binfmt_elf.c" diff --git a/arch/parisc/kernel/binfmt_elf32.c b/arch/parisc/kernel/binfmt_elf32.c index 20dfa081ed0b..ad3ea00c64f7 100644 --- a/arch/parisc/kernel/binfmt_elf32.c +++ b/arch/parisc/kernel/binfmt_elf32.c @@ -92,7 +92,7 @@ struct elf_prpsinfo32 current->thread.map_base = DEFAULT_MAP_BASE32; \ current->thread.task_size = DEFAULT_TASK_SIZE32 \ -#undef ns_to_timeval -#define ns_to_timeval ns_to_compat_timeval +#undef ns_to_kernel_old_timeval +#define ns_to_kernel_old_timeval ns_to_compat_timeval #include "../../../fs/binfmt_elf.c" diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 83732fef510d..7ae716db7d99 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1500,18 +1500,18 @@ static void fill_prstatus(struct elf_prstatus *prstatus, * group-wide total, not its individual thread total. */ thread_group_cputime(p, &cputime); - prstatus->pr_utime = ns_to_timeval(cputime.utime); - prstatus->pr_stime = ns_to_timeval(cputime.stime); + prstatus->pr_utime = ns_to_kernel_old_timeval(cputime.utime); + prstatus->pr_stime = ns_to_kernel_old_timeval(cputime.stime); } else { u64 utime, stime; task_cputime(p, &utime, &stime); - prstatus->pr_utime = ns_to_timeval(utime); - prstatus->pr_stime = ns_to_timeval(stime); + prstatus->pr_utime = ns_to_kernel_old_timeval(utime); + prstatus->pr_stime = ns_to_kernel_old_timeval(stime); } - prstatus->pr_cutime = ns_to_timeval(p->signal->cutime); - prstatus->pr_cstime = ns_to_timeval(p->signal->cstime); + prstatus->pr_cutime = ns_to_kernel_old_timeval(p->signal->cutime); + prstatus->pr_cstime = ns_to_kernel_old_timeval(p->signal->cstime); } static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p, diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index 429326b6e2e7..89717459224b 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -1362,17 +1362,17 @@ static void fill_prstatus(struct elf_prstatus *prstatus, * group-wide total, not its individual thread total. */ thread_group_cputime(p, &cputime); - prstatus->pr_utime = ns_to_timeval(cputime.utime); - prstatus->pr_stime = ns_to_timeval(cputime.stime); + prstatus->pr_utime = ns_to_kernel_old_timeval(cputime.utime); + prstatus->pr_stime = ns_to_kernel_old_timeval(cputime.stime); } else { u64 utime, stime; task_cputime(p, &utime, &stime); - prstatus->pr_utime = ns_to_timeval(utime); - prstatus->pr_stime = ns_to_timeval(stime); + prstatus->pr_utime = ns_to_kernel_old_timeval(utime); + prstatus->pr_stime = ns_to_kernel_old_timeval(stime); } - prstatus->pr_cutime = ns_to_timeval(p->signal->cutime); - prstatus->pr_cstime = ns_to_timeval(p->signal->cstime); + prstatus->pr_cutime = ns_to_kernel_old_timeval(p->signal->cutime); + prstatus->pr_cstime = ns_to_kernel_old_timeval(p->signal->cstime); prstatus->pr_exec_fdpic_loadmap = p->mm->context.exec_fdpic_loadmap; prstatus->pr_interp_fdpic_loadmap = p->mm->context.interp_fdpic_loadmap; diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c index 504b3c3539dc..5df608af1306 100644 --- a/fs/compat_binfmt_elf.c +++ b/fs/compat_binfmt_elf.c @@ -51,8 +51,8 @@ #define elf_prstatus compat_elf_prstatus #define elf_prpsinfo compat_elf_prpsinfo -#undef ns_to_timeval -#define ns_to_timeval ns_to_compat_timeval +#undef ns_to_kernel_old_timeval +#define ns_to_kernel_old_timeval ns_to_compat_timeval /* * To use this file, asm/elf.h must define compat_elf_check_arch. diff --git a/include/uapi/linux/elfcore.h b/include/uapi/linux/elfcore.h index 0b2c9e16e345..baf03562306d 100644 --- a/include/uapi/linux/elfcore.h +++ b/include/uapi/linux/elfcore.h @@ -53,10 +53,10 @@ struct elf_prstatus pid_t pr_ppid; pid_t pr_pgrp; pid_t pr_sid; - struct timeval pr_utime; /* User time */ - struct timeval pr_stime; /* System time */ - struct timeval pr_cutime; /* Cumulative user time */ - struct timeval pr_cstime; /* Cumulative system time */ + struct __kernel_old_timeval pr_utime; /* User time */ + struct __kernel_old_timeval pr_stime; /* System time */ + struct __kernel_old_timeval pr_cutime; /* Cumulative user time */ + struct __kernel_old_timeval pr_cstime; /* Cumulative system time */ #if 0 long pr_instr; /* Current instruction */ #endif From patchwork Mon Nov 27 17:00:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 119761 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp544140qgn; Mon, 27 Nov 2017 09:04:37 -0800 (PST) X-Google-Smtp-Source: AGs4zMYdaBwcIUUpfSM3ZjORTQyHT+2CEvXfevto49JQLTM9MWNvl+FIQ/0RnEua8xVEk3ai8FF6 X-Received: by 10.101.93.132 with SMTP id f4mr17730427pgt.152.1511802276943; Mon, 27 Nov 2017 09:04:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511802276; cv=none; d=google.com; s=arc-20160816; b=zT7XnU8YspzDeoLxxkjlsopJtx/9dHw8olwEGjV8IOxVmYyK7tQQUTnwUe9tR5EvFw l2CUxLm6pcjjvolOF2yyETD1+io5bxV7LMGTXIAo+X0rJuRAp+whYiTz31IopS8aNhbs sEkeqqaGC+yNzoepn764//rVXFnl9eOZc8YuJB41Li7dOkOG9wySmJdV1qoI7P/jQH5c xtIfD+f68Um58X19UqpoEgSox1bzLgHQkzSdomfJFfasb1suuSVwZsvuqKDd+iy9DSHZ 5blotpalay07KEqL1XO0yipesXynP5QIhH0u65JllETfwCir+6KP6l9h6F0gYA2LthfU ELzA== 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=tXLs6TtQYodGTUiQSEa8PxQuQ86XlPcB0PDAaw+8WLc=; b=gPszk+sRDHvBGQbhjf3yXO8b0BHFf0ELRnjzqnkQM/HzhW4vXuECuy64avTlm4mSXt yd1pmCY4KgLiFZ048aWtInMyM3LEIpVjGMWrxRuYjpRba3s2lsnawTNd9I7mH3Sa5U6X G8gsOdtXDFOwd04E2P4GhuIXpp281JBWslBY1Zqb/FsrTZNbPZpH6inMk4e09tmO9NAS oKb5RWor1kQcQg7/V+kh208P2yQl999TM3IbLWuShUkmGwAp20QIVTLOdFFtYZfRTGVv A6HpsUJFONw0vyBl9Z5GNXKMXCIVWtu+aFCJfv580/hqF9XJPd6PxUZdzIXGumxQeGJ/ r7oQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 m15si4897925pgs.790.2017.11.27.09.04.36; Mon, 27 Nov 2017 09:04:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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 linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932372AbdK0REf (ORCPT + 28 others); Mon, 27 Nov 2017 12:04:35 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:53303 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932256AbdK0REa (ORCPT ); Mon, 27 Nov 2017 12:04:30 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.145]) with ESMTPA (Nemesis) id 0Mdund-1eTUcB2hW1-00PfEd; Mon, 27 Nov 2017 18:03:46 +0100 From: Arnd Bergmann To: John Stultz , Thomas Gleixner Cc: y2038@lists.linaro.org, libc-alpha@sourceware.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Albert ARIBAUD , Arnd Bergmann , Richard Henderson , Ivan Kokshaysky , Matt Turner , Al Viro , Ingo Molnar , Frederic Weisbecker , Deepa Dinamani , Greg Kroah-Hartman , "Eric W. Biederman" , Oleg Nesterov , Andrew Morton , Kirill Tkhai , linux-alpha@vger.kernel.org Subject: [PATCH 3/3] y2038: rusage: use __kernel_old_timeval for process times Date: Mon, 27 Nov 2017 18:00:47 +0100 Message-Id: <20171127170121.634826-3-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171127170121.634826-1-arnd@arndb.de> References: <20171127170121.634826-1-arnd@arndb.de> X-Provags-ID: V03:K0:jyBN2A6NDwPh/DEGRvt0YaZPAd1lG3rP7n1U2VkWIVM4VIeGKiq YvO4xRGBzZamAGmPfYfAkLcA4QmVyAn+23Qtjx2QauvZZoJLpKdM1cJwuWZwOco/fzt8tWZ xRmhI1hFPVEVa475NoeqJ4a5WdoTSVkQLUWLdtV0jX9A5jVMTpeT2K9ORV2htFH+miTMXuo 9cZs901A4UuNhH1ijfRJg== X-UI-Out-Filterresults: notjunk:1; V01:K0:kK16DXKrCMw=:MdIDOX2KxJQNgAH9TlKjgg afTI5P+j96VQ/Ygtppq510g7FFD5h4JmIomSy4ddLozQgAyFnNsF8aggzywEKcO/oAQkaPMCX QoOmZPD/3jmG0lHBbmLTA9ulpJQGMg3PSnzGsbO1ZZvlaU2pwjLqufW8+PqPpiS9xi3PUI4RQ J9LcGB9NOzvMUnAByuCy+Ep4x5RQsQ+Vo1QX9Q+924jDhRaB7Xq/69DN2kn1fwJ33SVrJBAOj k+YJudm+Fvg4U5Ik87SPA5cT0Hf+9pO1MB4bmFV1Lu+G1oCePb45h5z/dd3YjJ0B+bQnGo+9I u67Ie+mbe4u8rGNJDgvxPVY+zz5vswFiMXKbT3oQEaIh0XxIcqvmSXOuaILa5ypv5XNgYTySj 5KC2NV7hzMBgvF+Y2vJALqR+MHFk8tzLORenn7dZQ+8FemAstVB34WJ00+2Q7hk8W+KDZoh0M ZJJFdylV+5CiTUSSXvWx1O1LEkcQYP0jFRikuCn1lvHWy5rvDELXkZtew0mv/Ft6V3XGAH2nX qPB44GLSXZugh3qvYFHQFWm0TNxprWpzIoVCa7MqQrQ98jxfF8b3pP8QvyPM1/6gwbBhZL1QJ deqAIVX/s9QxlQ4iT87VKELhcmlk+/R4rrmO+42tSJmPxQo2+lLKDpRIAFwrTQBi3PXS9LOe2 HfC9/6k5xLnV7FjRG7cX74YwLvS3wqBxYEkJ1cduTImYjc0MUAjr3euvzVUGhMcy2vSP2bQym FNqwwmoH+lK8HudhEP4LaPRNIPhTtvEHEZBUaw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 'struct rusage' contains the run times of a process in 'timeval' format and is accessed through the wait4() and getrusage() system calls. This is not a problem for y2038 safety by itself, but causes an issue when the C library starts using 64-bit time_t on 32-bit architectures because the structure layout becomes incompatible. There are three possible ways of dealing with this: a) deprecate the wait4() and getrusage() system calls, and create a set of kernel interfaces based around a newly defined structure that could solve multiple problems at once, e.g. provide more fine-grained timestamps. The C library could then implement the posix interfaces on top of the new system calls. b) Extend the approach taken by the x32 ABI, and use the 64-bit native structure layout for rusage on all architectures with new system calls that is otherwise compatible. A possible problem here is that we end up with incompatible definitions of rusage between /usr/include/linux/resource.h and /usr/include/bits/resource.h c) Change the definition of struct rusage to be independent of time_t. This is the easiest change, as it does not involve new system call entry points, but it has the risk of introducing compile-time incompatibilities with user space sources that rely on the type of ru_utime and ru_stime. I'm picking approch c) for its simplicity, but I'd like to hear from others whether they would prefer a different approach. Signed-off-by: Arnd Bergmann --- arch/alpha/kernel/osf_sys.c | 2 +- include/uapi/linux/resource.h | 4 ++-- kernel/sys.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) -- 2.9.0 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c index fa1a392ca9a2..445ded2ea471 100644 --- a/arch/alpha/kernel/osf_sys.c +++ b/arch/alpha/kernel/osf_sys.c @@ -970,7 +970,7 @@ put_tv32(struct timeval32 __user *o, struct timespec64 *i) } static inline long -put_tv_to_tv32(struct timeval32 __user *o, struct timeval *i) +put_tv_to_tv32(struct timeval32 __user *o, struct __kernel_old_timeval *i) { return copy_to_user(o, &(struct timeval32){ .tv_sec = i->tv_sec, diff --git a/include/uapi/linux/resource.h b/include/uapi/linux/resource.h index cc00fd079631..74ef57b38f9f 100644 --- a/include/uapi/linux/resource.h +++ b/include/uapi/linux/resource.h @@ -22,8 +22,8 @@ #define RUSAGE_THREAD 1 /* only the calling thread */ struct rusage { - struct timeval ru_utime; /* user time used */ - struct timeval ru_stime; /* system time used */ + struct __kernel_old_timeval ru_utime; /* user time used */ + struct __kernel_old_timeval ru_stime; /* system time used */ __kernel_long_t ru_maxrss; /* maximum resident set size */ __kernel_long_t ru_ixrss; /* integral shared memory size */ __kernel_long_t ru_idrss; /* integral unshared data size */ diff --git a/kernel/sys.c b/kernel/sys.c index 83ffd7dccf23..c459e294aa9e 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -1717,8 +1717,8 @@ void getrusage(struct task_struct *p, int who, struct rusage *r) unlock_task_sighand(p, &flags); out: - r->ru_utime = ns_to_timeval(utime); - r->ru_stime = ns_to_timeval(stime); + r->ru_utime = ns_to_kernel_old_timeval(utime); + r->ru_stime = ns_to_kernel_old_timeval(stime); if (who != RUSAGE_CHILDREN) { struct mm_struct *mm = get_task_mm(p);