Skip to contentSkip to conversation

getrandom02: relax check for returned data

PATCH Superseded Jan Stancek 2 participants 3 messages Feb 8, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 getrandom02: relax check for returned data

"nb * 0.1" can easily fail for nb < 20, since all we need are 2 identical bytes. Worst case (nb == 19) is almost identical to "birthday problem", but with smaller pool. Chance of hitting 2 identical bytes in pool of 19 is close to 50%.

Adjust formula to allow small repetitions in small pools. Chance we fail now should be pretty unlikely, ~10^-16.

---
 testcases/kernel/syscalls/getrandom/getrandom02.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/syscalls/getrandom/getrandom02.c +1 -1
index 0ac8bd28aed0..ec19f0fb32c5 100644
@@ -83,7 +83,7 @@ static int check_content(int nb)
 
 	memset(table, 0, sizeof(table));
 
-	max = nb * 0.10;
+	max = 6 + nb * 0.2;
 
 	for (i = 0; i < nb; i++) {
 		index = buf[i];
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v2 1/1 getrandom02: relax check for returned data

Hi!

Quoted 10 lines

"nb * 0.1" can easily fail for nb < 20, since all we need are 2 identical bytes. Worst case (nb == 19) is almost identical to "birthday problem", but with smaller pool. Chance of hitting 2 identical bytes in pool of 19 is close to 50%.

Adjust formula to allow small repetitions in small pools. Chance we fail now should be pretty unlikely, ~10^-16.

Acked.

Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH v2 1/1 getrandom02: relax check for returned data

----- Original Message -----

Quoted 13 lines

From: "Cyril Hrubis" <[email protected]>
To: "Jan Stancek" <[email protected]>
Cc: [email protected]
Sent: Wednesday, 8 February, 2017 3:12:51 PM
Subject: Re: [PATCH v2] getrandom02: relax check for returned data

Hi!

Quoted 6 lines

"nb * 0.1" can easily fail for nb < 20, since all we need are 2 identical bytes. Worst case (nb == 19) is almost identical to "birthday problem", but with smaller pool. Chance of hitting 2 identical bytes in pool of 19 is close to 50%.

Quoted 6 lines
Quoted 4 lines

Adjust formula to allow small repetitions in small pools. Chance we fail now should be pretty unlikely, ~10^-16.

Acked.

Pushed.

Regards,
Jan

Quoted 5 lines

--
Cyril Hrubis
[email protected]