git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] reftable/stack: accept insecure random bytes

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 7, 2025, 21:03 UTC
Message-ID
<xmqqv7uqqqu9.fsf@gitster.g>
In-Reply-To
<xmqqzfk2qr62.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 12 quoted lines
> Yet a platform replaces it with a function that returns an error or
> aborts?  What kind of nonsense is that?  Do we really need to cater
> to such an insanity?
>
> Use of git_rand() here goes backwards against the more recent trend
> in reftable/ directory to wean the code off of the rest of Git by
> getting rid of unnecessary dependency, doesn't it?
>
> I think [PATCH 1/2] makes sense regardless, though.  But shouldn't
> we be pushing back this step, with "fix your rand(3)"?
>
> Thanks.

Ah, I misread the patch. It has two hunks, and what I said applies to the earlier one, but the later one is already contaminated with git_rand(), and that is what is failing, i.e. it is not a nonsense platform replacing rand() with something that can fail.

It may still make sense to drop the first hunk, and consider how to proceed when you further want to reduce the unnecessary dependencies for external users of the reftable library, though. Are there correctness implications if git_rand() in format_name() yields non random results (like, always using "rnd = 0" instead of calling git_rand())? I seriously hope not. And if there is no correctness implications, perhaps we can replace it with rand() or even constant "0"?

Thanks.
Show 28 quoted lines
>> Reported-by: Randall S. Becker <rsbecker@nexbridge.com>
>> Signed-off-by: Patrick Steinhardt <ps@pks.im>
>> ---
>>  reftable/stack.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/reftable/stack.c b/reftable/stack.c
>> index 6d0aa774e7e29d5366ed55df19725944f8eef792..572a74e00f9ed6040534e060652e72c26641749d 100644
>> --- a/reftable/stack.c
>> +++ b/reftable/stack.c
>> @@ -493,7 +493,7 @@ static int reftable_stack_reload_maybe_reuse(struct reftable_stack *st,
>>  		close(fd);
>>  		fd = -1;
>>  
>> -		delay = delay + (delay * rand()) / RAND_MAX + 1;
>> +		delay = delay + (delay * git_rand(CSPRNG_BYTES_INSECURE)) / UINT32_MAX + 1;
>>  		sleep_millisec(delay);
>>  	}
>>  
>> @@ -659,7 +659,7 @@ int reftable_stack_add(struct reftable_stack *st,
>>  static int format_name(struct reftable_buf *dest, uint64_t min, uint64_t max)
>>  {
>>  	char buf[100];
>> -	uint32_t rnd = (uint32_t)git_rand(0);
>> +	uint32_t rnd = git_rand(CSPRNG_BYTES_INSECURE);
>>  	snprintf(buf, sizeof(buf), "0x%012" PRIx64 "-0x%012" PRIx64 "-%08x",
>>  		 min, max, rnd);
>>  	reftable_buf_reset(dest);
Previous: Junio C HamanoNext: Patrick Steinhardt
Message 8 of 19 in “reftable/stack: stop dying on exhausted entropy pool”
  1. 0/2 reftable/stack: stop dying on exhausted entropy poolPatrick Steinhardt, Jan 7, 2025
  2. 1/2 wrapper: allow generating insecure random bytesPatrick Steinhardt, Jan 7, 2025
  3. 2/2 reftable/stack: accept insecure random bytesPatrick Steinhardt, Jan 7, 2025
  4. rsbecker@nexbridge.comJan 7, 2025
  5. Junio C HamanoJan 7, 2025
  6. rsbecker@nexbridge.comJan 7, 2025
  7. Junio C HamanoJan 7, 2025
  8. Junio C HamanoJan 7, 2025
  9. Patrick SteinhardtJan 8, 2025
  10. Junio C HamanoJan 8, 2025
  11. Patrick SteinhardtJan 8, 2025
  12. Junio C HamanoJan 8, 2025
  13. Patrick SteinhardtJan 8, 2025
  14. rsbecker@nexbridge.comJan 7, 2025
  15. brian m. carlsonJan 7, 2025
  16. rsbecker@nexbridge.comJan 7, 2025
  17. Patrick SteinhardtJan 8, 2025
  18. rsbecker@nexbridge.comJan 8, 2025
  19. brian m. carlsonJan 8, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.