From owner-svn-src-head@freebsd.org Wed Mar 18 01:25:08 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 4FE502781FE for ; Wed, 18 Mar 2020 01:25:08 +0000 (UTC) (envelope-from ian@freebsd.org) Received: from outbound3d.ore.mailhop.org (outbound3d.ore.mailhop.org [54.186.57.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 48hsm249mGz3Jv0 for ; Wed, 18 Mar 2020 01:25:06 +0000 (UTC) (envelope-from ian@freebsd.org) ARC-Seal: i=1; a=rsa-sha256; t=1584494704; cv=none; d=outbound.mailhop.org; s=arc-outbound20181012; b=XVvpbVMobtBdHsIkd5jt7eDT87R5fjfTxLJr7YovzIqENxQOLRmCr3+mm+lJODbKwf3NsoMN3OCYi Z2L7DipHOU7FXJcH5GaxjIGZEhFPqi9/BDF7kKOBUbmWtQS+ni1CNwIqkC757KsdwaVSL19Mj/5Igp /oupa+RzXy4y+62Q2Rru1d8CZcMZpKpgZUKNqfakUdyUFKFr8bHtMiYqJvBkhturA21KoI13pdyQrU wS/lsb4GdMc7PZczDjxVQoMlzedWZhCgB1v8LaBxCI/DpUrB3MMjkwG1l8qCoL9JSoJmlXWtU34BFd T6d2cTWv1R4gGGmE8XeVYec7kHvPYAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=arc-outbound20181012; h=content-transfer-encoding:mime-version:content-type:references:in-reply-to: date:to:from:subject:message-id:dkim-signature:from; bh=7PI7hl5cfNVe/SqIvpIVX3vcpQPBKk2kfGPgmS1A/kk=; b=nTqDNzJrU/Y2hhMMuIABpHu6ylgajHZH7DDjW5N/+MqKvdlOcRfyTBRrzQXIT1YyMzfPZ020/zYaw 5KbTkPQ2N59UeFap/BMe6ZCaxsNqhjWw8wrpj2gfGH8i/iEIT1H1WDox5EdEMPOSW+NY+Cu5DVtqw9 +/nj3Pju7KRRQ3zXhO4TLjjYomFEixyCfrKPL0QEhRG+kNWppLEOXOPoKxSxkHaCzJ7HhLcAFwVzJ9 XdTh+zJczSfKvVk+jtJY1QKIQiz9PPPl9mQyUnvgfr4YUIbEnQu6Gky5txCLNTADIyWRtrk2Jeaoj+ NWzVU/sRPGDboAW49gf+0cKY9dSJIqg== ARC-Authentication-Results: i=1; outbound3.ore.mailhop.org; spf=softfail smtp.mailfrom=freebsd.org smtp.remote-ip=67.177.211.60; dmarc=none header.from=freebsd.org; arc=none header.oldest-pass=0; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=dkim-high; h=content-transfer-encoding:mime-version:content-type:references:in-reply-to: date:to:from:subject:message-id:from; bh=7PI7hl5cfNVe/SqIvpIVX3vcpQPBKk2kfGPgmS1A/kk=; b=ieMozSjGLDFJdVSquebtDd/Iw40DIS24TCYhUcJSSECT5j/XvZ29MYc3OYYQHyKrqn5FJ9dY5bqRo eVnQFsju3Htf9DbmLEAyHkB3YWUJLRPpBPltcziVrNA510o49MATVMxqudOIbgo3aUm72cH2bJKhNo +F3otuCirPh9Q0UBUhv/Q7MwsW3GWUFcXICzLp4wE+zZRtkqXRTeYtovq7E+czxz2v0VPxFh99kemw wOzdBPyl4z3RknHiuqjdKrcA6+uF+BGPdFxnNow5i/LNTxVaBkz9AWZfDBG4r4TvGYDbsRS+gng45E D+nRHHoN8aHVieaK7tGYnF6M0ff6wMw== X-MHO-RoutePath: aGlwcGll X-MHO-User: 4a5346cd-68b7-11ea-b80e-052b4a66b6b2 X-Report-Abuse-To: https://support.duocircle.com/support/solutions/articles/5000540958-duocircle-standard-smtp-abuse-information X-Originating-IP: 67.177.211.60 X-Mail-Handler: DuoCircle Outbound SMTP Received: from ilsoft.org (unknown [67.177.211.60]) by outbound3.ore.mailhop.org (Halon) with ESMTPSA id 4a5346cd-68b7-11ea-b80e-052b4a66b6b2; Wed, 18 Mar 2020 01:25:03 +0000 (UTC) Received: from rev (rev [172.22.42.240]) by ilsoft.org (8.15.2/8.15.2) with ESMTP id 02I1P2OV074116; Tue, 17 Mar 2020 19:25:02 -0600 (MDT) (envelope-from ian@freebsd.org) Message-ID: <96b14f0cff17b3367e3428dbcdc1bf12d7ab7356.camel@freebsd.org> Subject: Re: svn commit: r359053 - head/sys/kern From: Ian Lepore To: John Baldwin , Conrad Meyer , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Date: Tue, 17 Mar 2020 19:25:01 -0600 In-Reply-To: References: <202003172227.02HMRHLM086023@repo.freebsd.org> <047c4edb4ff9fa6c40be6492c2f082e374f7a941.camel@freebsd.org> Content-Type: text/plain; charset="ASCII" X-Mailer: Evolution 3.28.5 FreeBSD GNOME Team Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 48hsm249mGz3Jv0 X-Spamd-Bar: + Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [1.97 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_SPAM_LONG(1.00)[0.996,0]; NEURAL_SPAM_MEDIUM(0.98)[0.976,0]; ASN(0.00)[asn:16509, ipnet:54.186.0.0/15, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Mar 2020 01:25:08 -0000 On Tue, 2020-03-17 at 17:05 -0700, John Baldwin wrote: > On 3/17/20 3:36 PM, Ian Lepore wrote: > > On Tue, 2020-03-17 at 22:27 +0000, Conrad Meyer wrote: > > > Author: cem > > > Date: Tue Mar 17 22:27:16 2020 > > > New Revision: 359053 > > > URL: https://svnweb.freebsd.org/changeset/base/359053 > > > > > > Log: > > > Implement sysctl kern.boot_id > > > > > > Boot IDs are random, opaque 128-bit identifiers that > > > distinguish distinct > > > system boots. A new ID is generated each time the system > > > boots. Unlike > > > kern.boottime, the value is not modified by NTP > > > adjustments. It remains fixed > > > until the machine is restarted. > > > > > > PR: 244867 > > > Reported by: Ricardo Fraile > > > MFC after: I do not intend to, but feel free > > > > > > Modified: > > > head/sys/kern/kern_mib.c > > > > > > Modified: head/sys/kern/kern_mib.c > > > ================================================================= > > > ============= > > > --- head/sys/kern/kern_mib.c Tue Mar 17 21:29:03 2020 ( > > > r359052) > > > +++ head/sys/kern/kern_mib.c Tue Mar 17 22:27:16 2020 ( > > > r359053) > > > @@ -448,6 +448,32 @@ SYSCTL_PROC(_kern, KERN_HOSTID, hostid, > > > CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE > > > | CTLFLAG_CAPRD, > > > NULL, 0, sysctl_hostid, "LU", "Host ID"); > > > > > > +static struct mtx bootid_lk; > > > +MTX_SYSINIT(bootid_lock, &bootid_lk, "bootid generator lock", > > > MTX_DEF); > > > + > > > +static int > > > +sysctl_bootid(SYSCTL_HANDLER_ARGS) > > > +{ > > > + static uint8_t boot_id[16]; > > > + static bool initialized = false; > > > + > > > + mtx_lock(&bootid_lk); > > > + if (!initialized) { > > > + if (!is_random_seeded()) { > > > + mtx_unlock(&bootid_lk); > > > + return (ENXIO); > > > + } > > > + arc4random_buf(boot_id, sizeof(boot_id)); > > > + initialized = true; > > > + } > > > + mtx_unlock(&bootid_lk); > > > + > > > + return (SYSCTL_OUT(req, boot_id, sizeof(boot_id))); > > > +} > > > +SYSCTL_PROC(_kern, OID_AUTO, boot_id, > > > + CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_MPSAFE | > > > CTLFLAG_CAPRD, > > > + NULL, 0, sysctl_bootid, "", "Random boot ID"); > > > + > > > /* > > > * The osrelease string is copied from the global (osrelease in > > > vers.c) into > > > * prison0 by a sysinit and is inherited by child jails if not > > > changed at jail > > > > This seems a bit complex. Why run a sysinit to init a mutex so > > that > > you can safely do a lazy init of boot_id? Seems like it would be > > much > > easier to just use a sysinit at SI_SUB_LAST to init boot_id before > > sysctl can reference it. > > Presumably you may not have enough entropy by SI_SUB_LAST to generate > it? > I thought arc4random in the kernel could provide random numbers immediately (and definitely after jitter in device attachment times at the end of kernel init)? This doesn't seem like the kind of thing that needs crypto-strength randomness. -- Ian