Skip to content

Commit

Permalink
gather extra early boot entropy like PaX
Browse files Browse the repository at this point in the history
Signed-off-by: khusika <khusikadhamar@gmail.com>
  • Loading branch information
thestinger authored and khusika committed Aug 28, 2018
1 parent ed3c52a commit 4cce657
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include <linux/page-debug-flags.h>
#include <linux/hugetlb.h>
#include <linux/sched/rt.h>
#include <linux/random.h>

#include <asm/sections.h>
#include <asm/tlbflush.h>
Expand Down Expand Up @@ -843,6 +844,16 @@ void __free_pages_bootmem(struct page *page, unsigned long pfn,
__ClearPageReserved(p);
set_page_count(p, 0);

if (!PageHighMem(page) && page_to_pfn(page) < 0x100000) {
unsigned long hash = 0;
size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
const unsigned long *data = lowmem_page_address(page);

for (index = 0; index < end; index++)
hash ^= hash + data[index];
add_device_randomness((const void *)&hash, sizeof(hash));
}

page_zone(page)->managed_pages += nr_pages;
set_page_refcounted(page);
__free_pages(page, order);
Expand Down

0 comments on commit 4cce657

Please sign in to comment.