• Eric Biggers's avatar
    random: fix data race on crng init time · 009ba856
    Eric Biggers authored
    _extract_crng() does plain loads of crng->init_time and
    crng_global_init_time, which causes undefined behavior if
    crng_reseed() and RNDRESEEDCRNG modify these corrently.
    
    Use READ_ONCE() and WRITE_ONCE() to make the behavior defined.
    
    Don't fix the race on crng->init_time by protecting it with crng->lock,
    since it's not a problem for duplicate reseedings to occur.  I.e., the
    lockless access with READ_ONCE() is fine.
    
    Fixes: d848e5f8 ("random: add new ioctl RNDRESEEDCRNG")
    Fixes: e192be9d ("random: replace non-blocking pool with a Chacha20-based CRNG")
    Cc: stable@vger.kernel.org
    Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
    Acked-by: default avatarPaul E. McKenney <paulmck@kernel.org>
    Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
    009ba856
random.c 67.8 KB