Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Mar 2020 17:05:55 -0700
From:      John Baldwin <jhb@FreeBSD.org>
To:        Ian Lepore <ian@freebsd.org>, Conrad Meyer <cem@FreeBSD.org>, src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r359053 - head/sys/kern
Message-ID:  <c1f41292-c83a-2f79-66e4-394ed94d448a@FreeBSD.org>
In-Reply-To: <047c4edb4ff9fa6c40be6492c2f082e374f7a941.camel@freebsd.org>
References:  <202003172227.02HMRHLM086023@repo.freebsd.org> <047c4edb4ff9fa6c40be6492c2f082e374f7a941.camel@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <rfraile AT rfraile.eu>
>>   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?

-- 
John Baldwin



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?c1f41292-c83a-2f79-66e4-394ed94d448a>