summaryrefslogtreecommitdiffstats
path: root/drivers/char/random.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-07-31 15:11:00 -0400
committerTheodore Ts'o <tytso@mit.edu>2018-08-02 17:33:06 -0400
commit9a47249d444d344051c7c0e909fad0e88515a5c2 (patch)
tree00b73a9ccce98c635da8eaed3b3c081c8a3cca4d /drivers/char/random.c
parentb34fbaa9289328c7aec67d2b8b8b7d02bc61c67d (diff)
random: Make crng state queryable
It is very useful to be able to know whether or not get_random_bytes_wait / wait_for_random_bytes is going to block or not, or whether plain get_random_bytes is going to return good randomness or bad randomness. The particular use case is for mitigating certain attacks in WireGuard. A handshake packet arrives and is queued up. Elsewhere a worker thread takes items from the queue and processes them. In replying to these items, it needs to use some random data, and it has to be good random data. If we simply block until we can have good randomness, then it's possible for an attacker to fill the queue up with packets waiting to be processed. Upon realizing the queue is full, WireGuard will detect that it's under a denial of service attack, and behave accordingly. A better approach is just to drop incoming handshake packets if the crng is not yet initialized. This patch, therefore, makes that information directly accessible. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'drivers/char/random.c')
-rw-r--r--drivers/char/random.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 561082d46a82..bf5f99fc36f1 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1664,6 +1664,21 @@ int wait_for_random_bytes(void)
1664EXPORT_SYMBOL(wait_for_random_bytes); 1664EXPORT_SYMBOL(wait_for_random_bytes);
1665 1665
1666/* 1666/*
1667 * Returns whether or not the urandom pool has been seeded and thus guaranteed
1668 * to supply cryptographically secure random numbers. This applies to: the
1669 * /dev/urandom device, the get_random_bytes function, and the get_random_{u32,
1670 * ,u64,int,long} family of functions.
1671 *
1672 * Returns: true if the urandom pool has been seeded.
1673 * false if the urandom pool has not been seeded.
1674 */
1675bool rng_is_initialized(void)
1676{
1677 return crng_ready();
1678}
1679EXPORT_SYMBOL(rng_is_initialized);
1680
1681/*
1667 * Add a callback function that will be invoked when the nonblocking 1682 * Add a callback function that will be invoked when the nonblocking
1668 * pool is initialised. 1683 * pool is initialised.
1669 * 1684 *