Received: by 10.192.165.156 with SMTP id m28csp826100imm; Mon, 16 Apr 2018 09:17:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/wJ2r7GJ4gKta2q3mIA/WU9oOMez1u18D0pL1YO3WyKsXcZe+WLxc7Ejt2uL1mYpmNj6ha X-Received: by 2002:a17:902:7291:: with SMTP id d17-v6mr16053420pll.218.1523895475413; Mon, 16 Apr 2018 09:17:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523895475; cv=none; d=google.com; s=arc-20160816; b=Z5RMz6EXahq6fECkj+7+RoYxW8Cs2LXvOaswBDRvLL26L3dww5I4rTqFPHwnBJEcIR 4Bx/WuOvvaGBTenEJe55iC5ZYdCwhrcwUwgP1J0+i3FoCmDqfAt6ioUaiNEzA3bLAtiZ qfzesO2dlqRCG5/S5wRjJJbuip8V8i9k/xfuVyZ2KEAhIE75vJ1ls3/33MSK06XY7GOk XWzsnqUHM9w6g8kbK1S7J8zd3szMWXQW7xK55U5iUZi9iFhuKfjhPrSYN0MsTeBKSXJc 6B8sCExX4bewbKdd7om6rbopB9ZMPGLqZOaXpRhwdtaTazWTaYcmX2eFSy1lvOOAbIBw 3jzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=j1743B9pdBZnqJaR5Li6eMPOlSErvNY6avokGibRr6c=; b=Un6gCazlK5z0hAvWmnXhujl0+XJZhYGBGOGn2i5c5g/QQH3JyccTeWlh48BpO8LDi5 AvXBHnjDW3wmtVrHLHKx08lyWengK4psA0KuD7kfTzA8HJHV9k2ChM6FSOw3cVa85hZ9 qUHmDVDFRvEgt54Ix68JBUB/rYUmbBJmOKQ9IrR+G8vw4vhrnrt1Ci4aqwo4Fe54X1Dw 3qDWUzwI1VkJcJEpBHcW2SJiLC5mVKcRQT/cWgKV6Jg+g3a77SEPDxvQ95VfKbcXN01W EEK3bsZPzTN57FTrqHhM8nb67ah1x65KfMaH8O8BsjGv/qEoo2Q066ti1Jw6phMxZaEB yyVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=F6OhZjf6; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m185si11095351pfm.258.2018.04.16.09.17.41; Mon, 16 Apr 2018 09:17:55 -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=pass header.i=@google.com header.s=20161025 header.b=F6OhZjf6; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753206AbeDPQP6 (ORCPT + 99 others); Mon, 16 Apr 2018 12:15:58 -0400 Received: from mail-it0-f53.google.com ([209.85.214.53]:40170 "EHLO mail-it0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753093AbeDPQP4 (ORCPT ); Mon, 16 Apr 2018 12:15:56 -0400 Received: by mail-it0-f53.google.com with SMTP id u62-v6so12269286ita.5 for ; Mon, 16 Apr 2018 09:15:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=j1743B9pdBZnqJaR5Li6eMPOlSErvNY6avokGibRr6c=; b=F6OhZjf6bMv0aWRg5xYPackzWH1BlNjtWzk7Nt1A+6jnFr19wAqB8DPBenm1bVKvm4 /o1nfs1AJxntjQjWWfJqqqtl3EDrYfDu7bBpf/ULaXGLTeOOGnQ9m0OnJJted4TiNh+/ SZsZRZdj7SJFu1fSQLLfLm8aLuT4izEnQXT+la53NWX38Ge/ff4G0rpZAo9/zH9aoyfn 3ekxIlKPj8MXX/AuhiVrL3Zyo/8TUzTOjmO1J7wNYjl+5zgpFkTn7v3d3wxU7+9x2ev+ ijxIQtQMQSwqNre0iloe0iVVc8Phx5Wx6FIHZl7vX+X2ye46xLhN9F3oCvC1kDrcDY3t PGfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=j1743B9pdBZnqJaR5Li6eMPOlSErvNY6avokGibRr6c=; b=E/BA4CobUpM2+ooMXcDL+5J/azLrUVA/C2JLSlzmvf4MtSw3IiWohv+F964hwtDpSK c1YsZo+eZ9wjijK2Avh1jk9grzI3Yo9B3OsX6fRRJiCU535enzgELuoucc/h1W0+9kHE MjTLViIiq2gBnIagzgELqkP2phnvWpYC7DAMHAhLRrVtRq2oxNStdoQXSTYJY58bfT1n DNNgywUGWOsdGSU9Pui3PtaHmGmWWYr0Wp3Sxiy5tKyVcrCWwB15eoZAjd7aumA7n/ab TjuauS6klpbDkEX/riOh6bZmYdl3sYN4WOwSNzUXF58pMRjs/NwgW1tU0ALrQhJkA2dy U+dQ== X-Gm-Message-State: ALQs6tAr8Qj85zqR13d/DO143r8BUcR9HbhjQXzLiCIJAQrtiCwqpdXg 3kppWaxUmWeUtmYxC/lZ+pp5sHw8EhQW8bYWmM6lUQ== X-Received: by 2002:a24:120d:: with SMTP id 13-v6mr16740358itp.53.1523895354909; Mon, 16 Apr 2018 09:15:54 -0700 (PDT) MIME-Version: 1.0 References: <20180414195921.GA10437@avx2> <20180414224419.GA21830@thunk.org> In-Reply-To: From: Thomas Garnier Date: Mon, 16 Apr 2018 16:15:44 +0000 Message-ID: Subject: Re: repeatable boot randomness inside KVM guest To: Kees Cook Cc: tytso@mit.edu, Alexey Dobriyan , LKML , Linux-MM 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 Mon, Apr 16, 2018 at 8:54 AM Kees Cook wrote: > 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. Entropy at early boot in VM has always been a problem for this feature or others. Did you look at the impact on other boot security features fetching random values? Does your VM had RDRAND support (we use get_random_long() which will fetch from RDRAND to provide as much entropy as possible at this point)? > > > > 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. You can't re-randomize pre-allocated pages that's why the cache is randomized that early. If you don't have RDRAND, we could re-randomize later at boot with more entropy that could be useful in this specific case. > > > > 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.... The state is seeded with get_random_long() which will use RDRAND and any available entropy at this point. I am not sure the value of calling get_random_long() on each iteration especially if you don't have RDRAND. > > > > (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. Thanks for including me. > -Kees > -- > Kees Cook > Pixel Security -- Thomas