]> git.baikalelectronics.ru Git - kernel.git/commit
random: fix accounting race condition with lockless irq entropy_count update
authorJiri Kosina <jkosina@suse.cz>
Fri, 24 May 2013 22:55:33 +0000 (15:55 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 24 May 2013 23:22:52 +0000 (16:22 -0700)
commit98a6d2b5207aaf8d381cf5eda22bd298b64d7f96
tree773d7546880a333ccdabf72a2480a9e9aabe112e
parenta4d1b939e63183eaa3f926a98843f9cd9cde0d1c
random: fix accounting race condition with lockless irq entropy_count update

Commit a5be15fc0d86 ("random: use lockless techniques in the interrupt
path") turned IRQ path from being spinlock protected into lockless
cmpxchg-retry update.

That commit removed r->lock serialization between crediting entropy bits
from IRQ context and accounting when extracting entropy on userspace
read path, but didn't turn the r->entropy_count reads/updates in
account() to use cmpxchg as well.

It has been observed, that under certain circumstances this leads to
read() on /dev/urandom to return 0 (EOF), as r->entropy_count gets
corrupted and becomes negative, which in turn results in propagating 0
all the way from account() to the actual read() call.

Convert the accounting code to be the proper lockless counterpart of
what has been partially done by a5be15fc0d86.

Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Greg KH <greg@kroah.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/char/random.c