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: 102149 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp354428qgy; Fri, 17 Jun 2016 08:58:40 -0700 (PDT) X-Received: by 10.157.7.162 with SMTP id 31mr2299806oto.129.1466179120414; Fri, 17 Jun 2016 08:58:40 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r18si16117331otc.169.2016.06.17.08.58.40 for ; Fri, 17 Jun 2016 08:58:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org 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-arn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pS Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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(-) -- 2.9.0 -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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;