]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
random: round-robin registers as ulong, not u32
authorJason A. Donenfeld <Jason@zx2c4.com>
Tue, 22 Feb 2022 12:46:10 +0000 (13:46 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 25 Jun 2022 09:49:07 +0000 (11:49 +0200)
commit da3951ebdcd1cb1d5c750e08cd05aee7b0c04d9a upstream.

When the interrupt handler does not have a valid cycle counter, it calls
get_reg() to read a register from the irq stack, in round-robin.
Currently it does this assuming that registers are 32-bit. This is
_probably_ the case, and probably all platforms without cycle counters
are in fact 32-bit platforms. But maybe not, and either way, it's not
quite correct. This commit fixes that to deal with `unsigned long`
rather than `u32`.

Cc: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/char/random.c

index d2f308d9fb519112f0a71af643a090d65a2eedd0..cd3b37d8bb2003c8cd208302e55128b8af4b4caa 100644 (file)
@@ -1256,15 +1256,15 @@ int random_online_cpu(unsigned int cpu)
 }
 #endif
 
-static u32 get_reg(struct fast_pool *f, struct pt_regs *regs)
+static unsigned long get_reg(struct fast_pool *f, struct pt_regs *regs)
 {
-       u32 *ptr = (u32 *)regs;
+       unsigned long *ptr = (unsigned long *)regs;
        unsigned int idx;
 
        if (regs == NULL)
                return 0;
        idx = READ_ONCE(f->reg_idx);
-       if (idx >= sizeof(struct pt_regs) / sizeof(u32))
+       if (idx >= sizeof(struct pt_regs) / sizeof(unsigned long))
                idx = 0;
        ptr += idx++;
        WRITE_ONCE(f->reg_idx, idx);