All of lore.kernel.org
 help / color / mirror / Atom feed
From: Balbir Singh <bsingharora@gmail.com>
To: Kees Cook <keescook@chromium.org>, linux-kernel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Emese Revfy <re.emese@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Vlastimil Babka <vbabka@suse.cz>,
	Mel Gorman <mgorman@techsingularity.net>,
	Michal Hocko <mhocko@suse.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Taku Izumi <izumi.taku@jp.fujitsu.com>,
	linux-doc@vger.kernel.org, linux-mm@kvack.org,
	kernel-hardening@lists.openwall.com
Subject: Re: [PATCH] mm: Add the ram_latent_entropy kernel parameter
Date: Fri, 12 Aug 2016 13:52:21 +1000	[thread overview]
Message-ID: <99df3a39-ecf1-90a0-2649-fa0bda270ceb@gmail.com> (raw)
In-Reply-To: <20160810222805.GA13733@www.outflux.net>



On 11/08/16 08:28, Kees Cook wrote:
> From: Emese Revfy <re.emese@gmail.com>
> 
> When "ram_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 entropy isn't cryptographically
> secure, but does help provide additional unpredictability on otherwise
> low-entropy systems.
> 
> Based on work created by the PaX Team.
> 
> Signed-off-by: Emese Revfy <re.emese@gmail.com>
> [kees: renamed parameter, dropped relationship with plugin, updated log]
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> This patch has been extracted from the latent_entropy gcc plugin, as
> suggested by Linus: https://lkml.org/lkml/2016/8/8/840
> ---
>  Documentation/kernel-parameters.txt |  5 +++++
>  mm/page_alloc.c                     | 21 +++++++++++++++++++++
>  2 files changed, 26 insertions(+)
> 
> diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
> index 46c030a49186..9d054984370f 100644
> --- a/Documentation/kernel-parameters.txt
> +++ b/Documentation/kernel-parameters.txt
> @@ -3245,6 +3245,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
>  	raid=		[HW,RAID]
>  			See Documentation/md.txt.
>  
> +	ram_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.
> +
>  	ramdisk_size=	[RAM] Sizes of RAM disks in kilobytes
>  			See Documentation/blockdev/ramdisk.txt.
>  
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index fb975cec3518..1de94f0ff29d 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -64,6 +64,7 @@
>  #include <linux/page_owner.h>
>  #include <linux/kthread.h>
>  #include <linux/memcontrol.h>
> +#include <linux/random.h>
>  
>  #include <asm/sections.h>
>  #include <asm/tlbflush.h>
> @@ -1236,6 +1237,15 @@ static void __free_pages_ok(struct page *page, unsigned int order)
>  	local_irq_restore(flags);
>  }
>  
> +bool __meminitdata ram_latent_entropy;
> +
> +static int __init setup_ram_latent_entropy(char *str)
> +{
> +	ram_latent_entropy = true;
> +	return 0;
> +}
> +early_param("ram_latent_entropy", setup_ram_latent_entropy);
> +
>  static void __init __free_pages_boot_core(struct page *page, unsigned int order)
>  {
>  	unsigned int nr_pages = 1 << order;
> @@ -1251,6 +1261,17 @@ static void __init __free_pages_boot_core(struct page *page, unsigned int order)
>  	__ClearPageReserved(p);
>  	set_page_count(p, 0);
>  
> +	if (ram_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];

Won't the hash be the same across boots? Is this entropy addition for
KASLR, since it is so early in boot?q

> +		add_device_randomness((const void *)&hash, sizeof(hash));
> +	}
> +
>  	page_zone(page)->managed_pages += nr_pages;
>  	set_page_refcounted(page);
>  	__free_pages(page, order);
> 


Balbir Singh

WARNING: multiple messages have this Message-ID (diff)
From: Balbir Singh <bsingharora@gmail.com>
To: Kees Cook <keescook@chromium.org>, linux-kernel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Emese Revfy <re.emese@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Vlastimil Babka <vbabka@suse.cz>,
	Mel Gorman <mgorman@techsingularity.net>,
	Michal Hocko <mhocko@suse.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Taku Izumi <izumi.taku@jp.fujitsu.com>,
	linux-doc@vger.kernel.org, linux-mm@kvack.org,
	kernel-hardening@lists.openwall.com
Subject: Re: [PATCH] mm: Add the ram_latent_entropy kernel parameter
Date: Fri, 12 Aug 2016 13:52:21 +1000	[thread overview]
Message-ID: <99df3a39-ecf1-90a0-2649-fa0bda270ceb@gmail.com> (raw)
In-Reply-To: <20160810222805.GA13733@www.outflux.net>



On 11/08/16 08:28, Kees Cook wrote:
> From: Emese Revfy <re.emese@gmail.com>
> 
> When "ram_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 entropy isn't cryptographically
> secure, but does help provide additional unpredictability on otherwise
> low-entropy systems.
> 
> Based on work created by the PaX Team.
> 
> Signed-off-by: Emese Revfy <re.emese@gmail.com>
> [kees: renamed parameter, dropped relationship with plugin, updated log]
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> This patch has been extracted from the latent_entropy gcc plugin, as
> suggested by Linus: https://lkml.org/lkml/2016/8/8/840
> ---
>  Documentation/kernel-parameters.txt |  5 +++++
>  mm/page_alloc.c                     | 21 +++++++++++++++++++++
>  2 files changed, 26 insertions(+)
> 
> diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
> index 46c030a49186..9d054984370f 100644
> --- a/Documentation/kernel-parameters.txt
> +++ b/Documentation/kernel-parameters.txt
> @@ -3245,6 +3245,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
>  	raid=		[HW,RAID]
>  			See Documentation/md.txt.
>  
> +	ram_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.
> +
>  	ramdisk_size=	[RAM] Sizes of RAM disks in kilobytes
>  			See Documentation/blockdev/ramdisk.txt.
>  
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index fb975cec3518..1de94f0ff29d 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -64,6 +64,7 @@
>  #include <linux/page_owner.h>
>  #include <linux/kthread.h>
>  #include <linux/memcontrol.h>
> +#include <linux/random.h>
>  
>  #include <asm/sections.h>
>  #include <asm/tlbflush.h>
> @@ -1236,6 +1237,15 @@ static void __free_pages_ok(struct page *page, unsigned int order)
>  	local_irq_restore(flags);
>  }
>  
> +bool __meminitdata ram_latent_entropy;
> +
> +static int __init setup_ram_latent_entropy(char *str)
> +{
> +	ram_latent_entropy = true;
> +	return 0;
> +}
> +early_param("ram_latent_entropy", setup_ram_latent_entropy);
> +
>  static void __init __free_pages_boot_core(struct page *page, unsigned int order)
>  {
>  	unsigned int nr_pages = 1 << order;
> @@ -1251,6 +1261,17 @@ static void __init __free_pages_boot_core(struct page *page, unsigned int order)
>  	__ClearPageReserved(p);
>  	set_page_count(p, 0);
>  
> +	if (ram_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];

Won't the hash be the same across boots? Is this entropy addition for
KASLR, since it is so early in boot?q

> +		add_device_randomness((const void *)&hash, sizeof(hash));
> +	}
> +
>  	page_zone(page)->managed_pages += nr_pages;
>  	set_page_refcounted(page);
>  	__free_pages(page, order);
> 


Balbir Singh

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

WARNING: multiple messages have this Message-ID (diff)
From: Balbir Singh <bsingharora@gmail.com>
To: Kees Cook <keescook@chromium.org>, linux-kernel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Emese Revfy <re.emese@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Vlastimil Babka <vbabka@suse.cz>,
	Mel Gorman <mgorman@techsingularity.net>,
	Michal Hocko <mhocko@suse.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Taku Izumi <izumi.taku@jp.fujitsu.com>,
	linux-doc@vger.kernel.org, linux-mm@kvack.org,
	kernel-hardening@lists.openwall.com
Subject: [kernel-hardening] Re: [PATCH] mm: Add the ram_latent_entropy kernel parameter
Date: Fri, 12 Aug 2016 13:52:21 +1000	[thread overview]
Message-ID: <99df3a39-ecf1-90a0-2649-fa0bda270ceb@gmail.com> (raw)
In-Reply-To: <20160810222805.GA13733@www.outflux.net>



On 11/08/16 08:28, Kees Cook wrote:
> From: Emese Revfy <re.emese@gmail.com>
> 
> When "ram_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 entropy isn't cryptographically
> secure, but does help provide additional unpredictability on otherwise
> low-entropy systems.
> 
> Based on work created by the PaX Team.
> 
> Signed-off-by: Emese Revfy <re.emese@gmail.com>
> [kees: renamed parameter, dropped relationship with plugin, updated log]
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> This patch has been extracted from the latent_entropy gcc plugin, as
> suggested by Linus: https://lkml.org/lkml/2016/8/8/840
> ---
>  Documentation/kernel-parameters.txt |  5 +++++
>  mm/page_alloc.c                     | 21 +++++++++++++++++++++
>  2 files changed, 26 insertions(+)
> 
> diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
> index 46c030a49186..9d054984370f 100644
> --- a/Documentation/kernel-parameters.txt
> +++ b/Documentation/kernel-parameters.txt
> @@ -3245,6 +3245,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
>  	raid=		[HW,RAID]
>  			See Documentation/md.txt.
>  
> +	ram_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.
> +
>  	ramdisk_size=	[RAM] Sizes of RAM disks in kilobytes
>  			See Documentation/blockdev/ramdisk.txt.
>  
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index fb975cec3518..1de94f0ff29d 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -64,6 +64,7 @@
>  #include <linux/page_owner.h>
>  #include <linux/kthread.h>
>  #include <linux/memcontrol.h>
> +#include <linux/random.h>
>  
>  #include <asm/sections.h>
>  #include <asm/tlbflush.h>
> @@ -1236,6 +1237,15 @@ static void __free_pages_ok(struct page *page, unsigned int order)
>  	local_irq_restore(flags);
>  }
>  
> +bool __meminitdata ram_latent_entropy;
> +
> +static int __init setup_ram_latent_entropy(char *str)
> +{
> +	ram_latent_entropy = true;
> +	return 0;
> +}
> +early_param("ram_latent_entropy", setup_ram_latent_entropy);
> +
>  static void __init __free_pages_boot_core(struct page *page, unsigned int order)
>  {
>  	unsigned int nr_pages = 1 << order;
> @@ -1251,6 +1261,17 @@ static void __init __free_pages_boot_core(struct page *page, unsigned int order)
>  	__ClearPageReserved(p);
>  	set_page_count(p, 0);
>  
> +	if (ram_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];

Won't the hash be the same across boots? Is this entropy addition for
KASLR, since it is so early in boot?q

> +		add_device_randomness((const void *)&hash, sizeof(hash));
> +	}
> +
>  	page_zone(page)->managed_pages += nr_pages;
>  	set_page_refcounted(page);
>  	__free_pages(page, order);
> 


Balbir Singh

  parent reply	other threads:[~2016-08-12  3:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-10 22:28 [PATCH] mm: Add the ram_latent_entropy kernel parameter Kees Cook
2016-08-10 22:28 ` [kernel-hardening] " Kees Cook
2016-08-10 22:28 ` Kees Cook
2016-08-11 15:39 ` Dave Hansen
2016-08-11 15:39   ` [kernel-hardening] " Dave Hansen
2016-08-11 15:39   ` Dave Hansen
2016-08-12  3:52 ` Balbir Singh [this message]
2016-08-12  3:52   ` [kernel-hardening] " Balbir Singh
2016-08-12  3:52   ` Balbir Singh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=99df3a39-ecf1-90a0-2649-fa0bda270ceb@gmail.com \
    --to=bsingharora@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=corbet@lwn.net \
    --cc=hannes@cmpxchg.org \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=izumi.taku@jp.fujitsu.com \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@suse.com \
    --cc=re.emese@gmail.com \
    --cc=torvalds@linux-foundation.org \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.