From patchwork Tue Jun 14 22:22:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emese Revfy X-Patchwork-Id: 9177055 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 8779060772 for ; Tue, 14 Jun 2016 22:16:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77AE426490 for ; Tue, 14 Jun 2016 22:16:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C46128339; Tue, 14 Jun 2016 22:16:04 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 94B1826490 for ; Tue, 14 Jun 2016 22:16:03 +0000 (UTC) Received: (qmail 29870 invoked by uid 550); 14 Jun 2016 22:16:01 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: kernel-hardening@lists.openwall.com Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 29852 invoked from network); 14 Jun 2016 22:16:00 -0000 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=JjymZz2uhHCvPzmtlt3GvEBeElqLMEyz88V7qTna/FQ=; b=eYaCGXeFRVV/IGdMOfCK9mPdx5raEbazjKYrIPoes1T3PIImS4GRHQdwJ6Ikc+AW1t 7Rym9FQmoOjaHLlxvXGegIqLxDupbrlrTvohonMkueg86LkXYEePtqH9SHOWA/3SOmkz 7Gb1q+sO6gJA0//t/STVYeQskAZPAj93DiP0vgXZDNbszZ0IQoIAc7vIVwkOro+rgtNI +k/rcc7s1EyV+qtit6+wiXf/+Ug8405a7WjV5L2HqXDc+4gTyT2vuswcBF104rSfCBxk SnBkMw4F2UUfz/5ac3PFkhv+at3/l0GsPCxJHtT/K0xPNyIXuBmunWzMhZZBOtx+zp1L I3Yw== 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=JjymZz2uhHCvPzmtlt3GvEBeElqLMEyz88V7qTna/FQ=; b=kVIkAmyQ6xkJAE1hF25Toyy3pvqirFHJ3iwxWiFbiJ28Y3CTENKkcryR0xTcvBMd1F jSs9ghoGHpDxsH/DME1c5su6OLBOyLNnuO8V1xuMWYZdbRIAG/6KXPjxQv8Idt6cYICy d+CVlzeyEuC0whG2eJG37yjZS3aLoatSbYrHAq6DfZvDH52TUesfSMrhMcGtZZzcB317 JU7r0JUB5B1oCbG19pc6sxyBg2NY4O9P3jEgmzGbRdBmkcWyh5NRRVN6UDtvggqNk52h 3BbDJo04cE+2DV5ZyzK5JWQoOJIGuHHOg81rEUayTHCNV42+BQGnHmJgzw2a46Sl9Ad2 JLhw== X-Gm-Message-State: ALyK8tJazavBKonbwGFztqPJ6H4/YQWbfqpsMRZu4MvUFXzflCdLIx064dgKL43SqglzKA== X-Received: by 10.194.37.40 with SMTP id v8mr8021639wjj.161.1465942549457; Tue, 14 Jun 2016 15:15:49 -0700 (PDT) Date: Wed, 15 Jun 2016 00:22:37 +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 Message-Id: <20160615002237.87ab511f3ed4420923476c02@gmail.com> In-Reply-To: <20160615001754.f9e986cf961d1466f5e086dc@gmail.com> References: <20160615001754.f9e986cf961d1466f5e086dc@gmail.com> X-Mailer: Sylpheed 3.5.0 (GTK+ 2.24.30; x86_64-pc-linux-gnu) Mime-Version: 1.0 Subject: [kernel-hardening] [PATCH v3 4/4] Add the extra_latent_entropy kernel parameter 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 | 25 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index 5349363..6c2496e 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 c099ebd..8bf832e 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -405,6 +405,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 known to be cryptographically secure! diff --git a/mm/page_alloc.c b/mm/page_alloc.c index ffc4f4a..72c61bd 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,21 @@ 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);