• Jason A. Donenfeld's avatar
    random: silence compiler warnings and fix race · 3a182635
    Jason A. Donenfeld authored
    commit 4a072c71 upstream.
    
    Odd versions of gcc for the sh4 architecture will actually warn about
    flags being used while uninitialized, so we set them to zero. Non crazy
    gccs will optimize that out again, so it doesn't make a difference.
    
    Next, over aggressive gccs could inline the expression that defines
    use_lock, which could then introduce a race resulting in a lock
    imbalance. By using READ_ONCE, we prevent that fate. Finally, we make
    that assignment const, so that gcc can still optimize a nice amount.
    
    Finally, we fix a potential deadlock between primary_crng.lock and
    batched_entropy_reset_lock, where they could be called in opposite
    order. Moving the call to invalidate_batched_entropy to outside the lock
    rectifies this issue.
    
    Fixes: b169c13dSigned-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
    Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    3a182635
random.c 62.1 KB