From patchwork Mon Jun 20 18:43:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emese Revfy X-Patchwork-Id: 9188513 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 692646089D for ; Mon, 20 Jun 2016 18:37:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59B5427BE5 for ; Mon, 20 Jun 2016 18:37:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E6EB27CF5; Mon, 20 Jun 2016 18:37:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C56427C39 for ; Mon, 20 Jun 2016 18:37:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933174AbcFTShP (ORCPT ); Mon, 20 Jun 2016 14:37:15 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33613 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933153AbcFTSg6 (ORCPT ); Mon, 20 Jun 2016 14:36:58 -0400 Received: by mail-wm0-f68.google.com with SMTP id r201so16121460wme.0; Mon, 20 Jun 2016 11:36:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lYfUlDKCzdUQpSbLKNtP97Y9gE0ATbS+HiOJ9AvSJKQ=; b=C8wLAgdlOyS/k4ZskDjrq3zA1h/pwmmnFsvu61DmBkL6ZWF2Uv8aqanikfDuf24pJu uNmNq3rgNy+ly8NoD36kt3v5t1CRDNz36zKypyNmMvFodkaCDWKFmyk3ZQtI706HG+vB ysKqRpKPWPmlKND87qU1jfZl6Yh3DADiCEY9cLa2YblmcK+w776X2Fo/mZz7XmDheCXM gV1fkuzdNPdPYybYUJBMKr8goosx6B0+9i3UjI3iwWoZRcbs0Xpa/PLNEZPR83iOgXyu iSYWNPvlOyNNpHKe2zk92KsK01mrmd70UAIMrbN30ShsZJsoGVc1/LTC5LZxRXmXxmH/ fRug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lYfUlDKCzdUQpSbLKNtP97Y9gE0ATbS+HiOJ9AvSJKQ=; b=dNqGhyz1Ba4iMs5kAeG97qXxDK5OjEWE9Mu/v6fcqZhxagIUNigd9YRwNaC18FQl2W IQlo0dakd+qqa4CtXNcYEkPLKdsiXrKcvGqBVq36sUziqILFotJOYU5DYHGybPW05zw9 ChdAg2W0Obw3FQeiBvSpFkIPDVaDhH6GpR4KRIvxvFt/agLAz4lEvJOVEXFd14zfg2l4 kZ0NfTDhiuldDk8y/Cp7tWhlL/CYzz9Jm3EA1L5LIARZ/7zPEkmHC9TqW4Zk+g8J9iu8 KYHdDsYFrEr046UDqaRkqTkaeKPUDCF5EIxiYzctuvmAkUlaStenzlkFgLuR3P8lxKhr fMfQ== X-Gm-Message-State: ALyK8tKQmHGEuqtThmMwEbXjskN7JmDJvAl+FRZ/NRLTojujD05pkoAu7IMeQCBMZ0p56Q== X-Received: by 10.28.45.142 with SMTP id t136mr658981wmt.40.1466447816515; Mon, 20 Jun 2016 11:36:56 -0700 (PDT) Received: from localhost (beleg.madhouse-project.org. [128.199.36.147]) by smtp.gmail.com with ESMTPSA id w188sm9262166wmw.11.2016.06.20.11.36.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jun 2016 11:36:55 -0700 (PDT) Date: Mon, 20 Jun 2016 20:43:36 +0200 From: Emese Revfy To: kernel-hardening@lists.openwall.com Cc: pageexec@freemail.hu, spender@grsecurity.net, mmarek@suse.com, keescook@chromium.org, linux-kernel@vger.kernel.org, yamada.masahiro@socionext.com, linux-kbuild@vger.kernel.org, tytso@mit.edu, akpm@linux-foundation.org, linux-mm@kvack.org, axboe@kernel.dk, viro@zeniv.linux.org.uk, paulmck@linux.vnet.ibm.com, mingo@redhat.com, tglx@linutronix.de, bart.vanassche@sandisk.com, davem@davemloft.net Subject: [PATCH v4 4/4] Add the extra_latent_entropy kernel parameter Message-Id: <20160620204336.9f5ca671b32acf298ab4bc17@gmail.com> In-Reply-To: <20160620203910.a8b6b5b10d18f24661916e7b@gmail.com> References: <20160620203910.a8b6b5b10d18f24661916e7b@gmail.com> X-Mailer: Sylpheed 3.5.0 (GTK+ 2.24.30; x86_64-pc-linux-gnu) Mime-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When extra_latent_entropy is passed on the kernel command line, entropy will be extracted from up to the first 4GB of RAM while the runtime memory allocator is being initialized. Based on work created by the PaX Team. Signed-off-by: Emese Revfy --- Documentation/kernel-parameters.txt | 5 +++++ arch/Kconfig | 5 +++++ mm/page_alloc.c | 26 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index 82b42c9..d870702 100644 --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt @@ -2862,6 +2862,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted. the specified number of seconds. This is to be used if your oopses keep scrolling off the screen. + extra_latent_entropy + Enable a very simple form of latent entropy extraction + from the first 4GB of memory as the bootmem allocator + passes the memory pages to the buddy allocator. + pcbit= [HW,ISDN] pcd. [PARIDE] diff --git a/arch/Kconfig b/arch/Kconfig index 4b7cc2f..3374d50 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -404,6 +404,11 @@ config GCC_PLUGIN_LATENT_ENTROPY is some slowdown of the boot process (about 0.5%) and fork and irq processing. + When extra_latent_entropy is passed on the kernel command line, + entropy will be extracted from up to the first 4GB of RAM while the + runtime memory allocator is being initialized. This costs even more + slowdown of the boot process. + Note that entropy extracted this way is not cryptographically secure! diff --git a/mm/page_alloc.c b/mm/page_alloc.c index ffc4f4a..0a40c12 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -63,6 +63,7 @@ #include #include #include +#include #include #include @@ -1234,6 +1235,15 @@ static void __free_pages_ok(struct page *page, unsigned int order) local_irq_restore(flags); } +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); + #ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY volatile u64 latent_entropy __latent_entropy; EXPORT_SYMBOL(latent_entropy); @@ -1254,6 +1264,22 @@ static void __init __free_pages_boot_core(struct page *page, unsigned int order) __ClearPageReserved(p); set_page_count(p, 0); + 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]; +#ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY + latent_entropy ^= hash; + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy)); +#else + add_device_randomness((const void *)&hash, sizeof(hash)); +#endif + } + page_zone(page)->managed_pages += nr_pages; set_page_refcounted(page); __free_pages(page, order);