From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202606 header.b=JJa9tNEr; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 2C4FC5A0262 for ; Thu, 16 Jul 2026 09:34:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202606; t=1784187272; bh=WrTYLuKrUC4KN44CDAEsnwZcHSgZbB4KlAmKU2vFc0w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JJa9tNErpzrjLCYpwzoA/y5POL2kr8gbbjeRZcU9Mfk2mTB0o/PktmOyfCfV7g0eQ KM/IPsIp4/D5IdMP7DMKctHWXAsGXIkpE2ht+bxtq2i/4sGYqLLtfXqu75TveiMofI pMQotl7C0k95lKPZDHbPHcMSf6wM1UxdIZ03CB429io0VmVeOEbVtk4GLM4hY5Bpua 84ychrhQzG658YAqpLZ/1UCAhhSAIq/IFfjyMr8PS6RzewOVDvr5idIypUHEdS4Q/v 6YYTcJwleZ9Dq8kZc1R0kAMrBfw9iUT6JFD1HC8WLWGB60RoWyrEk42YaBVWCfgipJ bHvShqXTuz0pw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4h14Yh5xhvz4wCP; Thu, 16 Jul 2026 17:34:32 +1000 (AEST) Date: Thu, 16 Jul 2026 17:34:25 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v2 4/4] ndp: Use high quality entropy in NDP timer even if not needed Message-ID: References: <20260716072222.1819811-1-sbrivio@redhat.com> <20260716072222.1819811-5-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="AILTVZL23YAvwn8V" Content-Disposition: inline In-Reply-To: <20260716072222.1819811-5-sbrivio@redhat.com> Message-ID-Hash: RIV7R7GC2JOGSCH45P5CS7QOTJQIMXGL X-Message-ID-Hash: RIV7R7GC2JOGSCH45P5CS7QOTJQIMXGL X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --AILTVZL23YAvwn8V Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jul 16, 2026 at 09:22:22AM +0200, Stefano Brivio wrote: > ...instead of calling random(), to make static checkers happy. >=20 > I don't think that an attacker could actually gain anything by making > router advertisement intervals predictable, but a doubt remains, and > this is cheap enough that we might just want to do this to get rid of > the noise from static checkers informing us that random() shouldn't be > used. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > v2: Turn random_part to uint32_t and cast to time_t before using it, to > avoid using negative values >=20 > ndp.c | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) >=20 > diff --git a/ndp.c b/ndp.c > index 1f2bcb0..439fc0c 100644 > --- a/ndp.c > +++ b/ndp.c > @@ -413,6 +413,7 @@ void ndp_timer(const struct ctx *c, const struct time= spec *now) > { > time_t max_rtr_adv_interval =3D DEFAULT_MAX_RTR_ADV_INTERVAL; > time_t min_rtr_adv_interval, interval; > + uint32_t random_part; > =20 > if (!tap_is_ready(c) || c->no_ra || now->tv_sec < next_ra) > return; > @@ -433,15 +434,18 @@ void ndp_timer(const struct ctx *c, const struct ti= mespec *now) > * and causing flurries of RAs at the same time. > * > * This random doesn't need to be cryptographically strong, so random(3) > - * is fine. Other routers on the link also want to avoid > - * synchronisation, and anything malicious has much easier ways to cause > - * trouble. > + * would be fine. Other routers on the link also want to avoid > + * synchronisation, and anything malicious would have much easier ways > + * to cause trouble. However, for the sake of static checkers, use high > + * quality entropy as provided by raw_random(). > * > * The modulus also makes this not strictly a uniform distribution, but, > * again, it's close enough for our purposes. > */ > + raw_random(&random_part, sizeof(random_part)); > interval =3D min_rtr_adv_interval + > - random() % (max_rtr_adv_interval - min_rtr_adv_interval); > + (time_t)random_part % (max_rtr_adv_interval - > + min_rtr_adv_interval); > =20 > if (!next_ra) > goto first; > --=20 > 2.43.0 >=20 --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --AILTVZL23YAvwn8V Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmpYiXYACgkQzQJF27ox 2GcGoA/+K1LWJm6cNxR+9ShxTGOzBFNdJMT6zBG7WF2OqMwfrNPn4AT3N+HR/Bt6 zuXvXb6cET+HgB1sKpiDNFEjeulmj/9nmbr1AGUVjl14A90KMiBHnWXh65Mvv2bW NlPdKpv76W+3Kh2rNnwrBZMmcB2WJJPXqlFjXg4Ieo8QjuURTFAMo/GDQzdNmx3P Kl1uXX3CYCC7ig7mqMggTMNAkh6bnVnwnVDOXRn7fg8k4qfNTewEtJNmMzWzEmw7 Jx0BzM/9e4FtxjSjK1GCkjpbRu74fkIFHRBcl8x/IVlW5ayjSulMNr1njDzW9ugH VyXwSibbmHh+pqCB6kKATmzCUdItL5xJQCdvzz2zSt/b0Zx5DYzEy7Gwb0WoIZes FIr1DAn/vVDEclFvTWjSTNUD+shqK4XVK9/RIiPX2uM6QD+2+n+7HlYP8KpvQ+Yu QkQG1JM/naqFit5VNYq2+mK2DDUFROGpnbH4tw4tSfjOgDRaXbmoD7lgHZxdppYr k2sNOZ3t+5b9jT1Bs//ija3lCuhIKdTdFO+VBiECPrB+PVMgvMnUugSodjMZnOVV j3LNiX2afkaQohzV9lG+UlWE3vXrwaER3KUWeN5qddyfvSCt7wXubmXrApd0OPb7 E8vIaC11aYT8XZchq5SxVOCfQu+ENMwQM9jIVF7RKrqLWiMzOL0= =qtAf -----END PGP SIGNATURE----- --AILTVZL23YAvwn8V--