Skip to contentSkip to conversation

fix typo/thinko in get_random_bytes()

PATCH Applied Luck, Tony 3 participants 5 messages Nov 16, 2011 – Nov 18, 2011 Random number driver

lore
Share & tools
lore

Luck, Tony

author
#0 lore raw

PATCH 1/1 fix typo/thinko in get_random_bytes()

If there is an architecture-specific random number generator we use it to acquire randomness one "long" at a time. We should put these random words into consecutive words in the result buffer - not just overwrite the first word again and again.

---

drivers/char/random.c +1 -1
index 63e19ba..6035ab8 100644
@@ -941,7 +941,7 @@ void get_random_bytes(void *buf, int nbytes)
 		if (!arch_get_random_long(&v))
 			break;
 		
-		memcpy(buf, &v, chunk);
+		memcpy(p, &v, chunk);
 		p += chunk;
 		nbytes -= chunk;
 	}
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Tony

If there is an architecture-specific random number generator we use it to acquire randomness one "long" at a time. We should put these random words into consecutive words in the result buffer - not just overwrite the first word again and again.

Ouch. Good catch. This, I guess, is the downside of doing this only on the kernel paths... made this kind of errors harder to catch.

Linus, do you want to take this one or should I put it in the urgent queue in tip?

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#2 lore raw
Quoted 6 lines · H. Peter Anvin
Quoted 5 lines · Tony

If there is an architecture-specific random number generator we use it to acquire randomness one "long" at a time. We should put these random words into consecutive words in the result buffer - not just overwrite the first word again and again.

Quoted 6 lines
Quoted 1 line

Ouch. Good catch. This, I guess, is the downside of doing this only on the kernel paths... made this kind of errors harder to catch.

#3 lore raw
Quoted 10 lines · Thomas Gleixner
Quoted 6 lines · H. Peter Anvin
Quoted 5 lines · Tony

If there is an architecture-specific random number generator we use it to acquire randomness one "long" at a time. We should put these random words into consecutive words in the result buffer - not just overwrite the first word again and again.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Ouch. Good catch. This, I guess, is the downside of doing this only on the kernel paths... made this kind of errors harder to catch.

Applied to x86/urgent... I'll try to get the tip-bot back online today if I can find the time.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#4 lore raw

[tip:x86/urgent] random: Fix handing of arch_get_random_long in get_random_bytes()

In reply to Luck, Tony
Commit-ID:  0d2f096b8785b67c38afcf6e1fbb9674af2e05ca
Gitweb:     http://git.kernel.org/tip/0d2f096b8785b67c38afcf6e1fbb9674af2e05ca
Author:     Luck, Tony <[email protected]>
AuthorDate: Wed, 16 Nov 2011 10:50:56 -0800
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Wed, 16 Nov 2011 16:41:02 -0800

random: Fix handing of arch_get_random_long in get_random_bytes()

If there is an architecture-specific random number generator we use it to acquire randomness one "long" at a time. We should put these random words into consecutive words in the result buffer - not just overwrite the first word again and again.

---
 drivers/char/random.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/char/random.c +1 -1
index 63e19ba..6035ab8 100644
@@ -941,7 +941,7 @@ void get_random_bytes(void *buf, int nbytes)
 		if (!arch_get_random_long(&v))
 			break;
 		
-		memcpy(buf, &v, chunk);
+		memcpy(p, &v, chunk);
 		p += chunk;
 		nbytes -= chunk;
 	}