From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org,
tglx@linutronix.de, arnd@arndb.de
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>,
Russell King <linux@armlinux.org.uk>
Subject: [PATCH v6 10/17] arm: use fallback for random_get_entropy() instead of zero
Date: Sat, 23 Apr 2022 23:26:16 +0200 [thread overview]
Message-ID: <20220423212623.1957011-11-Jason@zx2c4.com> (raw)
In-Reply-To: <20220423212623.1957011-1-Jason@zx2c4.com>
In the event that random_get_entropy() can't access a cycle counter or
similar, falling back to returning 0 is really not the best we can do.
Instead, at least calling random_get_entropy_fallback() would be
preferable, because that always needs to return _something_, even
falling back to jiffies eventually. It's not as though
random_get_entropy_fallback() is super high precision or guaranteed to
be entropic, but basically anything that's not zero all the time is
better than returning zero all the time.
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Russell King <linux@armlinux.org.uk>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
arch/arm/include/asm/timex.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/arm/include/asm/timex.h b/arch/arm/include/asm/timex.h
index 7c3b3671d6c2..6d1337c169cd 100644
--- a/arch/arm/include/asm/timex.h
+++ b/arch/arm/include/asm/timex.h
@@ -11,5 +11,6 @@
typedef unsigned long cycles_t;
#define get_cycles() ({ cycles_t c; read_current_timer(&c) ? 0 : c; })
+#define random_get_entropy() (((unsigned long)get_cycles()) ?: random_get_entropy_fallback())
#endif
--
2.35.1
next prev parent reply other threads:[~2022-04-23 21:27 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-23 21:26 [PATCH v6 00/17] archs/random: fallback to best raw ktime when no cycle counter Jason A. Donenfeld
2022-04-23 21:26 ` [PATCH v6 01/17] ia64: define get_cycles macro for arch-override Jason A. Donenfeld
2022-04-23 21:26 ` [PATCH v6 02/17] s390: " Jason A. Donenfeld
2022-04-23 21:26 ` [PATCH v6 03/17] parisc: " Jason A. Donenfeld
2022-04-23 21:26 ` [PATCH v6 04/17] alpha: " Jason A. Donenfeld
2022-04-23 21:26 ` [PATCH v6 05/17] powerpc: " Jason A. Donenfeld
2022-04-23 21:26 ` [PATCH v6 06/17] timekeeping: add raw clock fallback for random_get_entropy() Jason A. Donenfeld
2022-04-23 21:26 ` [PATCH v6 07/17] m68k: use fallback for random_get_entropy() instead of zero Jason A. Donenfeld
2022-04-23 21:26 ` [PATCH v6 08/17] riscv: " Jason A. Donenfeld
2022-04-23 21:26 ` [PATCH v6 09/17] mips: use fallback for random_get_entropy() instead of just c0 random Jason A. Donenfeld
2022-04-23 21:26 ` Jason A. Donenfeld [this message]
2022-04-23 21:26 ` [PATCH v6 11/17] openrisc: use fallback for random_get_entropy() instead of zero Jason A. Donenfeld
2022-04-23 21:26 ` [PATCH v6 12/17] nios2: " Jason A. Donenfeld
2022-04-23 21:26 ` [PATCH v6 13/17] x86: " Jason A. Donenfeld
2022-04-23 21:26 ` [PATCH v6 14/17] um: " Jason A. Donenfeld
2022-04-23 21:26 ` [PATCH v6 15/17] sparc: " Jason A. Donenfeld
2022-04-23 21:26 ` [PATCH v6 16/17] xtensa: " Jason A. Donenfeld
2022-04-23 21:26 ` [PATCH v6 17/17] random: insist on random_get_entropy() existing in order to simplify Jason A. Donenfeld
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220423212623.1957011-11-Jason@zx2c4.com \
--to=jason@zx2c4.com \
--cc=arnd@arndb.de \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox