From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 975CEC6FA83 for ; Tue, 27 Sep 2022 08:28:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84B3E8E00B7; Tue, 27 Sep 2022 04:28:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7FB028E00AF; Tue, 27 Sep 2022 04:28:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69AAB8E00B7; Tue, 27 Sep 2022 04:28:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 57B138E00AF for ; Tue, 27 Sep 2022 04:28:29 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 230411404AD for ; Tue, 27 Sep 2022 08:28:29 +0000 (UTC) X-FDA: 79957188738.20.7450E32 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf03.hostedemail.com (Postfix) with ESMTP id B50EB2000B for ; Tue, 27 Sep 2022 08:28:28 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C27A0616D9 for ; Tue, 27 Sep 2022 08:28:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D76A3C433B5 for ; Tue, 27 Sep 2022 08:28:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1664267304; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gF2B0EX39catiZugICdowKOfDfyx3TjUROolfQVqhqI=; b=Q4YS52KUu5BTFy2/9feSQ0tXR2kzgs2Z///o6YVaxJeW9gKooHCd30CLHGPwQcmNKAAmZJ I3xDj6yFp/COv/CvZbeSkFlJMHkZeXSgNUrAeu3P25akAz8lzIKIiyR8K5f98qSgf/mF/R +pZlIGj5629qBBX1COF5dhqN2eEQSSs= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id fcc08515 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 27 Sep 2022 08:28:23 +0000 (UTC) Received: by mail-vs1-f54.google.com with SMTP id j7so8927018vsr.13 for ; Tue, 27 Sep 2022 01:28:23 -0700 (PDT) X-Gm-Message-State: ACrzQf3PBX+9mrryiIL+/CySBtbva8Wt/xAtcAxX/KqUUWDU+M4un0b/ 8hGeOD5sSDODXWAazKBlmpmsURoyHoS380YZxl8= X-Google-Smtp-Source: AMsMyM6X2DSr6gttEtduc86QXGelPE6LLKNPgVbMAN95bkgM5yITN8MEKy/4Iw4i/OTaE7jkF9BrcUcaw1srErYF8T0= X-Received: by 2002:a67:c289:0:b0:398:cdc:c3ef with SMTP id k9-20020a67c289000000b003980cdcc3efmr11024734vsj.76.1664267302601; Tue, 27 Sep 2022 01:28:22 -0700 (PDT) MIME-Version: 1.0 References: <20220926213130.1508261-1-Jason@zx2c4.com> In-Reply-To: From: "Jason A. Donenfeld" Date: Tue, 27 Sep 2022 10:28:11 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/2] random: split initialization into early step and later step To: linux@dominikbrodowski.net Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, Kees Cook , Andrew Morton , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=zx2c4.com header.s=20210105 header.b=Q4YS52KU; spf=pass (imf03.hostedemail.com: domain of "SRS0=O2ZR=Z6=zx2c4.com=Jason@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=O2ZR=Z6=zx2c4.com=Jason@kernel.org"; dmarc=pass (policy=quarantine) header.from=zx2c4.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664267308; a=rsa-sha256; cv=none; b=YY4rg8HJSfQO5z3DBcv+dDR+wjsBaKkieSD+xqldp+AcUvdssk6GcqzWGkGfkoY8DDydDi J9VCQGToghdRnt5J1vnz2HeCKUoxKa48R8lLu4ufN4k3vdbpm7Q3NEPrVRZGWvDQSMhLyq 84aqGzviGnP5xMVA+QA5zYeJYtiXCKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664267308; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gF2B0EX39catiZugICdowKOfDfyx3TjUROolfQVqhqI=; b=BAlWpNATPQGpHF7PCmgZGs2XYeaVhEuy7HiZ0pGGFRATStq4pvSJ0pAE2faacJn9/AxwyW EUImhYkf2F+tu8rpXHE6mE/3hjR/Es4YkKqceU/QBYHy6LbBfln4z8dIuR2LMUgukiBCxA AymTfkEz6KZuQENIAA7+32JxP6FbCq8= Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=zx2c4.com header.s=20210105 header.b=Q4YS52KU; spf=pass (imf03.hostedemail.com: domain of "SRS0=O2ZR=Z6=zx2c4.com=Jason@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=O2ZR=Z6=zx2c4.com=Jason@kernel.org"; dmarc=pass (policy=quarantine) header.from=zx2c4.com X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: B50EB2000B X-Stat-Signature: h6s1gfcnt4qauzriytxfrj8wru3x3sb7 X-HE-Tag: 1664267308-644760 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Sep 27, 2022 at 8:35 AM Dominik Brodowski wrote: > > #if defined(LATENT_ENTROPY_PLUGIN) > > static const u8 compiletime_seed[BLAKE2S_BLOCK_SIZE] __initconst __latent_entropy; > > @@ -803,34 +798,46 @@ int __init random_init(const char *command_line) > > i += longs; > > continue; > > } > > - entropy[0] = random_get_entropy(); > > - _mix_pool_bytes(entropy, sizeof(*entropy)); > > arch_bits -= sizeof(*entropy) * 8; > > ++i; > > } > > > Previously, random_get_entropy() was mixed into the pool ARRAY_SIZE(entropy) > times. > > > +/* > > + * This is called a little bit after the prior function, and now there is > > + * access to timestamps counters. Interrupts are not yet enabled. > > + */ > > +void __init random_init(void) > > +{ > > + unsigned long entropy = random_get_entropy(); > > + ktime_t now = ktime_get_real(); > > + > > + _mix_pool_bytes(utsname(), sizeof(*(utsname()))); > > But now, it's only mixed into the pool once. Is this change on purpose? Yea, it is. I don't think it's really doing much of use. Before we did it because it was convenient -- because we simply could. But in reality mostly what we care about is capturing when it gets to that point in the execution. For jitter, the actual jitter function (try_to_generate_entropy()) is better here. However, before feeling too sad about it, remember that extract_entropy() is still filling a block with rdtsc when rdrand fails, the same way as this function was. So it's still in there anyway. Jason