From: Patrick Steinhardt <ps@pks.im>
To: Junio C Hamano <gitster@pobox.com>
Cc: "brian m. carlson" <sandals@crustytoothpaste.net>,
Ramsay Jones <ramsay@ramsayjones.plus.com>,
GIT Mailing-list <git@vger.kernel.org>,
Adam Dinwoodie <git@dinwoodie.org>
Subject: Re: [PATCH 12/12] config.mak.uname: add a note about CSPRNG_METHOD for Linux
Date: Wed, 19 Mar 2025 14:30:04 +0100 [thread overview]
Message-ID: <Z9rG3JVA5vSoYynt@pks.im> (raw)
In-Reply-To: <xmqqr02wbtdn.fsf@gitster.g>
On Sun, Mar 16, 2025 at 01:41:40PM -0700, Junio C Hamano wrote:
> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
>
> > When arc4random was added to glibc, the Linux kernel CSPRNG maintainer
> > argued that it was not a secure approach (I disagree), and convinced the
> > glibc maintainers to just make it a wrapper around the Linux kernel
> > CSPRNG, which it now is. So there's no actual benefit to calling
> > arc4random versus getrandom, and since it's newer and less commonly
> > available than getrandom, as well as slightly slower (because of an
> > extra function call), getrandom should be preferred.
>
> This
>
> https://www.phoronix.com/news/GNU-Glibc-arc4random-Functions
>
> was the first hit of my search in the area, but I think you are
> referring to
>
> https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=eaad4f9
>
> that happened 5 days after the thing got in and the code there tells
> me that your summary of the situation is quite accurate.
>
> So I agree that dropping this patch makes sense, but do we want to
> do a bit more to improve the situation?
>
> Here is an attempt to improve what we have in Makefile (and possibly
> the Linux section in config.mak.uname, but that is improving what we
> do not have) to tell folks that arc4random in glibc is only for
> compatibility and they should pick getrandom() until the situation
> changes.
>
> --- >8 ---
> Subject: config/Makefile: a note on CSPRNG_METHOD choice for Linux
>
> arc4random() was added to glibc in July 2022, but quickly replaced
> by a stub implementation that wraps around getrandom(). Hence there
> is no actual benefit to calling arc4random() over getrandom() on
> glibc based systems, at least for now.
>
> To avoid enticing Linux users to choose arc4random(), leave a note
> that their arc4random() in glibc is not the same as what their
> friends use on other platforms, and guide them to use getrandom()
> instead in the meantime.
Makes me wonder whether we should also change the order in which Meson
auto-detects functions. That is, do we want the following patch that
favors getrandom over arc4random?
Patrick
diff --git a/meson.build b/meson.build
index d6e27b236fa..501b2becabb 100644
--- a/meson.build
+++ b/meson.build
@@ -1481,15 +1481,15 @@ endif
# Backends are ordered to reflect our preference for more secure and faster
# ones over the ones that are less so.
-if csprng_backend in ['auto', 'arc4random'] and compiler.has_header_symbol('stdlib.h', 'arc4random_buf', required: csprng_backend == 'arc4random')
+if csprng_backend in ['auto', 'getrandom'] and compiler.has_header_symbol('sys/random.h', 'getrandom', required: csprng_backend == 'getrandom')
+ libgit_c_args += '-DHAVE_GETRANDOM'
+ csprng_backend = 'getrandom'
+elif csprng_backend in ['auto', 'arc4random'] and compiler.has_header_symbol('stdlib.h', 'arc4random_buf', required: csprng_backend == 'arc4random')
libgit_c_args += '-DHAVE_ARC4RANDOM'
csprng_backend = 'arc4random'
elif csprng_backend in ['auto', 'arc4random_bsd'] and compiler.has_header_symbol('bsd/stdlib.h', 'arc4random_buf', required: csprng_backend == 'arc4random_bsd')
libgit_c_args += '-DHAVE_ARC4RANDOM_BSD'
csprng_backend = 'arc4random_bsd'
-elif csprng_backend in ['auto', 'getrandom'] and compiler.has_header_symbol('sys/random.h', 'getrandom', required: csprng_backend == 'getrandom')
- libgit_c_args += '-DHAVE_GETRANDOM'
- csprng_backend = 'getrandom'
elif csprng_backend in ['auto', 'getentropy'] and compiler.has_header_symbol('unistd.h', 'getentropy', required: csprng_backend == 'getentropy')
libgit_c_args += '-DHAVE_GETENTROPY'
csprng_backend = 'getentropy'
next prev parent reply other threads:[~2025-03-19 13:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-15 2:49 [PATCH 12/12] config.mak.uname: add a note about CSPRNG_METHOD for Linux Ramsay Jones
2025-03-16 0:28 ` brian m. carlson
2025-03-16 20:41 ` Junio C Hamano
2025-03-16 21:57 ` Ramsay Jones
2025-03-19 13:30 ` Patrick Steinhardt [this message]
2025-03-20 1:28 ` Ramsay Jones
2025-03-20 5:20 ` Patrick Steinhardt
2025-03-20 16:41 ` Ramsay Jones
2025-03-16 21:51 ` Ramsay Jones
2025-03-16 23:52 ` brian m. carlson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z9rG3JVA5vSoYynt@pks.im \
--to=ps@pks.im \
--cc=git@dinwoodie.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=ramsay@ramsayjones.plus.com \
--cc=sandals@crustytoothpaste.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).