From owner-svn-src-all@freebsd.org Fri Nov 22 21:07:24 2019 Return-Path: Delivered-To: svn-src-all@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 F34FE1C1907; Fri, 22 Nov 2019 21:07:24 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47KTXD6B83z4G2Q; Fri, 22 Nov 2019 21:07:24 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-ot1-f42.google.com with SMTP id c19so7368249otr.11; Fri, 22 Nov 2019 13:07:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc:content-transfer-encoding; bh=h2JuILx+qaWTJFsWqiy2eaik2RRQGVThzHDlEk4AZpo=; b=RHxqlppXi+jklbCpL8r46XdHIkFoEIF9kMmCtSgUw1YzRmKw8aQFICvV4Sk/ThjV1m 6zlyIukmSJWT6WPHG/4Py6cuOBOiJM/3CJCelllt/nzMhVzkTDXX5gvyUl5RHjL5oiFi WHntqiA3f/Iw5Rt+7Rjmc9ujBZzZcehy3OOU7eVZcAplwMiNOc6cyouDUbkXAJTiTSCK ElsCRIGmR7WqSr/YzWlJzXt3R+srrpjWX5AeiByumi7j5NMcdZR5amyUEgRISJzAXZGi kInmIFP109f5cI2HgGBhLyNNJyPZpkewipZ/CfReO0NYnROuDGYdRxh7U+/UuOBBObn6 bjJg== X-Gm-Message-State: APjAAAUoZiaNnpLH2FJyAYUdHhIscI+s09AbFN3s/cHGoRNd2h6FYWse THblU3JrrPlEPGb4K0GHGXgLglya X-Google-Smtp-Source: APXvYqyj4qpGhVNnQHrf2t0/G6KQ+2YqmKi5mwJIT0pQrmOghxT9av7SpJyIB9WESpQqvZDQ8AI94Q== X-Received: by 2002:a9d:1c9a:: with SMTP id l26mr11687305ota.1.1574456842884; Fri, 22 Nov 2019 13:07:22 -0800 (PST) Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com. [209.85.167.181]) by smtp.gmail.com with ESMTPSA id m205sm2426492oif.10.2019.11.22.13.07.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Nov 2019 13:07:22 -0800 (PST) Received: by mail-oi1-f181.google.com with SMTP id y194so7766158oie.4; Fri, 22 Nov 2019 13:07:22 -0800 (PST) X-Received: by 2002:aca:1e02:: with SMTP id m2mr14117150oic.81.1574456842468; Fri, 22 Nov 2019 13:07:22 -0800 (PST) MIME-Version: 1.0 References: <201911222020.xAMKKbE0017524@repo.freebsd.org> <85EFA1CD-5093-4588-9FA4-F704DA122674@panasas.com> In-Reply-To: <85EFA1CD-5093-4588-9FA4-F704DA122674@panasas.com> Reply-To: cem@freebsd.org From: Conrad Meyer Date: Fri, 22 Nov 2019 13:07:11 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r355018 - in head/sys: dev/random sys To: Ravi Pokala Cc: src-committers , svn-src-all , svn-src-head Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 47KTXD6B83z4G2Q X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-6.00 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-0.999,0]; REPLY(-4.00)[]; TAGGED_FROM(0.00)[] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Nov 2019 21:07:25 -0000 It wasn't lost in the change. The parameters now have the names "entropy" and "len," but it is the same functionality. Best, Conrad On Fri, Nov 22, 2019 at 12:56 PM Ravi Pokala wrote: > > Hi Conrad, > > The original code did > > explicit_bzero(data, size); > > which appears to have been lost in this change. Is that intentional? If s= o, why is that okay? > > Thanks, > > Ravi (rpokala@) > > =EF=BB=BF-----Original Message----- > From: on behalf of Conrad Meyer > Date: 2019-11-22, Friday at 12:20 > To: , , > Subject: svn commit: r355018 - in head/sys: dev/random sys > > Author: cem > Date: Fri Nov 22 20:20:37 2019 > New Revision: 355018 > URL: https://svnweb.freebsd.org/changeset/base/355018 > > Log: > random(4): Abstract loader entropy injection > > Break random_harvestq_prime up into some logical subroutines. The = goal > is that it becomes easier to add other early entropy sources. > > While here, drop pre-12.0 compatibility logic. loader default conf= iguration > should preload the file as expeced since 12.0. > > Approved by: csprng(delphij, markm) > Differential Revision: https://reviews.freebsd.org/D22482 > > Modified: > head/sys/dev/random/random_harvestq.c > head/sys/sys/random.h > > Modified: head/sys/dev/random/random_harvestq.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D > --- head/sys/dev/random/random_harvestq.c Fri Nov 22 20:18:07 2019 = (r355017) > +++ head/sys/dev/random/random_harvestq.c Fri Nov 22 20:20:37 2019 = (r355018) > @@ -402,6 +402,57 @@ random_harvestq_init(void *unused __unused) > SYSINIT(random_device_h_init, SI_SUB_RANDOM, SI_ORDER_SECOND, random= _harvestq_init, NULL); > > /* > + * Subroutine to slice up a contiguous chunk of 'entropy' and feed i= t into the > + * underlying algorithm. Returns number of bytes actually fed into = underlying > + * algorithm. > + */ > +static size_t > +random_early_prime(char *entropy, size_t len) > +{ > + struct harvest_event event; > + size_t i; > + > + len =3D rounddown(len, sizeof(event.he_entropy)); > + if (len =3D=3D 0) > + return (0); > + > + for (i =3D 0; i < len; i +=3D sizeof(event.he_entropy)) { > + event.he_somecounter =3D (uint32_t)get_cyclecount(); > + event.he_size =3D sizeof(event.he_entropy); > + event.he_source =3D RANDOM_CACHED; > + event.he_destination =3D > + harvest_context.hc_destination[RANDOM_CACHED]++; > + memcpy(event.he_entropy, entropy + i, sizeof(event.he_ent= ropy)); > + random_harvestq_fast_process_event(&event); > + } > + explicit_bzero(entropy, len); > + return (len); > +} > + > +/* > + * Subroutine to search for known loader-loaded files in memory and = feed them > + * into the underlying algorithm early in boot. Returns the number = of bytes > + * loaded (zero if none were loaded). > + */ > +static size_t > +random_prime_loader_file(const char *type) > +{ > + uint8_t *keyfile, *data; > + size_t size; > + > + keyfile =3D preload_search_by_type(type); > + if (keyfile =3D=3D NULL) > + return (0); > + > + data =3D preload_fetch_addr(keyfile); > + size =3D preload_fetch_size(keyfile); > + if (data =3D=3D NULL) > + return (0); > + > + return (random_early_prime(data, size)); > +} > + > +/* > * This is used to prime the RNG by grabbing any early random stuff > * known to the kernel, and inserting it directly into the hashing > * module, currently Fortuna. > @@ -410,41 +461,19 @@ SYSINIT(random_device_h_init, SI_SUB_RANDOM, SI= _ORDER_ > static void > random_harvestq_prime(void *unused __unused) > { > - struct harvest_event event; > - size_t count, size, i; > - uint8_t *keyfile, *data; > + size_t size; > > /* > * Get entropy that may have been preloaded by loader(8) > * and use it to pre-charge the entropy harvest queue. > */ > - keyfile =3D preload_search_by_type(RANDOM_CACHED_BOOT_ENTROPY_MOD= ULE); > -#ifndef NO_BACKWARD_COMPATIBILITY > - if (keyfile =3D=3D NULL) > - keyfile =3D preload_search_by_type(RANDOM_LEGACY_BOOT_ENTROPY= _MODULE); > -#endif > - if (keyfile !=3D NULL) { > - data =3D preload_fetch_addr(keyfile); > - size =3D preload_fetch_size(keyfile); > - /* Trim the size. If the admin has a file with a funny si= ze, we lose some. Tough. */ > - size -=3D (size % sizeof(event.he_entropy)); > - if (data !=3D NULL && size !=3D 0) { > - for (i =3D 0; i < size; i +=3D sizeof(event.he_en= tropy)) { > - count =3D sizeof(event.he_entropy); > - event.he_somecounter =3D (uint32_t)get_cy= clecount(); > - event.he_size =3D count; > - event.he_source =3D RANDOM_CACHED; > - event.he_destination =3D > - harvest_context.hc_destination[RANDOM= _CACHED]++; > - memcpy(event.he_entropy, data + i, sizeof= (event.he_entropy)); > - random_harvestq_fast_process_event(&event= ); > - } > - explicit_bzero(data, size); > - if (bootverbose) > - printf("random: read %zu bytes from prelo= aded cache\n", size); > - } else > - if (bootverbose) > - printf("random: no preloaded entropy cach= e\n"); > + size =3D random_prime_loader_file(RANDOM_CACHED_BOOT_ENTROPY_MODU= LE); > + if (bootverbose) { > + if (size > 0) > + printf("random: read %zu bytes from preloaded cac= he\n", > + size); > + else > + printf("random: no preloaded entropy cache\n"); > } > } > SYSINIT(random_device_prime, SI_SUB_RANDOM, SI_ORDER_MIDDLE, random_= harvestq_prime, NULL); > > Modified: head/sys/sys/random.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D > --- head/sys/sys/random.h Fri Nov 22 20:18:07 2019 (r355017) > +++ head/sys/sys/random.h Fri Nov 22 20:20:37 2019 (r355018) > @@ -81,7 +81,6 @@ enum random_entropy_source { > _Static_assert(ENTROPYSOURCE <=3D 32, > "hardcoded assumption that values fit in a typical word-sized bi= tset"); > > -#define RANDOM_LEGACY_BOOT_ENTROPY_MODULE "/boot/entropy" > #define RANDOM_CACHED_BOOT_ENTROPY_MODULE "boot_entropy_cache" > > extern u_int hc_source_mask; > > >