#include #include #include #include #include "rnd.h" static int fd_rnd = -1; static void randombytes(unsigned char *x, unsigned long long xlen) { int ret; if (fd_rnd == -1) { for (;;) { fd_rnd = open("/dev/urandom", O_RDONLY); if (fd_rnd != -1) break; sleep(1); } } while (xlen > 0) { if (xlen < 1048576) ret = xlen; else ret = 1048576; ret = read(fd_rnd, x, ret); if (ret < 1) { sleep(1); continue; } x += ret; xlen -= ret; } } /* Note: it's not really secure, but the name only suggests it's better to use * than rand(3) when transferring bytes over the network in non-security * critical structure members. secrand() is only used to fill up salts actually. */ int secrand(void) { int ret; randombytes((void *) &ret, sizeof(ret)); return ret; } git.cgi/linux/net-next.git/'>net-next.git
net-next plumbingsTobias Klauser
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@ozlabs.org>2016-10-21 20:04:17 +1100
committerMichael Ellerman <mpe@ellerman.id.au>2016-10-24 19:29:47 +1100
commit09b7e37b18eecc1e347f4b1a3bc863f32801f634 (patch)
treea4dec55defb910ad1d1823c8750a45e2e8f40fbf
parent56c46222af0d09149fadec2a3ce9d4889de01cc6 (diff)
powerpc/64: Fix race condition in setting lock bit in idle/wakeup code
This fixes a race condition where one thread that is entering or leaving a power-saving state can inadvertently ignore the lock bit that was set by another thread, and potentially also clear it. The core_idle_lock_held function is called when the lock bit is seen to be set. It polls the lock bit until it is clear, then does a lwarx to load the word containing the lock bit and thread idle bits so it can be updated. However, it is possible that the value loaded with the lwarx has the lock bit set, even though an immediately preceding lwz loaded a value with the lock bit clear. If this happens then we go ahead and update the word despite the lock bit being set, and when called from pnv_enter_arch207_idle_mode, we will subsequently clear the lock bit. No identifiable misbehaviour has been attributed to this race. This fixes it by checking the lock bit in the value loaded by the lwarx. If it is set then we just go back and keep on polling. Fixes: b32aadc1a8ed ("powerpc/powernv: Fix race in updating core_idle_state") Cc: stable@vger.kernel.org # v4.2+ Signed-off-by: Paul Mackerras <paulus@ozlabs.org> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>