Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2222029pxb; Wed, 30 Mar 2022 19:49:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+OaAI/1Dyvl/LXIXXimJ9/yMAkeB4g3GgNRMQ12i8G30IO7FeuygmqyKV5LSOx6epxbyw X-Received: by 2002:a17:903:2305:b0:154:4aa2:e800 with SMTP id d5-20020a170903230500b001544aa2e800mr2725221plh.167.1648694941869; Wed, 30 Mar 2022 19:49:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648694941; cv=none; d=google.com; s=arc-20160816; b=uisslDzN3vIi6PMRfsBk1kvt8IxrW0Ni0oEPO8RYlFhJe6kK0/AUoHJvOxQQTZbh2P KNvABAZ/o2PMTWivS5Nh0ZZwvEuna4TGQ7JyRvM7GAK7wtoGqyQC0/a7PplmpxO+FSOu 0bsKOWAOg4ccV+4BKOAqtRH3IrOGQQsaemgfASQcsExAUpITfmWzqePPNhOymUNoXnXt ITrta5GB7EcKnTg6KqRP9xppPn/bKslbzvD4cIngS22sjnP+gVzdw/IYiekJYmYhdkq0 EqvnJaTxz7B220sd03QjQTZinAgPEjr2OW6KAZJc2MmAZQ7qO8lZcRXawOXzoZBzOsm5 3X0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=dKO0rsHOFyAMpWyi1MHnQVOBdREz93tr5XlY/aCT89k=; b=Zm1kXDh2Rp3d8qmzUkIx6XSgmuSBulQtGwIFYgRnO/+LknF43grBnNHUL5BrWlbkCb DhSbG/O2exkgNvH8yl1DpgEhP+uMzrhL6xv5b0Bowwv8pL0G9qQMdwWNUS6OF9LMOo0O ZJMz+GqWHCmMLueo04yAbXcltoYWsBJ/ooq5Trt3eDQLdquj63N6E/IIA/Mo+Kb+/DfG Wro7t8TQmUPyZum853TbqgxWVO3J8xHgTe+Mo70W3PzQvrAJTO6xWr1pmC0CFgdjulp/ jLZfyyJlZdYrUrChJMDKtFQDENMP38B7TV/yZMfQB7Y9bP+N4+mslMijjrhw8FjWNiwy VdLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sweetwater-ai.20210112.gappssmtp.com header.s=20210112 header.b=HuX8hqSN; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id u17-20020a62d451000000b004fa3a8e0018si21705772pfl.207.2022.03.30.19.49.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 19:49:01 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@sweetwater-ai.20210112.gappssmtp.com header.s=20210112 header.b=HuX8hqSN; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8BF4BBD8BF; Wed, 30 Mar 2022 19:37:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350118AbiC3SjR (ORCPT + 99 others); Wed, 30 Mar 2022 14:39:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352492AbiC3SfU (ORCPT ); Wed, 30 Mar 2022 14:35:20 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EA4F49FAA for ; Wed, 30 Mar 2022 11:33:31 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id y10so25452267edv.7 for ; Wed, 30 Mar 2022 11:33:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sweetwater-ai.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=dKO0rsHOFyAMpWyi1MHnQVOBdREz93tr5XlY/aCT89k=; b=HuX8hqSNN5CkzIlnxfFjhdrv+0hTKMiO/saHmO8S5JDzFWMGcv/5KDwUAo32rYCysn X77M8eptIyb61789PEkrwWql5tRKB9J77M8fq0MwhTccLCZJLdKGAOoHGL6pWRui9ZTO bMRVaQiHPR78HPQOjJ/go74Pw5Cy8v6E3yw3PoryL1+twgVAmF06wPH7EuNgVtgBBMRY PGRydspLrTf832CuGoWHkQm7PSSelwm6jOkHWjlMi0X52TNW9TWYxb8LuxqrgKpoPByl Xpza3Cb7yNeuPfYSbS/2ylp8aqgwMOMKtcSobjgViLCTbryqSUzJMxoVFksfihYscBks V3Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=dKO0rsHOFyAMpWyi1MHnQVOBdREz93tr5XlY/aCT89k=; b=vWnVIP06mjcSsPzzkG1DbVLP3aFrbUEkTrvdjchT8tmjksaWXZ/TexJ6Cd+xi6qYCU fpN0qX2RsToPercNgB+vNuQQqEnmmCm61FnuPS4wAxM+uABJjmhkkbwbdA+am14xtiI3 +N3bqtqJoSIei4Zc7B+Q4Rr9Go1M8v053zwDQ6KmkLw/ugoBiPyFkwQMVmPt7rsTGSCN MkE8d0TEI6O/tzdkrIOAcrKEqOp5b+mWeF1VBoCVK4Wsrq1zk80HHWKLXcE6EJAXVhZq vFZjPXQ28OnkWmVKh6ZRbS3ktk92jlRh2uWrTfqNtFCtzSCuy0Lr4YL+NK9F3hhEMIZ5 Qjeg== X-Gm-Message-State: AOAM5314gU7e+NhrVBOeX/W3ZIKZhUxhhLV0XXnsCuaHosdX+6SnzhwV dz0maYYzPXnmClCY6FJRZbN1acusFHFlb3X6eYiapQ== X-Received: by 2002:aa7:c704:0:b0:418:ee8f:3fd0 with SMTP id i4-20020aa7c704000000b00418ee8f3fd0mr12314131edq.248.1648665209697; Wed, 30 Mar 2022 11:33:29 -0700 (PDT) MIME-Version: 1.0 References: <20220328111828.1554086-1-sashal@kernel.org> <20220328111828.1554086-16-sashal@kernel.org> <9e78091d07d74550b591c6a594cd72cc@AcuMS.aculab.com> In-Reply-To: From: Michael Brooks Date: Wed, 30 Mar 2022 11:33:21 -0700 Message-ID: Subject: Re: [PATCH AUTOSEL 5.17 16/43] random: use computational hash for entropy extraction To: David Laight Cc: Sasha Levin , Dominik Brodowski , Eric Biggers , Greg Kroah-Hartman , "Jason A. Donenfeld" , Jean-Philippe Aumasson , "Theodore Ts'o" , "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The /dev/random device driver need not concern itself with root adversaries as this type of user has permissions to read and overwrite memory - this user even possesses permission to replace the kernel elf binary with a copy of /dev/random that always returns the number 0 - that is their right. This whole issue of leaks is because we are relying upon fast but insecure hash-function-like methods to extract data from a sensitive pool. LFSR and CRC32 (which was used in an earlier version of /dev/random) have similarities to secure hash functions - but "aren't good enough for military work" - which is why we are even discussing the topic of leakage. If we use a secure primitive in the right way - preferably one that is faster than SHA1 - such as chcha20 or even faster still AES-NI (both in a feedback mode). Then the leakage is stopped. If the pool cannot leak then we do not need an entropy counter which is the mutex that handle_irq_event_percpu() fights over. This reduces interrupt latency, reduces computational load of all interrupts, and helps contribute to the pool being less predictable because now an outside construct has to account for race conditions. -Michael On Wed, Mar 30, 2022 at 10:10 AM Michael Brooks wrote: > > Of course I am assuming local user non-root access. One does not need > to reverse the mix operations in order to form a parallel construction > - a one way function is sufficient for such a construct as both sides > will operate on the data in the same manner. > > This attack scenario is simply a non-issue in keypoolrandom. > https://github.com/TheRook/KeypoolRandom > > On Wed, Mar 30, 2022 at 9:49 AM David Laight wr= ote: > > > > From: Michael Brooks > > > Sent: 30 March 2022 17:08 > > ... > > > I=E2=80=99d like to describe this bug using mathematics, because that= is how I > > > work - I am the kind of person that appreciates rigor. In this case, > > > let's use inductive reasoning to illuminate this issue. > > > > > > Now, in this attack scenario let =E2=80=9Cp=E2=80=9D be the overall p= ool state and let > > > =E2=80=9Cn=E2=80=9D be the good unknown values added to the pool. Fi= nally, let =E2=80=9Ck=E2=80=9D be > > > the known values - such as jiffies. If we then describe the ratio of > > > unknown uniqueness with known uniqueness as p=3Dn/k then as a k grows > > > the overall predictability of the pool approaches an infinite value a= s > > > k approaches zero. A parallel pool, let's call it p=E2=80=99 (that = is > > > pronounced =E2=80=9Cp-prime=E2=80=9D for those who don=E2=80=99t get = the notation). let > > > p=E2=80=99=3Dn=E2=80=99/k=E2=80=99. In this case the attacker has no = hope of constructing n=E2=80=99, > > > but they can construct k=E2=80=99 - therefore the attacker=E2=80=99s = parasol model of > > > the pool p=E2=80=99 will become more accurate as the attack persists = leading > > > to p=E2=80=99 =3D p as time->=E2=88=9E. > > > > > > Q.E.D. > > > > That rather depends on how the (not) 'randmoness' is added to the pool. > > If there are 'r' bits of randomness in the pool and a 'stir in' a pile > > of known bits there can still be 'n' bits of randomness in the pool. > > > > The whole thing really relies on the non-reversability of the final prn= g. > > Otherwise if you have 'r' bits of randomness in the pool and 'p' bits > > in the prng you only need to request 'r + p' bits of output to be able > > to solve the 'p + r' simultaneous equations in 'p + r' unknowns > > (I think that is in the field {0, 1}). > > > > The old kernel random number generator that used xor to combine the > > outputs of several LFSR is trivially reversable. > > It will leak whatever it was seeded with. > > > > The non-reversability of the pool isn't as important since you need > > to reverse the prng as well. > > > > So while, in some sense, removing 'p' bits from the entropy pool > > to seed the prng only leaves 'r - p' bits left. > > That is only true if you think the prng is reversable. > > Provided 'r > p' (preferably 'r >> p') you can reseed the prng > > again (provided you take reasonably random bits) without > > really exposing any more state to an attacker. > > > > Someone doing cat /dev/urandom >/dev/null should just keep reading > > values out of the entropy pool. > > But if they are discarding the values that shouldn't help them > > recover the state of the entropy pool or the prng - even if only > > constant values are being added to the pool. > > > > Really what you mustn't do is delete the bits used to seed the prng > > from the entropy pool. > > About the only way to actually reduce the randomness of the entropy > > pool is if you've discovered what is actually in it, know the > > 'stirring' algorithm and feed in data that exactly cancels out > > bits that are present already. > > I suspect that anything with root access can manage that! > > (Although they can just overwrite the entropy pool itself, > > and the prng for that matter.) > > > > David > > > > - > > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, M= K1 1PT, UK > > Registration No: 1397386 (Wales)