From owner-svn-src-head@freebsd.org Wed Mar 18 20:36:34 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 3C5AD26C0EF; Wed, 18 Mar 2020 20:36:34 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (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 48jMJd58qTz4Ddj; Wed, 18 Mar 2020 20:36:33 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id 02IKaIjU018685 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Wed, 18 Mar 2020 22:36:21 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 02IKaIjU018685 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id 02IKaIC1018684; Wed, 18 Mar 2020 22:36:18 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 18 Mar 2020 22:36:18 +0200 From: Konstantin Belousov To: Ian Lepore Cc: John Baldwin , Conrad Meyer , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r359053 - head/sys/kern Message-ID: <20200318203618.GF1992@kib.kiev.ua> References: <202003172227.02HMRHLM086023@repo.freebsd.org> <047c4edb4ff9fa6c40be6492c2f082e374f7a941.camel@freebsd.org> <96b14f0cff17b3367e3428dbcdc1bf12d7ab7356.camel@freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <96b14f0cff17b3367e3428dbcdc1bf12d7ab7356.camel@freebsd.org> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on tom.home X-Rspamd-Queue-Id: 48jMJd58qTz4Ddj X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-2.07 / 15.00]; REPLY(-4.00)[]; NEURAL_SPAM_LONG(0.97)[0.970,0]; NEURAL_SPAM_MEDIUM(0.96)[0.962,0] 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 20:36:34 -0000 On Tue, Mar 17, 2020 at 07:25:01PM -0600, Ian Lepore wrote: > 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 notG > > > > 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. I think that a large simplification can come from the random driver initializing the boot_id variable immediately before setting things so that is_random_seeded() start returning true. But even this might be too complex, Why not copy the value from the boottime on boot, and not ever touch it after.