linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: use timespec64 for jent_get_nstime
@ 2016-06-17 15:59 Arnd Bergmann
  2016-06-18  8:16 ` Stephan Mueller
  2016-06-21  6:20 ` Stephan Mueller
  0 siblings, 2 replies; 12+ messages in thread
From: Arnd Bergmann @ 2016-06-17 15:59 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller
  Cc: y2038, Arnd Bergmann, Stephan Mueller, Kees Cook,
	Alexander Kuleshov, linux-crypto, linux-kernel

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 <arnd@arndb.de>
---
 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;
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-06-21 17:33 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-17 15:59 [PATCH] crypto: use timespec64 for jent_get_nstime Arnd Bergmann
2016-06-18  8:16 ` Stephan Mueller
2016-06-21  6:20 ` Stephan Mueller
2016-06-21  8:32   ` Arnd Bergmann
2016-06-21  8:39     ` Stephan Mueller
2016-06-21 16:22     ` [Y2038] " John Stultz
2016-06-21 16:34       ` Stephan Mueller
2016-06-21 16:47         ` John Stultz
2016-06-21 16:51           ` Stephan Mueller
2016-06-21 17:07             ` Stephan Mueller
2016-06-21 17:12             ` John Stultz
2016-06-21 17:16               ` Stephan Mueller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).