lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220224173948.34045-1-Jason@zx2c4.com>
Date:   Thu, 24 Feb 2022 18:39:48 +0100
From:   "Jason A. Donenfeld" <Jason@...c4.com>
To:     linux-kernel@...r.kernel.org
Cc:     "Jason A. Donenfeld" <Jason@...c4.com>,
        Theodore Ts'o <tytso@....edu>,
        Dominik Brodowski <linux@...inikbrodowski.net>
Subject: [PATCH] random: use proper cycle_t type for random_get_entropy()

random_get_entropy() returns a cycles_t, not an unsigned long, which is
sometimes 64 bits on various 32-bit platforms, including x86.
Conversely, jiffies is always unsigned long. This commit fixes things to
use cycles_t for fields that use random_get_entropy() and unsigned long
for fields that use jiffies.

Cc: Theodore Ts'o <tytso@....edu>
Cc: Dominik Brodowski <linux@...inikbrodowski.net>
Signed-off-by: Jason A. Donenfeld <Jason@...c4.com>
---
 drivers/char/random.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 19bf44b9ba0f..4e37b8e2acc1 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1002,7 +1002,7 @@ int __init rand_initialize(void)
 
 /* There is one of these per entropy source */
 struct timer_rand_state {
-	cycles_t last_time;
+	unsigned long last_time;
 	long last_delta, last_delta2;
 };
 
@@ -1016,7 +1016,7 @@ struct timer_rand_state {
  */
 void add_device_randomness(const void *buf, size_t size)
 {
-	unsigned long time = random_get_entropy() ^ jiffies;
+	cycles_t time = random_get_entropy() ^ jiffies;
 	unsigned long flags;
 
 	if (crng_init == 0 && size)
@@ -1042,8 +1042,8 @@ EXPORT_SYMBOL(add_device_randomness);
 static void add_timer_randomness(struct timer_rand_state *state, unsigned int num)
 {
 	struct {
+		cycles_t cycles;
 		long jiffies;
-		unsigned int cycles;
 		unsigned int num;
 	} sample;
 	long delta, delta2, delta3;
@@ -1356,7 +1356,7 @@ static void entropy_timer(struct timer_list *t)
 static void try_to_generate_entropy(void)
 {
 	struct {
-		unsigned long now;
+		cycles_t now;
 		struct timer_list timer;
 	} stack;
 
-- 
2.35.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ