X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8F1C3858C2D
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1706420759;
	bh=+BRefCJcxo39lUT+Cg1mYDYrNSSALrdYTtS34FmkAjA=;
	h=Date:To:Cc:Subject:In-Reply-To:References:List-Id:
	 List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe:
	 From:Reply-To:From;
	b=aZHA98PCXc4luyBZNkHfTpe6uuRIIEbnXPsVtJSV7AhcKd/8C/PuHW7yPRKFDzKwd
	 MfAWQwp1A92P17QniEyy5yYke3Fy2ENzpo01C01PqzfZ8kaA/YzbbTWBkBPQozX2Vj
	 9TEV7r8+5HmpQtluvnKvt2tBCVrdg6WKj9VuN6jo=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 357303858D28
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 357303858D28
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706420732; cv=none;
 b=XgnvWia7OIPwcZhEJArXv+ypI77W/DcJWUcsRzjAbPAq2O6rQjltjoyxuFm2nSNTxoNWoHDkD+f4FeODCzoNdbD37cJk+Z0IgpXU7FHE1H/8z0EQ8pRV0/6vRQRXn80cd9TPFWULBc0J0f4PDgczgbkshaPVrIULEA/YUJkcbk0=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
 t=1706420732; c=relaxed/simple;
 bh=UtAtcWAaymCXF2TU1QOaKsBHJ9fz8sYm3WIaZ7r+Jp0=;
 h=DKIM-Signature:Date:To:From:Subject:Message-ID:MIME-Version;
 b=sG8Kdsk3XhBC51I7bwUIHIzD2AkaKEOWITgafY09EaM/iF5rERcsItuInuulgXDu3SAJY6Lky1fUx6M9OJqO9FH/QFhddQIm2SfnmbqJt8PtLOTIqIHRssV4KjjmpgaWtdgVQN2VoBkOEyyAFDGxWGH7X7PMbYJ3ryfHmzyPJ0I=
ARC-Authentication-Results: i=1; server2.sourceware.org
Date: Sun, 28 Jan 2024 05:45:11 +0000
To: Glenn Strauss <gs-cygwin.com@gluelogic.com>
Cc: cygwin@cygwin.com
Subject: Re: arc4random does not reseed after using fork()
Message-ID: <B_5chRHpRPev3w3hvJQIMNpOxXcLRhlic7PFJxCVEgBb_PHb9aYDoOTrKNQVkjhkF19Z-F3eFDzkGs5OqANhPu4oud6B5x3QFGk9RHHKPzI=@protonmail.com>
In-Reply-To: <ZbRFO6gtx0XHMZ5k@xps13>
References: <ZbRFO6gtx0XHMZ5k@xps13>
Feedback-ID: 1750573:user:proton
MIME-Version: 1.0
X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00, DKIM_SIGNED,
 DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_MSPIKE_H5,
 RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP,
 T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
 server2.sourceware.org
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.30
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Johnothan King via Cygwin <cygwin@cygwin.com>
Reply-To: Johnothan King <johnothanking@protonmail.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cygwin-bounces+archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>

> FYI: There was a thread in Nov 2023 about rand() which might be related.
> 
> rand is not ISO C compliant in Cygwin
> https://cygwin.com/pipermail/cygwin/2023-November/254735.html
> 
> conclusion of that thread:
> https://cygwin.com/pipermail/cygwin/2023-November/254764.html

I don't think that has much relevance here, as this is regarding
arc4random's seed after a fork, not rand's behavior in threads.
In any case I think I have found the cause of the bug. In
arc4random.c, _rs_stir_if_needed() attempts to detect a fork by
calling _rs_forkdetect(), which is located in arc4random.h. However,
that function is nothing more than a stub:
   static inline void
   _rs_forkdetect(void)
   {
   #ifdef _ARC4RANDOM_FORKDETECT
   	_ARC4RANDOM_FORKDETECT();
   #endif
   }
If _ARC4RANDOM_FORKDETECT is defined, _rs_forkdetect will attempt to
use it for detecting if a fork occured (the LibreSSL implementation
then zeros out `rs' with 'memset(rs, 0, sizeof(*rs));'.
Yet Cygwin has no such function or macro, so _rs_forkdetect does
nothing and _rs_stir subsequently cannot reseed after a fork() occurs.

- Johnothan King

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
