mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] random: always fill buffer in get_random_bytes_wait
@ 2018-02-04 22:07 Jason A. Donenfeld
  2018-02-21  3:08 ` Jason A. Donenfeld
  2018-02-28 22:59 ` Theodore Ts'o
  0 siblings, 2 replies; 3+ messages in thread
From: Jason A. Donenfeld @ 2018-02-04 22:07 UTC (permalink / raw)
  To: tytso, gregkh, linux-kernel; +Cc: Jason A. Donenfeld

In the unfortunate event that a developer fails to check the return
value of get_random_bytes_wait, or simply wants to make a "best effort"
attempt, for whatever that's worth, it's much better to still fill the
buffer with _something_ rather than catastrophically failing in the case
of an interruption. This is both a defense in depth measure against
inevitable programming bugs, as well as a means of making the API a bit
more useful.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 include/linux/random.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/include/linux/random.h b/include/linux/random.h
index 4024f7d9c77d..2ddf13b4281e 100644
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -85,10 +85,8 @@ static inline unsigned long get_random_canary(void)
 static inline int get_random_bytes_wait(void *buf, int nbytes)
 {
 	int ret = wait_for_random_bytes();
-	if (unlikely(ret))
-		return ret;
 	get_random_bytes(buf, nbytes);
-	return 0;
+	return ret;
 }
 
 #define declare_get_random_var_wait(var) \
-- 
2.16.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] random: always fill buffer in get_random_bytes_wait
  2018-02-04 22:07 [PATCH] random: always fill buffer in get_random_bytes_wait Jason A. Donenfeld
@ 2018-02-21  3:08 ` Jason A. Donenfeld
  2018-02-28 22:59 ` Theodore Ts'o
  1 sibling, 0 replies; 3+ messages in thread
From: Jason A. Donenfeld @ 2018-02-21  3:08 UTC (permalink / raw)
  To: Theodore Ts'o, Greg Kroah-Hartman, LKML; +Cc: Jason A. Donenfeld

Hi Ted,

Can you apply this?

Thanks,
Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] random: always fill buffer in get_random_bytes_wait
  2018-02-04 22:07 [PATCH] random: always fill buffer in get_random_bytes_wait Jason A. Donenfeld
  2018-02-21  3:08 ` Jason A. Donenfeld
@ 2018-02-28 22:59 ` Theodore Ts'o
  1 sibling, 0 replies; 3+ messages in thread
From: Theodore Ts'o @ 2018-02-28 22:59 UTC (permalink / raw)
  To: Jason A. Donenfeld; +Cc: gregkh, linux-kernel

On Sun, Feb 04, 2018 at 11:07:46PM +0100, Jason A. Donenfeld wrote:
> In the unfortunate event that a developer fails to check the return
> value of get_random_bytes_wait, or simply wants to make a "best effort"
> attempt, for whatever that's worth, it's much better to still fill the
> buffer with _something_ rather than catastrophically failing in the case
> of an interruption. This is both a defense in depth measure against
> inevitable programming bugs, as well as a means of making the API a bit
> more useful.
> 
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

Thanks, applied.

					- Ted

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-02-28 22:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-04 22:07 [PATCH] random: always fill buffer in get_random_bytes_wait Jason A. Donenfeld
2018-02-21  3:08 ` Jason A. Donenfeld
2018-02-28 22:59 ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome