|
Lee Duncan |
923963 |
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
|
|
Lee Duncan |
923963 |
Date: Sun, 4 Feb 2018 23:07:46 +0100
|
|
Lee Duncan |
923963 |
Subject: random: always fill buffer in get_random_bytes_wait
|
|
Lee Duncan |
923963 |
Git-commit: 25e3fca492035a2e1d4ac6e3b1edd9c1acd48897
|
|
Lee Duncan |
923963 |
Patch-mainline: v4.17-rc1
|
|
Lee Duncan |
923963 |
References: git-fixes
|
|
Lee Duncan |
923963 |
|
|
Lee Duncan |
923963 |
In the unfortunate event that a developer fails to check the return
|
|
Lee Duncan |
923963 |
value of get_random_bytes_wait, or simply wants to make a "best effort"
|
|
Lee Duncan |
923963 |
attempt, for whatever that's worth, it's much better to still fill the
|
|
Lee Duncan |
923963 |
buffer with _something_ rather than catastrophically failing in the case
|
|
Lee Duncan |
923963 |
of an interruption. This is both a defense in depth measure against
|
|
Lee Duncan |
923963 |
inevitable programming bugs, as well as a means of making the API a bit
|
|
Lee Duncan |
923963 |
more useful.
|
|
Lee Duncan |
923963 |
|
|
Lee Duncan |
923963 |
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
|
|
Lee Duncan |
923963 |
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
|
|
Lee Duncan |
923963 |
Acked-by: Lee Duncan <lduncan@suse.com>
|
|
Lee Duncan |
923963 |
---
|
|
Lee Duncan |
923963 |
include/linux/random.h | 4 +---
|
|
Lee Duncan |
923963 |
1 file changed, 1 insertion(+), 3 deletions(-)
|
|
Lee Duncan |
923963 |
|
|
Lee Duncan |
923963 |
diff --git a/include/linux/random.h b/include/linux/random.h
|
|
Lee Duncan |
923963 |
index 4024f7d9c77d..2ddf13b4281e 100644
|
|
Lee Duncan |
923963 |
--- a/include/linux/random.h
|
|
Lee Duncan |
923963 |
+++ b/include/linux/random.h
|
|
Lee Duncan |
923963 |
@@ -85,10 +85,8 @@ static inline unsigned long get_random_canary(void)
|
|
Lee Duncan |
923963 |
static inline int get_random_bytes_wait(void *buf, int nbytes)
|
|
Lee Duncan |
923963 |
{
|
|
Lee Duncan |
923963 |
int ret = wait_for_random_bytes();
|
|
Lee Duncan |
923963 |
- if (unlikely(ret))
|
|
Lee Duncan |
923963 |
- return ret;
|
|
Lee Duncan |
923963 |
get_random_bytes(buf, nbytes);
|
|
Lee Duncan |
923963 |
- return 0;
|
|
Lee Duncan |
923963 |
+ return ret;
|
|
Lee Duncan |
923963 |
}
|
|
Lee Duncan |
923963 |
|
|
Lee Duncan |
923963 |
#define declare_get_random_var_wait(var) \
|
|
Lee Duncan |
923963 |
|