Received: by 10.192.165.156 with SMTP id m28csp800772imm; Mon, 16 Apr 2018 08:55:54 -0700 (PDT) X-Google-Smtp-Source: AIpwx48rPvvmWqPprskwbqJ+zEPjABzu4uNVCvdyDJTM2l/9WtaYq3+U1YGzTvB9RLw0n4HWwhXv X-Received: by 10.98.32.80 with SMTP id g77mr22205887pfg.216.1523894153965; Mon, 16 Apr 2018 08:55:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523894153; cv=none; d=google.com; s=arc-20160816; b=MgYDom7s8BULP56/K2f/fAy8QkTPkpxCNCDJ6QT5tid+DJgAJKx+/Dg6T/7UsMGTxu dehK+kbeKy1BS2UQFHxeXpu6IYf63uzTxx3LKx5xyvXBuPGHc+m+ccdEAAQLTH9aUF/h voYWtbc4vesOpoDbMmMz1+XhE6w99XQ5mt5jAZFHvVwItaBO2agMyiJ2+MhDOK20105E Wg1ocBOdUr53LJhILSK3Uaj162cj11umlCfcPH94qLk8BJJZO7MM8IBENS+PdUfuVU4w SziYVIkj6CTB0OICOAaqfJB55QSmlKWzhPjeUYQfeDjb3k2KmiJ+YxjMV0hLDjJ0SOK1 KXqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=ZlFvScUzMEr4Ju8fJqrDvgVhTZAasBE+s1RHdWM7wog=; b=HDT+iBv87RaMxdbbM2rJYhYERCsDLywTxnfzMyHEIXdx9i9/fBxLOvZzcbnsDexMDt i37q4NLTiddhW/wTmsPbNq5ZTe2zK4NNQCu6w34HO/qY3v1ebbutvpGe+kmNlbKUowjL L3zohuBY8FGDj3Al5nHypphtwINVcRUIrI80yI47ryc2GrYKkfG6ozQsnFogyhOIyEJy p+u7LhxTkmAs0QI8/txl8ic16K+BtZ2vyjuwSu34bOyFbb3OdDGcP7alB1L+GuoSx+pW F7mRk1qsolH2aBjmmUnTksHUGGYI39cLnKN2nNwu2dm4ELFHDu1CEchHUFdEGnd8ybZy 2giA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=aMDD1qg3; dkim=fail header.i=@chromium.org header.s=google header.b=QlFzuIFr; 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=fail (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 m12si9876623pgd.240.2018.04.16.08.55.39; Mon, 16 Apr 2018 08:55:53 -0700 (PDT) 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=fail header.i=@google.com header.s=20161025 header.b=aMDD1qg3; dkim=fail header.i=@chromium.org header.s=google header.b=QlFzuIFr; 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=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751908AbeDPPyV (ORCPT + 99 others); Mon, 16 Apr 2018 11:54:21 -0400 Received: from mail-ua0-f169.google.com ([209.85.217.169]:41960 "EHLO mail-ua0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751227AbeDPPyT (ORCPT ); Mon, 16 Apr 2018 11:54:19 -0400 Received: by mail-ua0-f169.google.com with SMTP id t9so10411564uac.8 for ; Mon, 16 Apr 2018 08:54:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to; bh=ZlFvScUzMEr4Ju8fJqrDvgVhTZAasBE+s1RHdWM7wog=; b=aMDD1qg3JIHDSIT6LxPE4cexzWISpJ4AJzvwioYO9RY34tKFid3DNF53AH8GLg875a sQ5Ek7D2p9tl+KwbJaC+F2+4c28tyfdyo4FnVoDqqXCM5AIYFUl9fmTGoOxdOJz1FT7F U3U38ARtPS3HVeZ5y4re096AgDlZvMSfllVgOWQt5TU2OfUMws8Cs34bG1LDUf3i3mc0 GlOoi4MCweBQwbukG0y/EPYhHH7rpQDYOIE0GXQ+IvM2mavHxH2YIp5y0a1EZOyhMJEk 94SCl3edKeZsm/8zObNQMcjAiJ66C5gzKVvChlU4tc188RDWFjPJUpQwgILp14IOPbZs 4a6Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to; bh=ZlFvScUzMEr4Ju8fJqrDvgVhTZAasBE+s1RHdWM7wog=; b=QlFzuIFrz4qP3QKFeNy9eolnoSAM731rqE4b1lp33B7Mul6uUhsncEfEa3l54nXfUu Mvqutbex5q35kGLYJG4Ahj9B5VYn+G/Q2IOwzs/dI+zcfrpncut06Ky8HzDUicrkdvXj hs5SGP+5xTTUG75wtfWaNFv0NC3E0AGMK/Eqc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to; bh=ZlFvScUzMEr4Ju8fJqrDvgVhTZAasBE+s1RHdWM7wog=; b=CtkmCcdMG6cKZTld2KAsAgIeGuvXAteG06nnPzhS2FcJaF6Q5KhqGUVzYoXsEnnHJm Fo1Ok0z+g9JbLPnT8IERx8cavS9LL4OpTRqg1ClH82I2LqcszDpdmacr2a7MKqxe94Rp lh7YK1GU471BDH1eLCkuDGOkXGXCxf9s+9Lk2KCgi9RgqdYCV/gWbvhxO87P2dbS9AFA /jQYfbaHpzBerSwZViIMjAQB/HFS0lV+DE8aYYrzofMSrmOaGFNKu3vVcSjudiYp8MVF ol6GxLcTdKEK3a3PVqwrR0jahw0Hty7ctfitxUdUrpSld4sqWtlG5UH5LFi5+WWkqZc7 IQkQ== X-Gm-Message-State: ALQs6tByy+Gz5ypXo5TyHMnAUhAJ5GW80xPdYOO7mQ2vEiZL5xlVDqlp so8QCwpLONtcnz3S/JfE1aMxmkF8jdglSo0bvtN2Dg== X-Received: by 10.176.86.206 with SMTP id c14mr11755526uab.164.1523894058631; Mon, 16 Apr 2018 08:54:18 -0700 (PDT) MIME-Version: 1.0 Received: by 10.31.164.81 with HTTP; Mon, 16 Apr 2018 08:54:17 -0700 (PDT) In-Reply-To: <20180414224419.GA21830@thunk.org> References: <20180414195921.GA10437@avx2> <20180414224419.GA21830@thunk.org> From: Kees Cook Date: Mon, 16 Apr 2018 08:54:17 -0700 X-Google-Sender-Auth: b4iHoUSnfByOrwY0xUHJF0kovmg Message-ID: Subject: Re: repeatable boot randomness inside KVM guest To: "Theodore Y. Ts'o" , Alexey Dobriyan , LKML , Linux-MM , Thomas Garnier Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 14, 2018 at 3:44 PM, Theodore Y. Ts'o wrote: > +linux-mm@kvack.org > kvm@vger.kernel.org, security@kernel.org moved to bcc > > On Sat, Apr 14, 2018 at 10:59:21PM +0300, Alexey Dobriyan wrote: >> SLAB allocators got CONFIG_SLAB_FREELIST_RANDOM option which randomizes >> allocation pattern inside a slab: >> >> int cache_random_seq_create(struct kmem_cache *cachep, unsigned int count, gfp_t gfp) >> { >> ... >> /* Get best entropy at this stage of boot */ >> prandom_seed_state(&state, get_random_long()); >> >> Then I printed actual random sequences for each kmem cache. >> Turned out they were all the same for most of the caches and >> they didn't vary across guest reboots. > > The problem is at the super-early state of the boot path, kernel code > can't allocate memory. This is something most device drivers kinda > assume they can do. :-) > > So it means we haven't yet initialized the virtio-rng driver, and it's > before interrupts have been enabled, so we can't harvest any entropy > from interrupt timing. So that's why trying to use virtio-rng didn't > help. > >> The only way to get randomness for SLAB is to enable RDRAND inside guest. >> >> Is it KVM bug? > > No, it's not a KVM bug. The fundamental issue is in how the > CONFIG_SLAB_FREELIST_RANDOM is currently implemented. > > What needs to happen is freelist should get randomized much later in > the boot sequence. Doing it later will require locking; I don't know > enough about the slab/slub code to know whether the slab_mutex would > be sufficient, or some other lock might need to be added. > > The other thing I would note that is that using prandom_u32_state() doesn't > really provide much security. In fact, if the the goal is to protect > against a malicious attacker trying to guess what addresses will be > returned by the slab allocator, I suspect it's much like the security > patdowns done at airports. It might protect against a really stupid > attacker, but it's mostly security theater. > > The freelist randomization is only being done once; so it's not like > performance is really an issue. It would be much better to just use > get_random_u32() and be done with it. I'd drop using prandom_* > functions in slab.c and slubct and slab_common.c, and just use a > really random number generator, if the goal is real security as > opposed to security for show.... > > (Not that there's necessarily any thing wrong with security theater; > the US spends over 3 billion dollars a year on security theater. As > politicians know, symbolism can be important. :-) I've added Thomas Garnier to CC (since he wrote this originally). He can speak to its position in the boot ordering and the effective entropy. -Kees -- Kees Cook Pixel Security