From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754848AbcEXUWF (ORCPT ); Tue, 24 May 2016 16:22:05 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:35695 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751670AbcEXUWC (ORCPT ); Tue, 24 May 2016 16:22:02 -0400 Date: Tue, 24 May 2016 22:29:01 +0200 From: Emese Revfy To: Kees Cook Cc: "kernel-hardening@lists.openwall.com" , PaX Team , Brad Spengler , Michal Marek , LKML , Masahiro Yamada , linux-kbuild , "Theodore Ts'o" , Andrew Morton , Linux-MM , Jens Axboe , Al Viro , Paul McKenney , Ingo Molnar , Thomas Gleixner , bart.vanassche@sandisk.com, "David S. Miller" Subject: Re: [PATCH v1 3/3] Add the extra_latent_entropy kernel parameter Message-Id: <20160524222901.9c60f81a0e3a48df0654d5e6@gmail.com> In-Reply-To: References: <20160524001405.3e6abd1d5a63a871cc366cff@gmail.com> <20160524001736.135ae3cdc101ecec3232a493@gmail.com> X-Mailer: Sylpheed 3.5.0 (GTK+ 2.24.30; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 24 May 2016 10:09:16 -0700 Kees Cook wrote: > On Mon, May 23, 2016 at 3:17 PM, Emese Revfy wrote: > > @@ -1235,6 +1236,15 @@ static void __free_pages_ok(struct page *page, unsigned int order) > > } > > > > #ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY > > +bool __meminitdata extra_latent_entropy; > > + > > +static int __init setup_extra_latent_entropy(char *str) > > +{ > > + extra_latent_entropy = true; > > + return 0; > > +} > > +early_param("extra_latent_entropy", setup_extra_latent_entropy); > > + > > volatile u64 latent_entropy __latent_entropy; > > EXPORT_SYMBOL(latent_entropy); > > #endif > > @@ -1254,6 +1264,19 @@ static void __init __free_pages_boot_core(struct page *page, unsigned int order) > > __ClearPageReserved(p); > > set_page_count(p, 0); > > > > +#ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY > > + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) { > > + u64 hash = 0; > > + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash; > > + const u64 *data = lowmem_page_address(page); > > + > > + for (index = 0; index < end; index++) > > + hash ^= hash + data[index]; > > + latent_entropy ^= hash; > > + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy)); > > + } > > +#endif > > + > > We try to minimize #ifdefs in the .c code, so in this case, I think I > would define "extra_latent_entropy" during an #else above so this "if" > can be culled by the compiler automatically: > > #else > # define extra_latent_entropy false > #endif > > Others may have better suggestions to avoid the second #ifdef, but > this seems the cleanest way to me to tie this to the earlier #ifdef. Hi, I think the best way would be if I removed all #ifdefs because this is useful without the latent_entropy plugin. I don't know wether the default value of extra_latent_entropy should be true or false. I'll do some performance measurements. -- Emese