From patchwork Fri Jun 17 15:59:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 9184489 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E17C0608A2 for ; Fri, 17 Jun 2016 15:58:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC03527C2C for ; Fri, 17 Jun 2016 15:58:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B026E2835E; Fri, 17 Jun 2016 15:58:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A9A027C2C for ; Fri, 17 Jun 2016 15:58:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754850AbcFQP6X (ORCPT ); Fri, 17 Jun 2016 11:58:23 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:56447 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753341AbcFQP6W (ORCPT ); Fri, 17 Jun 2016 11:58:22 -0400 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue002) with ESMTPA (Nemesis) id 0MFljh-1b8j6Y0mpR-00EetO; Fri, 17 Jun 2016 17:58:07 +0200 From: Arnd Bergmann To: Herbert Xu , "David S. Miller" Cc: y2038@lists.linaro.org, Arnd Bergmann , Stephan Mueller , Kees Cook , Alexander Kuleshov , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] crypto: use timespec64 for jent_get_nstime Date: Fri, 17 Jun 2016 17:59:41 +0200 Message-Id: <20160617155952.1021006-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:jMDcUbEEzVh7sek2TaSCYHqc+gVpI4jiTHghhHGMYDBCbl9UF0C 4gzw7+J+nm5Yw2eF2cjRcZe/AUhgRhSim0lt5zIfWFYxFy8AWHD7uxbWQ8NvEpN8dW8hxg0 vOAvVWt00MqOjYxW1bJb3GMo4xcxtFAd0hEVnYSbVzl47HZ689Ruw/j19OLNgjqLb+bIWRB FCAh254bL456F9yWoSf4Q== X-UI-Out-Filterresults: notjunk:1; V01:K0:KEripBVyhZA=:qxrUHLdGMJcyrsjiqdntfW UmLJDaS2d3jusUG/TFq980FB51nZd7CBrukos/Kb+ghzpKkEx/Cncm/t3MzC+qX+yXLUShTpL pNBJjuU5hJWyGGI2jjrFGxw9UaKDqRBSHP3rnaohCc9bg5N0kmvpZKx0xi3QNTc/9Hfsgy0NY U69w6y+11UrrL7++tb+/VgYhP173xjZOiniCN17vxdSkybHAVZyzeZnZuq7EnT7SFfr1qnu4X K/fRMyF08iXFm6SP+PlY8BzEHDOWN6BYhOlWEZd1DRdkcDkQw+lJPKUFQwLc5+C4Ewrs5YAeO gtvJ5gSgz1gaPr1LKZMlvmM5Udo8xJt+WAOT1NFPaTMbXZwXbRSxws1UtvmUZ6asllRofDqy4 xaJPEmxjpgG/bFHQXin7haPULd9ApKIkdqcqAuTUTpHPJbv0jFG1wYgGfh9Z0OpcevguGtUxn Mc4nkqTaWa2Ut54Ms9S+B+kZ6l4lM7OuW5yqaa2Xpk6ZhvcG+ZI6u8CfaFMHRQTPT5IeCYick LgmtlQdd6oF7C+mgZeeRJwKsbgohVscPwHrslxIzO5SweuBSb6Shr1HknHeSMJIcoALrVJxQc mbC2PuFyNXLCoGtFORXjJhp62HPT07lVvppCMKGXzIWHwVVB5eYR8JV6f1ywFbE+ve3z83B6H O4FQFG99NL7pHxV+bnUD5aCDwBoL69M/YN5jj8ysimWmOrvha0kfzryuMCr3aaHHjXLYAkFQ1 KywNVebC8nsoyGpS Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The jent_get_nstime() function uses __getnstimeofday() to get something similar to a 64-bit nanosecond counter. As we want to get rid of struct timespec to fix the y2038 overflow, this patch changes the code to use __getnstimeofday64() instead, which returns a timespec64 structure. Nothing changes about the algorithm, but it looks like it might be better to use *out = ts.tv_sec * NSEC_PER_SEC + ts.tv_nsec; or even *out = ktime_get_raw_fast_ns(); to get an actual nanosecond value and avoid the predictable jitter that happens at the end of a second. Checking whether or not this would be good needs investigation by someone who understands the code better than me. Signed-off-by: Arnd Bergmann --- crypto/jitterentropy-kcapi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crypto/jitterentropy-kcapi.c b/crypto/jitterentropy-kcapi.c index 597cedd3531c..82ac44eff20d 100644 --- a/crypto/jitterentropy-kcapi.c +++ b/crypto/jitterentropy-kcapi.c @@ -89,7 +89,7 @@ void jent_memcpy(void *dest, const void *src, unsigned int n) void jent_get_nstime(__u64 *out) { - struct timespec ts; + struct timespec64 ts; __u64 tmp = 0; tmp = random_get_entropy(); @@ -98,9 +98,11 @@ void jent_get_nstime(__u64 *out) * If random_get_entropy does not return a value (which is possible on, * for example, MIPS), invoke __getnstimeofday * hoping that there are timers we can work with. + * + * should we have a __ktime_get_ns() instead? */ if ((0 == tmp) && - (0 == __getnstimeofday(&ts))) { + (0 == __getnstimeofday64(&ts))) { tmp = ts.tv_sec; tmp = tmp << 32; tmp = tmp | ts.tv_nsec;