Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1676348pxk; Tue, 1 Sep 2020 05:10:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSQE1fwtoYuoHebPcBOCwQySon/o2HfoEyxwfXRigne1xFiaPciVSkFiGDQi/mNgqWYMxL X-Received: by 2002:a17:906:f150:: with SMTP id gw16mr1115534ejb.528.1598962208211; Tue, 01 Sep 2020 05:10:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598962208; cv=none; d=google.com; s=arc-20160816; b=u6GP1Nr7pXJ766T20M39p5c2iFDu8PJmCu4tE2v2ImWgetNEES/veoRXo4xYnqFIPw 8Dx7GsOQliPEO2eGMnxacU3WIq6Z2GwQc8B0mnQzLZK2PpGnTYsgyDaprOV+ovHGuNGh U3VZ+gacLgm0OPb132x/ZuznfSa5ple/MlqFLum3qQrDEANiuAV7EplFhwBX/6mWcSUv 9GX0fT+N1WA8JdGDtxX0pryMx7fbsezECOsodYDgEHslErOuGVE2PrJVJibcZAyaNdsS tXc9L0ZBZYVXnBsBgGe+3dA/N5Ao49oVF8vYSWy+Gs7OleTeUW3zBIo/YAY13sotwa1G YfIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=m22PlnVO57pJTQbtQJEribzB/V2zXBGMEScl/R9uPuc=; b=JfiMDd24CccCvE94wddtK/sNZtNJ0zKRWWM9rT8z+LDj9b+wVyogxa1LsezFhuRNHN TDwmLKTXNvn+xKGEy0xoVC1YEXXj7vIRtYA0qIY537a14uoiZwylORW63YiqhulBMOc0 QHdVKgiF3MpGuqE8qlb1pGo/mBWrdE6jTklgLGl+6gtbkXyNP4KcGZ+Ey+CzNI+MN0+2 zXiUQQvdYYvXw09XE25UVCBibgdp+xNmtkGFkjpydlvCEyaGx0ntu2BGpB0Ql1JjXSXt 74eMGMb03xBKKKwsc8xRoiDBzR0GQAN5UEfsCCnxARGujvBW4RAB9BWs491mc5RFeVwO zn6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cy23si447269edb.311.2020.09.01.05.09.44; Tue, 01 Sep 2020 05:10:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728115AbgIAMHZ (ORCPT + 99 others); Tue, 1 Sep 2020 08:07:25 -0400 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:41211 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726144AbgIAL6r (ORCPT ); Tue, 1 Sep 2020 07:58:47 -0400 Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 081Bvts2001080; Tue, 1 Sep 2020 13:57:55 +0200 Date: Tue, 1 Sep 2020 13:57:55 +0200 From: Willy Tarreau To: Eric Dumazet Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Sedat Dilek , George Spelvin , Amit Klein , Eric Dumazet , "Jason A. Donenfeld" , Andy Lutomirski , Kees Cook , Thomas Gleixner , Peter Zijlstra , Linus Torvalds , tytso@mit.edu, Florian Westphal , Marc Plumb Subject: Re: [PATCH 2/2] random32: add noise from network and scheduling activity Message-ID: <20200901115755.GA1059@1wt.eu> References: <20200901064302.849-1-w@1wt.eu> <20200901064302.849-3-w@1wt.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.6.1 (2016-04-27) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Eric, On Tue, Sep 01, 2020 at 12:24:38PM +0200, Eric Dumazet wrote: > There is not much entropy here really : > > 1) dev & txq are mostly constant on a typical host (at least the kind of hosts that is targeted by > Amit Klein and others in their attacks. > > 2) len is also known by the attacker, attacking an idle host. > > 3) skb are also allocations from slab cache, which tend to recycle always the same pointers (on idle hosts) > > > 4) jiffies might be incremented every 4 ms (if HZ=250) I know. The point is essentially that someone "remote" or with rare access to the host's memory (i.e. in a VM on the same CPU sharing L1 with some CPU vulnerabilities) cannot synchronize with the PRNG and easily stay synchronized forever. Otherwise I totally agree that these are pretty weak. But in my opinion they are sufficient to turn a 100% success into way less. I try not to forget that we're just trying to make a ~15-bit port require ~2^14 attempts on average. Oh and by the way the number of calls also counts here. > Maybe we could feed percpu prandom noise with samples of ns resolution timestamps, > lazily cached from ktime_get() or similar functions. > > This would use one instruction on x86 to update the cache, with maybe more generic noise. Sure! I think the principle here allows to easily extend it to various places, and the more the better. Maybe actually we'll figure that there are plenty of sources of randomness that were not considered secure enough to feed /dev/random while they're perfectly fine for such use cases. > diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c > index 4c47f388a83f17860fdafa3229bba0cc605ec25a..a3e026cbbb6e8c5499ed780e57de5fa09bc010b6 100644 > --- a/kernel/time/timekeeping.c > +++ b/kernel/time/timekeeping.c > @@ -751,7 +751,7 @@ ktime_t ktime_get(void) > { > struct timekeeper *tk = &tk_core.timekeeper; > unsigned int seq; > - ktime_t base; > + ktime_t res, base; > u64 nsecs; > > WARN_ON(timekeeping_suspended); > @@ -763,7 +763,9 @@ ktime_t ktime_get(void) > > } while (read_seqcount_retry(&tk_core.seq, seq)); > > - return ktime_add_ns(base, nsecs); > + res = ktime_add_ns(base, nsecs); > + __this_cpu_add(prandom_noise, (unsigned long)ktime_to_ns(res)); > + return res; > } > EXPORT_SYMBOL_GPL(ktime_get); Actually it could even be nice to combine it with __builtin_return_address(0) given the large number of callers this one has! But I generally agree with your proposal. Thanks, Willy