• Jason A. Donenfeld's avatar
    random: silence compiler warnings and fix race · 4a072c71
    Jason A. Donenfeld authored
    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: b169c13d
    
    Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
    Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
    Cc: stable@vger.kernel.org
    4a072c71