Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp385134ybv; Fri, 7 Feb 2020 01:06:23 -0800 (PST) X-Google-Smtp-Source: APXvYqz/2BP/qg+wFA0ohWVGxqS3y59yvN2EvGES5ynsSJX0o1BEIBO+jsf3sgORD/rB55bBJJi9 X-Received: by 2002:a9d:7410:: with SMTP id n16mr1971825otk.23.1581066383207; Fri, 07 Feb 2020 01:06:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581066383; cv=none; d=google.com; s=arc-20160816; b=m4XcFUbSw8cgDheI6lTgAeXp9PTlvZK7HN+cKDs4z5vBHmQn0dX7v0RGOegsB/tsgN P8dGqLKuoZkxA59YiICRYyeUJQu0bt7I8MxZq6IUVI/tYcXdYKtVdvW2OgGEPDmIHvy8 thvKZh3K5WFPgUEfEOk9T38Vlts1lBuebJRZLynw2lF47OqsbKsr0OesVNApdNldyVb7 OSfSENiDxXmmesoG9BqQJl2v0GYsZqepZJfsZcu2MNwdX/kmHZEB7WgnecYs68Z8/2HX oGhU633SKPyNC6Q7FiloeYLiSfg5P9Dbflc3No1pJ/4l2pCem8HjKIAhK5Tbotf1APk8 pJBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Mz7Ey9gSAauDy/gNIB43lQyeRt2xn0zd/o4g7lTFRzY=; b=1JwjGle7NVWzqEYr6RXjsyM5sc2DlRKq2eJznimFO8K8DrALOjrPgOl5Mg0FrqRXo2 qayUBR20JH2qa9kVHeWx24DAYeR9uiuRAuxbF2IzJHk4r/gWVh7k/CNpDaAFI3eqGq3d +HbNLceRnIuJP8sRoTKzlV2EWV0Qa99Cu9YeCYM3mPdl5d8kmpt55MiMYCwwh3jcRRIB oGj1rEcVGEeBA4SBhILSZWU7Wf4owWBF15+RqU7JGzBbKFq4Y/f/hOAirnllb+aJNDtA 0ojz8zYpq9ZE+S5Jk5lTfFYNs8iStzyW1HpHfV/DpSKOsHXBIpjh0QtrIXylZaKSHaMR Yupw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=EbFgLJlU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i3si1346194otc.272.2020.02.07.01.06.10; Fri, 07 Feb 2020 01:06:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=EbFgLJlU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726626AbgBGJFH (ORCPT + 99 others); Fri, 7 Feb 2020 04:05:07 -0500 Received: from mail-oi1-f194.google.com ([209.85.167.194]:41705 "EHLO mail-oi1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726136AbgBGJFG (ORCPT ); Fri, 7 Feb 2020 04:05:06 -0500 Received: by mail-oi1-f194.google.com with SMTP id i1so1278658oie.8 for ; Fri, 07 Feb 2020 01:05:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Mz7Ey9gSAauDy/gNIB43lQyeRt2xn0zd/o4g7lTFRzY=; b=EbFgLJlUCVtdm+nm5zkXqa6IQ1oUHjUAG8sWUHvhz9ARUDzaZroyehH337WrjDq3ay LK32Hr3BEJDbDTRCKxqICnH2TMhsMQ0TmtEaX62cnkitw5tLUPIyqWHYHcZcAJ8YY4RO pr6LEHiF7oM5QsnYOoqfZvozpKd5rCilqqGwU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Mz7Ey9gSAauDy/gNIB43lQyeRt2xn0zd/o4g7lTFRzY=; b=fLJUmVfWxU4YdsCIv9o895bhq8dfXb/myaDeuj9ovnbF02Z1+D+EpdeOPVGWxe/OdM lZg4/EeOeUPzR4ADbfPnwRuM6H9pGUgP+bF1vpPnyBikiEwAeHkVMGyI9GJTyKkN6pyb WbFR3tfWY8nvcrGmXsRqiO9xrnlcVj5hLmuXijt9wjG9fGGXCj3maZa1VtgWLJ3EeB2U GvKOSttVytXeU3f9CW1JGKXhcrPZ+lJmEHS14Ord8dqTONcz+VIoqrZGz3cTcDDGPNr6 +GNCv0r7DQ0aWJLJAOvHxh9iKKx5tXyJxPgSzpZ00rGJMqC9IjvT+cf8Xfxw90yo4Yrz T18Q== X-Gm-Message-State: APjAAAVmXlR1PYltrpz+EiTsYF5cgBS6auSkpNzAxvyeNysmOTsmeL9/ 4flP4RMzFJnsITxBuqgJHeDScg== X-Received: by 2002:aca:4ad8:: with SMTP id x207mr1333594oia.55.1581066305665; Fri, 07 Feb 2020 01:05:05 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id t203sm845468oig.39.2020.02.07.01.05.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Feb 2020 01:05:04 -0800 (PST) Date: Fri, 7 Feb 2020 01:05:03 -0800 From: Kees Cook To: Jean-Philippe Aumasson Cc: "Jason A. Donenfeld" , Kristen Carlson Accardi , tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, arjan@linux.intel.com, rick.p.edgecombe@intel.com, x86@kernel.org, LKML , kernel-hardening@lists.openwall.com Subject: Re: [RFC PATCH 04/11] x86/boot/KASLR: Introduce PRNG for faster shuffling Message-ID: <202002070100.2521E7563@keescook> References: <20200205223950.1212394-1-kristen@linux.intel.com> <20200205223950.1212394-5-kristen@linux.intel.com> <20200206151001.GA280489@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 07, 2020 at 08:23:53AM +0100, Jean-Philippe Aumasson wrote: > > On Thu, Feb 6, 2020 at 4:10 PM Jason A. Donenfeld wrote: > > > Hey Kees, > > > > On Wed, Feb 05, 2020 at 02:39:43PM -0800, Kristen Carlson Accardi wrote: > > > +#define rot(x, k) (((x)<<(k))|((x)>>(64-(k)))) > > > +static u64 prng_u64(struct prng_state *x) > > > +{ > > > + u64 e; > > > + > > > + e = x->a - rot(x->b, 7); > > > + x->a = x->b ^ rot(x->c, 13); > > > + x->b = x->c + rot(x->d, 37); > > > + x->c = x->d + e; > > > + x->d = e + x->a; > > > + > > > + return x->d; > > > +} > > > > I haven't looked closely at where the original entropy sources are > > coming from and how all this works, but on first glance, this prng > > doesn't look like an especially cryptographically secure one. I realize > > that isn't necessarily your intention (you're focused on speed), but > > actually might this be sort of important? If I understand correctly, the > > objective of this patch set is so that leaking the address of one > > function doesn't leak the address of all other functions, as is the case > > with fixed-offset kaslr. But if you leak the addresses of _some_ set of > > functions, and your prng is bogus, might it be possible to figure out > > the rest? For some prngs, if you give me the output stream of a few > > numbers, I can predict the rest. For others, it's not this straight > > forward, but there are some varieties of similar attacks. If any of that > > set of concerns turns out to apply to your prng_u64 here, would that > > undermine kaslr in similar ways as the current fixed-offset variety? Or > > does it not matter because it's some kind of blinded fixed-size shuffle > > with complex reasoning that makes this not a problem? > > Let me share my 2 cents: > > That permutation might be safe but afaict it hasn't been analyzed wrt > modern cryptographic techniques and there might well be differential > characteristics, statistical biases, etc. > > What about just using SipHash's permutation, already in the kernel? It > works on 4*u64 words too, and 6 rounds would be enough. > > Doing a basic ops count, we currently have 5 group operations and 3 > rotations per round or 150 and 90 for the 30 init rounds. With SipHash it'd > be 48 and 36 with the proposed 6 rounds. Probably insignificant speed wise > as init is only done once but just to show that we'd get both better > security assurance and better performance. Yeah, this was never meant to be anything but a POC and after timing tests, it seemed like an unneeded abstraction but was kept for this RFC so it was possible to specify a stable seed at boot for debugging, etc. I think this patch will not survive to v1. :) -- Kees Cook