Skip to content

Commit 0b4f8af

Browse files
pks-tgitster
authored andcommitted
reftable/stack: accept insecure random bytes
The reftable library uses randomness in two call paths: - When reading a stack in case some of the referenced tables disappears. The randomness is used to delay the next read by a couple of milliseconds. - When writing a new table, where the randomness gets appended to the table name (e.g. "0x000000000001-0x000000000002-0b1d8ddf.ref"). In neither of these cases do we need strong randomness. Unfortunately though, we have observed test failures caused by the former case. In t0610 we have a test that spawns a 100 processes at once, all of which try to write a new table to the stack. And given that all of the processes will require randomness, it can happen that these processes make the entropy pool run dry, which will then cause us to die: + test_seq 100 + printf %s commit\trefs/heads/branch-%s\n 68d032e9edd3481ac96382786ececc37ec28709e 1 + printf %s commit\trefs/heads/branch-%s\n 68d032e9edd3481ac96382786ececc37ec28709e 2 ... + git update-ref refs/heads/branch-98 HEAD + git update-ref refs/heads/branch-97 HEAD + git update-ref refs/heads/branch-99 HEAD + git update-ref refs/heads/branch-100 HEAD fatal: unable to get random bytes fatal: unable to get random bytes fatal: unable to get random bytes fatal: unable to get random bytes fatal: unable to get random bytes fatal: unable to get random bytes fatal: unable to get random bytes The report was for NonStop, which uses OpenSSL as the backend for randomness. In the preceding commit we have adapted that backend to also return randomness in case the entropy pool is empty and the caller passes the `CSPRNG_BYTES_INSECURE` flag. Do so to fix the issue. Reported-by: Randall S. Becker <[email protected]> Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1568d15 commit 0b4f8af

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

reftable/stack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ static int reftable_stack_reload_maybe_reuse(struct reftable_stack *st,
493493
close(fd);
494494
fd = -1;
495495

496-
delay = delay + (delay * rand()) / RAND_MAX + 1;
496+
delay = delay + (delay * git_rand(CSPRNG_BYTES_INSECURE)) / UINT32_MAX + 1;
497497
sleep_millisec(delay);
498498
}
499499

@@ -659,7 +659,7 @@ int reftable_stack_add(struct reftable_stack *st,
659659
static int format_name(struct reftable_buf *dest, uint64_t min, uint64_t max)
660660
{
661661
char buf[100];
662-
uint32_t rnd = (uint32_t)git_rand(0);
662+
uint32_t rnd = git_rand(CSPRNG_BYTES_INSECURE);
663663
snprintf(buf, sizeof(buf), "0x%012" PRIx64 "-0x%012" PRIx64 "-%08x",
664664
min, max, rnd);
665665
reftable_buf_reset(dest);

0 commit comments

Comments
 (0)