Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp1830rdb; Wed, 21 Feb 2024 14:49:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVDYPQD3UcKEJr5srx9ZuvpVQ+Lyagd5kdZPblTRXWOzsnRkxSvC0WxhIJNJb64bBhY8E8NpyIYEcqaH85YN498JOpTbWSxiiE0Y8D/HA== X-Google-Smtp-Source: AGHT+IFrHwGruwUNiprLXv4o9TsaGD99deGAKPfK5qG0e3vZHO9b7e80EhlbPciwl2vLUTFVPVF1 X-Received: by 2002:a05:6a20:9c8d:b0:1a0:77ef:f203 with SMTP id mj13-20020a056a209c8d00b001a077eff203mr23286350pzb.6.1708555748159; Wed, 21 Feb 2024 14:49:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708555748; cv=pass; d=google.com; s=arc-20160816; b=K+2d+I2NzKHxFZb7J2KDWvmV0wZCDFvUhakWvPQZtGuuPR2nQvJhb3wkmmeyxeSA9c y9eMh5VG4ed5lOvdDTcJezZcyIWK7m1DsY88h+9c4N0Sax2xZqpSKGelPzAVp5jyU/jn E6J2p67PDQq4wWM6V5TX7fHq8aVRKkzdWQx+QRiNpRIet9Fu7LuGR6AP4u1bECMBOBR3 VDVTuyeSvshIYrbLdV+jX4hO5LQIKH1PJqVsOSIopQ4040ocRIIxKc4h9zifwCa89dtp KE/PYBHCulaEmTtagp9Znhkg7Q/0ctdNSehEZdcTQzfYpQ+/k+SWsmQmYKoCHTEB6Vir jDVQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=es+nHfrZDawShnoBYVnJSjMsByj6jahczvdIyngmFSk=; fh=SBDxtqlB4iPhp5qQiaFBiixTpsz+dnO6jUQCfve0HHM=; b=GXWCEjT2cxMdZdQ6LWlVqO9dMZKDa3oTma0UUr2uiYTvrhZYYG2jng7DSntPo6PpRn Rq1ZvaDBdds8iE34lYnnKuC2KCYQm0Myet3v1tpKNC7FxzWlkuK52opWZZiIEPh74uKX MYlLbibjX1TC9Wcnn24E+XUzb3h67nUrmyhXxTanDpws59iBy4h2V2mnTKe9qQl05yIz vT0q/idoY9zQ1xXsXhRD8eycjkZDb3BkhtzTMT9igS9MaVWI0hzw34ZZXsKm4r22D/4j fFbh1tsAzT+3ebMtibdbq6M0GCHGxeHxgdIS2W+vg4tZgR2wV6Vlw6yx1DD06it1MUgv Xodw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Hfx2vUG+; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-75614-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75614-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id z1-20020aa78881000000b006e479696179si4268361pfe.325.2024.02.21.14.49.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 14:49:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75614-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Hfx2vUG+; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-75614-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75614-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C63ADB2478E for ; Wed, 21 Feb 2024 22:47:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D814F12B150; Wed, 21 Feb 2024 22:47:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Hfx2vUG+" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FC3A3EA92 for ; Wed, 21 Feb 2024 22:47:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708555656; cv=none; b=phmO55qvco+m/ooqGFur+ScastyBoJBWv3gKUbiFk7DTwkNRCEKw8gcqkZJ423orzPkxhwsWH7Vd4nlWT9SMqhN3VqFTiqd5gCPiIgNL+Y9z/q298sR2FEaV0TPMtxOIkwdbqKHko9CBMp2fx72y8Rq6I3HCLFOahwhEm3ZGzC4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708555656; c=relaxed/simple; bh=RuvAyZ6Ue4BESfM0SbafCLF33EGwJftc48UezQEsvd4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=s4F7TvBasXYODTYlsFwXgR6XSjuPbIweX9WZ0AZEASZjmqUr3zPJR3wIDU6BqrZfsyRvTJWhamiFSabpADCQM/PpC4KM8imLBx4eTGLMJqgK9twHzQx5ka0sRO3LnO1C3NyQllQPYvFs3tjiVXzc9+GWfSUO9GRmMu0cBA7WVcs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Hfx2vUG+; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708555641; x=1740091641; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=RuvAyZ6Ue4BESfM0SbafCLF33EGwJftc48UezQEsvd4=; b=Hfx2vUG+TmiW/WGWfaxyNcW0AbaHrlTOtuWot1DSVGH5cTweWLS1+qu5 iwdVI9LGBjW2aRoOkAQEjw69WpnHrd1LpZ8BcoTRNwZvYJw3Lf5gNGbkL VycprhIqdyxGz1NSn8jVyDxYAvC+GJ4PeILypLtG9wI2qd4/BNJRLfeX7 48tYXnlK2Dndn0fTTlBn02iQA4BC/Sgj7r8fILRpPDOJgZGs9PTjkDY5N cTK47Rf04f2D3sCxUf38iYUyAhcO+4KiXzrxFK3ccvBIBB8Q2JPUQVODN gfFGViFX7GRwORULlTJPmNP/qdvuQn+YcVo+CAOFJ1DhDtbUzfN/qylgT w==; X-IronPort-AV: E=McAfee;i="6600,9927,10991"; a="13305962" X-IronPort-AV: E=Sophos;i="6.06,176,1705392000"; d="scan'208";a="13305962" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2024 14:47:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,176,1705392000"; d="scan'208";a="36085089" Received: from remiller-mobl1.amr.corp.intel.com (HELO [10.209.48.179]) ([10.209.48.179]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2024 14:47:17 -0800 Message-ID: <7a8c04bb-214b-4031-bdd6-59dad62f88a7@intel.com> Date: Wed, 21 Feb 2024 14:47:18 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] x86/coco: Require seeding RNG with RDRAND on CoCo systems Content-Language: en-US To: "Jason A. Donenfeld" Cc: x86@kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, Borislav Petkov , =?UTF-8?Q?Daniel_P_=2E_Berrang=C3=A9?= , Dave Hansen , Elena Reshetova , "H . Peter Anvin" , Ingo Molnar , "Kirill A . Shutemov" , Theodore Ts'o , Thomas Gleixner References: <20240221123248.25570-1-Jason@zx2c4.com> From: Dave Hansen Autocrypt: addr=dave.hansen@intel.com; keydata= xsFNBE6HMP0BEADIMA3XYkQfF3dwHlj58Yjsc4E5y5G67cfbt8dvaUq2fx1lR0K9h1bOI6fC oAiUXvGAOxPDsB/P6UEOISPpLl5IuYsSwAeZGkdQ5g6m1xq7AlDJQZddhr/1DC/nMVa/2BoY 2UnKuZuSBu7lgOE193+7Uks3416N2hTkyKUSNkduyoZ9F5twiBhxPJwPtn/wnch6n5RsoXsb ygOEDxLEsSk/7eyFycjE+btUtAWZtx+HseyaGfqkZK0Z9bT1lsaHecmB203xShwCPT49Blxz VOab8668QpaEOdLGhtvrVYVK7x4skyT3nGWcgDCl5/Vp3TWA4K+IofwvXzX2ON/Mj7aQwf5W iC+3nWC7q0uxKwwsddJ0Nu+dpA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EiVfL/Zjdg5VWiF9LL7iS+9hTeVdR09vThQ/DhVbCNxVk+DtyBHsjOKifrVsYep WpRGBIAu3bK8eXtyvrw1igWTNs2wazJ71+0z2jMzbclKAyRHKU9JdN6Hkkgr2nPb561yjcB8 sIq1pFXKyO+nKy6SZYxOvHxCcjk2fkw6UmPU6/j/nQlj2lfOAgNVKuDLothIxzi8pndB8Jju KktE5HJqUUMXePkAYIxEQ0mMc8Po7tuXdejgPMwgP7x65xtfEqI0RuzbUioFltsp1jUaRwQZ MTsCeQDdjpgHsj+P2ZDeEKCbma4m6Ez/YWs4+zDm1X8uZDkZcfQlD9NldbKDJEXLIjYWo1PH hYepSffIWPyvBMBTW2W5FRjJ4vLRrJSUoEfJuPQ3vW9Y73foyo/qFoURHO48AinGPZ7PC7TF vUaNOTjKedrqHkaOcqB185ahG2had0xnFsDPlx5y In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 2/21/24 09:19, Jason A. Donenfeld wrote: > On Wed, Feb 21, 2024 at 5:55 PM Dave Hansen wrote: >> On 2/21/24 04:32, Jason A. Donenfeld wrote: >>> +__init void cc_random_init(void) >>> +{ >>> + unsigned long rng_seed[32 / sizeof(long)]; >> My only nit with this is the magic "32". >> >> Why not 16? Or 64? > 32 bytes = 256-bits = what we're targeting. Very normal thing to see > places in the RNG, used all over random.c and lots of platform > drivers. Pretty obvious and straightforward to anyone familiar with > this kind of code. Not the kind of thing you'd want to replace with > some abstracted constant that makes you search. OK, so we're trying to get 256 bits of seed data from RDRAND? There's an entire section of the Intel whitepaper[1]: "Generating Seeds from RDRAND". It describes one "method of turning 512 128-bit samples from the DRNG into a 128-bit seed value". I was naively thinking that if the kernel wants 256 bits of seed data from RDRAND, it might take 2*(512 128-bit samples). I'm not suggesting that we use the exact construction from that whitepaper, but I'm reasonably sure I could actually explain to someone where a magic 1024 came from. I also went through a smattering of add_device_randomness() users. I didn't see much of a pattern there that seemed to line up with a 256-bits convention. If anything they seemed to just use what they had laying around. I saw byte counts of 16, 21, 12, 8, 1, strlen(), 56. But no pattern I could discern. Did you mean something different by "platform drivers"? If we're going to have arch/x86-specific crud, it would be great to make it obvious and straightforward to those of us simple folk that are familiar with arch/x86 code. 1. https://www.intel.com/content/www/us/en/developer/articles/guide/intel-digital-random-number-generator-drng-software-implementation-guide.html