Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1199975rdb; Tue, 30 Jan 2024 10:42:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IFBcFju7p2fPUIwgCrKZLAGZTyeOw7E51B0L/AHNhj/dpIlSwE3jSvcQcZRLgFM/h7kM8Lp X-Received: by 2002:a17:902:ec06:b0:1d5:8cbc:863c with SMTP id l6-20020a170902ec0600b001d58cbc863cmr2513338pld.27.1706640159383; Tue, 30 Jan 2024 10:42:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706640159; cv=pass; d=google.com; s=arc-20160816; b=nz5wqkhtdWD8bd+2goeW0YbHpQ+UPcEi+lsXDEUZph71ybCuaDjsJuJgt4sX8gpZ+B Cog0VN/ey5LE2LVFnLuPjCbPZ74ycXqGpk6zRUIw9roWnW0pRVw8nzZUm4QJv0CTBuAP hIBgDiVCCFIj2AW3ii9IHimuwk8jgC4Wm6NevD7ONh7UKl9PqUVhGdRxP3mLA9O6JFWg oEVQUf87w++CnhCmhGgZ7MJRDCVzQ5mLPbzP7gQ4r9bDFeMeqwedXjXBfsYySCDx0RoW XvrAZc/JyBFd+w/2+fmwB2+OcoU4YORCEJJAWwk448LVAtEspJ/mUSmihJ0BW3YkeU48 gYcQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:references:in-reply-to :user-agent:subject:cc:to:from:date:dkim-signature:dkim-filter; bh=LtA6AyWu9wA8RgFBYpf0xObk1vz6dfM341Zg3x5QGq0=; fh=Q0J1D5AMEJb4MRWb9meqRW38Rf+1GqYgsBVgnMUu2f8=; b=wTETbYw7JIWSHdxLh7P5W7ozdxCV6YeLFfFLa0ZEQZNc5uTbauczV1vQp8QUNYdKKP Ryy6yTdP+o7W2X8rtyosGL7PTEUlUuItk2+BnQZfzi3XqWS3hR1hTYSJj6IFFoly16Pw w81iIS8r2HyAuQp9dPqrs2FE1jZskEVngx1mEVv2+oyDdxnQ98sAM/3DSZish9WcXVq/ 9aiJL3P4w0hnfdu+WFQGXhPnhJ9+144mSY7UQmQJ4qhAd48Yy3ZgVLbuYfNrBL4x8e6B lvR0TKugPJ7B12CmYlj77pkGBNoZGp8pN6dJ+YYxVIACZjxTBCFn8qLK+m2Z1wcw+Xn4 /Mrw== ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@zytor.com header.s=2024011201 header.b=HZBrmsoW; arc=pass (i=1 spf=pass spfdomain=zytor.com dmarc=pass fromdomain=zytor.com); spf=pass (google.com: domain of linux-kernel+bounces-45127-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45127-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zytor.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 h7-20020a170902f7c700b001d8d200621dsi4413527plw.554.2024.01.30.10.42.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 10:42:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45127-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=fail header.i=@zytor.com header.s=2024011201 header.b=HZBrmsoW; arc=pass (i=1 spf=pass spfdomain=zytor.com dmarc=pass fromdomain=zytor.com); spf=pass (google.com: domain of linux-kernel+bounces-45127-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45127-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zytor.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 6CDB9B22032 for ; Tue, 30 Jan 2024 18:41:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2176C78B65; Tue, 30 Jan 2024 18:41:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b="HZBrmsoW" Received: from mail.zytor.com (terminus.zytor.com [198.137.202.136]) (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 7771078B5E for ; Tue, 30 Jan 2024 18:41:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706640076; cv=none; b=rAgilNdTOdbIM/92dQJfrKJZlpsZOrz5zn3/xLTnGy63Bt5XqyFD83PrB/aLW0GlnMXn9UNwV20M6IkQExB2kg3cOKoft/CRIkNZeIs1MHYln0qUrOaliwAPcn7c6pJiJrTSk3KF5pdBRRxeQDeBrYM2ejfSTpkA+Xa+Xzx5sR8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706640076; c=relaxed/simple; bh=FguebPSg0HUsNFSJ74ZD5+TiVpglPbVDOkutWtGbuyw=; h=Date:From:To:CC:Subject:In-Reply-To:References:Message-ID: MIME-Version:Content-Type; b=eDZipRVCoKCUzs+EQ9Ac+1JXxNbWqqiH3EV6FHDTMOvj/5m17irEwN48W5GIQUl+UKzuzkvoTa5BFVcQii7hD4+CPwKESXFjrArQIsSah5fdEE9INSlAwqjiGytV7DVObfS6eVub0w/zCZnAGCGjBvp2hv4Sxfs754ow8oBpr4M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com; spf=pass smtp.mailfrom=zytor.com; dkim=fail (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b=HZBrmsoW reason="signature verification failed"; arc=none smtp.client-ip=198.137.202.136 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zytor.com Received: from [IPv6:::1] ([172.56.208.49]) (authenticated bits=0) by mail.zytor.com (8.17.2/8.17.1) with ESMTPSA id 40UIeZF42947366 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Tue, 30 Jan 2024 10:40:37 -0800 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 40UIeZF42947366 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2024011201; t=1706640038; bh=LtA6AyWu9wA8RgFBYpf0xObk1vz6dfM341Zg3x5QGq0=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=HZBrmsoWblW/2FdH+M3Hpxl5mlwYWWb8aLRiQ7kt4LTEN8TGWLCgfdvvqODiXooKR DfsJM6lLCMnzaCv5tSpTo1s+O0HA9sYhO+1Tdiz6JSDGsz2J9ZjQaKL2amxBMx8Ymi aWw9MYCUZ9Dsgjt94Euehn6W4mnDxesGyqvBxYtZ7Jw25uUZX6GQ7FJPfItP1Iw9+B 5U6x0dDQ+fI/Q0QmubEIdADXftJ+T0kGOBIlgMjP9T/AmdbE5KUWCkLa4wmyoaWFp1 Ou1YsSa2xUROtuLKX65h2JPnR4I0T82ihMvU1XkV83NoW+4/6iSM5gmw8DGrQdbLvL 1U+gRPsRNkD6w== Date: Tue, 30 Jan 2024 10:40:24 -0800 From: "H. Peter Anvin" To: =?ISO-8859-1?Q?Daniel_P=2E_Berrang=E9?= , "Jason A. Donenfeld" CC: Dave Hansen , "Reshetova, Elena" , "Kirill A. Shutemov" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "x86@kernel.org" , "Theodore Ts'o" , Kuppuswamy Sathyanarayanan , "Nakajima, Jun" , Tom Lendacky , "Kalra, Ashish" , Sean Christopherson , "linux-coco@lists.linux.dev" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 2/2] x86/random: Issue a warning if RDRAND or RDSEED fails User-Agent: K-9 Mail for Android In-Reply-To: References: <20240130083007.1876787-1-kirill.shutemov@linux.intel.com> <20240130083007.1876787-2-kirill.shutemov@linux.intel.com> <88a72370-e300-4bbc-8077-acd1cc831fe7@intel.com> Message-ID: <33EBFB22-0063-4E3C-A43D-63638D308325@zytor.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On January 30, 2024 10:05:59 AM PST, "Daniel P=2E Berrang=C3=A9" wrote: >On Tue, Jan 30, 2024 at 06:49:15PM +0100, Jason A=2E Donenfeld wrote: >> On Tue, Jan 30, 2024 at 6:32=E2=80=AFPM Dave Hansen wrote: >> > >> > On 1/30/24 05:45, Reshetova, Elena wrote: >> > >> You're the Intel employee so you can find out about this with much >> > >> more assurance than me, but I understand the sentence above to be = _way >> > >> more_ true for RDRAND than for RDSEED=2E If your informed opinion = is, >> > >> "RDRAND failing can only be due to totally broken hardware" >> > > No, this is not the case per Intel SDM=2E I think we can live under= a simple >> > > assumption that both of these instructions can fail not just due to= broken >> > > HW, but also due to enough pressure put into the whole DRBG constru= ction >> > > that supplies random numbers via RDRAND/RDSEED=2E >> > >> > I don't think the SDM is the right thing to look at for guidance here= =2E >> > >> > Despite the SDM allowing it, we (software) need RDRAND/RDSEED failure= s >> > to be exceedingly rare by design=2E If they're not, we're going to g= et >> > our trusty torches and pitchforks and go after the folks who built th= e >> > broken hardware=2E >> > >> > Repeat after me: >> > >> > Regular RDRAND/RDSEED failures only occur on broken hardware >> > >> > If it's nice hardware that's gone bad, then we WARN() and try to make >> > the best of it=2E If it turns out that WARN() was because of a broke= n >> > hardware _design_ then we go sharpen the pitchforks=2E >> > >> > Anybody disagree? >>=20 >> Yes, I disagree=2E I made a trivial test that shows RDSEED breaks easil= y >> in a busy loop=2E So at the very least, your statement holds true only >> for RDRAND=2E >>=20 >> But, anyway, if the statement "RDRAND failures only occur on broken >> hardware" is true, then a WARN() in the failure path there presents no >> DoS potential of any kind, and so that's a straightforward conclusion >> to this discussion=2E However, that really hinges on "RDRAND failures >> only occur on broken hardware" being a true statement=2E > >There's a useful comment here from an Intel engineer > >https://web=2Earchive=2Eorg/web/20190219074642/https://software=2Eintel= =2Ecom/en-us/blogs/2012/11/17/the-difference-between-rdrand-and-rdseed > > "RDRAND is, indeed, faster than RDSEED because it comes > from a hardware-based pseudorandom number generator=2E > One seed value (effectively, the output from one RDSEED > command) can provide up to 511 128-bit random values > before forcing a reseed" > >We know we can exhaust RDSEED directly pretty trivially=2E Making your >test program run in parallel across 20 cpus, I got a mere 3% success >rate from RDSEED=2E > >If RDRAND is reseeding every 511 values, RDRAND output would have >to be consumed significantly faster than RDSEED in order that the >reseed will happen frequently enough to exhaust the seeds=2E > >This looks pretty hard, but maybe with a large enough CPU count >this will be possible in extreme load ? > >So I'm not convinced we can blindly wave away RDRAND failures as >guaranteed to mean broken hardware=2E > >With regards, >Daniel The general approach has been "don't credit entropy and try again on the n= ext interrupt=2E" We can, of course, be much more aggressive during boot=2E We only need 256-512 bits for the kernel random pool to be equivalent to b= reaking mainstream crypto primitives even if it is a PRNG only from that po= int on (which is extremely unlikely=2E) The Linux PRNG has a very large sta= te, which helps buffer entropy variations=2E Again, applications *should* be using /dev/[u]random as appropriate, and i= f they opt to use lower level primitives in user space they need to impleme= nt them correctly =E2=80=93 there is literally nothing the kernel can do at= that point=2E If the probability of success is 3% per your CPU that is still 2 bits of t= rue entropy per invocation=2E However, the probability of failure after 16 = loops is over 60%=2E I think this validates the concept of continuing to po= ll periodically rather than looping in time critical paths=2E