Re: [PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization

2016-08-09 Thread Thomas Garnier
On Mon, Aug 8, 2016 at 10:16 PM, Mika Penttilä
 wrote:
> On 08/08/2016 09:40 PM, Thomas Garnier wrote:
>> Default implementation expects 6 pages maximum are needed for low page
>> allocations. If KASLR memory randomization is enabled, the worse case
>> of e820 layout would require 12 pages (no large pages). It is due to the
>> PUD level randomization and the variable e820 memory layout.
>>
>> This bug was found while doing extensive testing of KASLR memory
>> randomization on different type of hardware.
>>
>> Signed-off-by: Thomas Garnier 
>> ---
>> Based on next-20160805
>> ---
>>  arch/x86/mm/init.c | 8 
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
>> index 6209289..3a27e6a 100644
>> --- a/arch/x86/mm/init.c
>> +++ b/arch/x86/mm/init.c
>> @@ -130,6 +130,14 @@ void  __init early_alloc_pgt_buf(void)
>>   unsigned long tables = INIT_PGT_BUF_SIZE;
>>   phys_addr_t base;
>>
>> + /*
>> +  * Depending on the machine e860 memory layout and the PUD alignement.
>> +  * We may need twice more pages when KASLR memoy randomization is
>> +  * enabled.
>> +  */
>> + if (IS_ENABLED(CONFIG_RANDOMIZE_MEMORY))
>> + tables *= 2;
>> +
>>   base = __pa(extend_brk(tables, PAGE_SIZE));
>>
>>   pgt_buf_start = base >> PAGE_SHIFT;
>>
>
> You should increase the reserve also :
> RESERVE_BRK(early_pgt_alloc, INIT_PGT_BUF_SIZE);

Yes, that's right. I will resend v2 changing INIT_PGD_BUF_SIZE.

>
>
> --Mika
>


Re: [PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization

2016-08-09 Thread Thomas Garnier
On Mon, Aug 8, 2016 at 10:16 PM, Mika Penttilä
 wrote:
> On 08/08/2016 09:40 PM, Thomas Garnier wrote:
>> Default implementation expects 6 pages maximum are needed for low page
>> allocations. If KASLR memory randomization is enabled, the worse case
>> of e820 layout would require 12 pages (no large pages). It is due to the
>> PUD level randomization and the variable e820 memory layout.
>>
>> This bug was found while doing extensive testing of KASLR memory
>> randomization on different type of hardware.
>>
>> Signed-off-by: Thomas Garnier 
>> ---
>> Based on next-20160805
>> ---
>>  arch/x86/mm/init.c | 8 
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
>> index 6209289..3a27e6a 100644
>> --- a/arch/x86/mm/init.c
>> +++ b/arch/x86/mm/init.c
>> @@ -130,6 +130,14 @@ void  __init early_alloc_pgt_buf(void)
>>   unsigned long tables = INIT_PGT_BUF_SIZE;
>>   phys_addr_t base;
>>
>> + /*
>> +  * Depending on the machine e860 memory layout and the PUD alignement.
>> +  * We may need twice more pages when KASLR memoy randomization is
>> +  * enabled.
>> +  */
>> + if (IS_ENABLED(CONFIG_RANDOMIZE_MEMORY))
>> + tables *= 2;
>> +
>>   base = __pa(extend_brk(tables, PAGE_SIZE));
>>
>>   pgt_buf_start = base >> PAGE_SHIFT;
>>
>
> You should increase the reserve also :
> RESERVE_BRK(early_pgt_alloc, INIT_PGT_BUF_SIZE);

Yes, that's right. I will resend v2 changing INIT_PGD_BUF_SIZE.

>
>
> --Mika
>


Re: [PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization

2016-08-08 Thread Mika Penttilä
On 08/08/2016 09:40 PM, Thomas Garnier wrote:
> Default implementation expects 6 pages maximum are needed for low page
> allocations. If KASLR memory randomization is enabled, the worse case
> of e820 layout would require 12 pages (no large pages). It is due to the
> PUD level randomization and the variable e820 memory layout.
> 
> This bug was found while doing extensive testing of KASLR memory
> randomization on different type of hardware.
> 
> Signed-off-by: Thomas Garnier 
> ---
> Based on next-20160805
> ---
>  arch/x86/mm/init.c | 8 
>  1 file changed, 8 insertions(+)
> 
> diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
> index 6209289..3a27e6a 100644
> --- a/arch/x86/mm/init.c
> +++ b/arch/x86/mm/init.c
> @@ -130,6 +130,14 @@ void  __init early_alloc_pgt_buf(void)
>   unsigned long tables = INIT_PGT_BUF_SIZE;
>   phys_addr_t base;
>  
> + /*
> +  * Depending on the machine e860 memory layout and the PUD alignement.
> +  * We may need twice more pages when KASLR memoy randomization is
> +  * enabled.
> +  */
> + if (IS_ENABLED(CONFIG_RANDOMIZE_MEMORY))
> + tables *= 2;
> +
>   base = __pa(extend_brk(tables, PAGE_SIZE));
>  
>   pgt_buf_start = base >> PAGE_SHIFT;
> 

You should increase the reserve also :
RESERVE_BRK(early_pgt_alloc, INIT_PGT_BUF_SIZE);


--Mika



Re: [PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization

2016-08-08 Thread Mika Penttilä
On 08/08/2016 09:40 PM, Thomas Garnier wrote:
> Default implementation expects 6 pages maximum are needed for low page
> allocations. If KASLR memory randomization is enabled, the worse case
> of e820 layout would require 12 pages (no large pages). It is due to the
> PUD level randomization and the variable e820 memory layout.
> 
> This bug was found while doing extensive testing of KASLR memory
> randomization on different type of hardware.
> 
> Signed-off-by: Thomas Garnier 
> ---
> Based on next-20160805
> ---
>  arch/x86/mm/init.c | 8 
>  1 file changed, 8 insertions(+)
> 
> diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
> index 6209289..3a27e6a 100644
> --- a/arch/x86/mm/init.c
> +++ b/arch/x86/mm/init.c
> @@ -130,6 +130,14 @@ void  __init early_alloc_pgt_buf(void)
>   unsigned long tables = INIT_PGT_BUF_SIZE;
>   phys_addr_t base;
>  
> + /*
> +  * Depending on the machine e860 memory layout and the PUD alignement.
> +  * We may need twice more pages when KASLR memoy randomization is
> +  * enabled.
> +  */
> + if (IS_ENABLED(CONFIG_RANDOMIZE_MEMORY))
> + tables *= 2;
> +
>   base = __pa(extend_brk(tables, PAGE_SIZE));
>  
>   pgt_buf_start = base >> PAGE_SHIFT;
> 

You should increase the reserve also :
RESERVE_BRK(early_pgt_alloc, INIT_PGT_BUF_SIZE);


--Mika



Re: [PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization

2016-08-08 Thread H. Peter Anvin
On August 8, 2016 9:01:42 PM PDT, Borislav Petkov  wrote:
>On Mon, Aug 08, 2016 at 11:40:07AM -0700, Thomas Garnier wrote:
>> Default implementation expects 6 pages maximum are needed for low
>page
>> allocations. If KASLR memory randomization is enabled, the worse case
>> of e820 layout would require 12 pages (no large pages). It is due to
>the
>> PUD level randomization and the variable e820 memory layout.
>
>Can't this number of required pages be computed based on the
>randomization offset or somesuch instead of maxing it out by default on
>every machine which enables CONFIG_RANDOMIZE_MEMORY?
>
>> This bug was found while doing extensive testing of KASLR memory
>> randomization on different type of hardware.
>> 
>> Signed-off-by: Thomas Garnier 
>> ---
>> Based on next-20160805
>> ---
>>  arch/x86/mm/init.c | 8 
>>  1 file changed, 8 insertions(+)
>> 
>> diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
>> index 6209289..3a27e6a 100644
>> --- a/arch/x86/mm/init.c
>> +++ b/arch/x86/mm/init.c
>> @@ -130,6 +130,14 @@ void  __init early_alloc_pgt_buf(void)
>>  unsigned long tables = INIT_PGT_BUF_SIZE;
>>  phys_addr_t base;
>>  
>> +/*
>> + * Depending on the machine e860 memory layout and the PUD
>alignement.
>
>   e820   alignment
>
>> + * We may need twice more pages when KASLR memoy randomization is
>
> memory
>
>> + * enabled.
>> + */
>> +if (IS_ENABLED(CONFIG_RANDOMIZE_MEMORY))
>> +tables *= 2;
>> +
>>  base = __pa(extend_brk(tables, PAGE_SIZE));
>>  
>>  pgt_buf_start = base >> PAGE_SHIFT;
>> -- 
>> 2.8.0.rc3.226.g39d4020
>> 

Upping the brk by a few pages is not a big deal.  Unused brk gets reclaimed at 
init release time.
-- 
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.


Re: [PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization

2016-08-08 Thread H. Peter Anvin
On August 8, 2016 9:01:42 PM PDT, Borislav Petkov  wrote:
>On Mon, Aug 08, 2016 at 11:40:07AM -0700, Thomas Garnier wrote:
>> Default implementation expects 6 pages maximum are needed for low
>page
>> allocations. If KASLR memory randomization is enabled, the worse case
>> of e820 layout would require 12 pages (no large pages). It is due to
>the
>> PUD level randomization and the variable e820 memory layout.
>
>Can't this number of required pages be computed based on the
>randomization offset or somesuch instead of maxing it out by default on
>every machine which enables CONFIG_RANDOMIZE_MEMORY?
>
>> This bug was found while doing extensive testing of KASLR memory
>> randomization on different type of hardware.
>> 
>> Signed-off-by: Thomas Garnier 
>> ---
>> Based on next-20160805
>> ---
>>  arch/x86/mm/init.c | 8 
>>  1 file changed, 8 insertions(+)
>> 
>> diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
>> index 6209289..3a27e6a 100644
>> --- a/arch/x86/mm/init.c
>> +++ b/arch/x86/mm/init.c
>> @@ -130,6 +130,14 @@ void  __init early_alloc_pgt_buf(void)
>>  unsigned long tables = INIT_PGT_BUF_SIZE;
>>  phys_addr_t base;
>>  
>> +/*
>> + * Depending on the machine e860 memory layout and the PUD
>alignement.
>
>   e820   alignment
>
>> + * We may need twice more pages when KASLR memoy randomization is
>
> memory
>
>> + * enabled.
>> + */
>> +if (IS_ENABLED(CONFIG_RANDOMIZE_MEMORY))
>> +tables *= 2;
>> +
>>  base = __pa(extend_brk(tables, PAGE_SIZE));
>>  
>>  pgt_buf_start = base >> PAGE_SHIFT;
>> -- 
>> 2.8.0.rc3.226.g39d4020
>> 

Upping the brk by a few pages is not a big deal.  Unused brk gets reclaimed at 
init release time.
-- 
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.


Re: [PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization

2016-08-08 Thread Borislav Petkov
On Mon, Aug 08, 2016 at 11:40:07AM -0700, Thomas Garnier wrote:
> Default implementation expects 6 pages maximum are needed for low page
> allocations. If KASLR memory randomization is enabled, the worse case
> of e820 layout would require 12 pages (no large pages). It is due to the
> PUD level randomization and the variable e820 memory layout.

Can't this number of required pages be computed based on the
randomization offset or somesuch instead of maxing it out by default on
every machine which enables CONFIG_RANDOMIZE_MEMORY?

> This bug was found while doing extensive testing of KASLR memory
> randomization on different type of hardware.
> 
> Signed-off-by: Thomas Garnier 
> ---
> Based on next-20160805
> ---
>  arch/x86/mm/init.c | 8 
>  1 file changed, 8 insertions(+)
> 
> diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
> index 6209289..3a27e6a 100644
> --- a/arch/x86/mm/init.c
> +++ b/arch/x86/mm/init.c
> @@ -130,6 +130,14 @@ void  __init early_alloc_pgt_buf(void)
>   unsigned long tables = INIT_PGT_BUF_SIZE;
>   phys_addr_t base;
>  
> + /*
> +  * Depending on the machine e860 memory layout and the PUD alignement.

e820   alignment

> +  * We may need twice more pages when KASLR memoy randomization is

  memory

> +  * enabled.
> +  */
> + if (IS_ENABLED(CONFIG_RANDOMIZE_MEMORY))
> + tables *= 2;
> +
>   base = __pa(extend_brk(tables, PAGE_SIZE));
>  
>   pgt_buf_start = base >> PAGE_SHIFT;
> -- 
> 2.8.0.rc3.226.g39d4020
> 

-- 
Regards/Gruss,
Boris.

ECO tip #101: Trim your mails when you reply.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 
(AG Nürnberg)
--


Re: [PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization

2016-08-08 Thread Borislav Petkov
On Mon, Aug 08, 2016 at 11:40:07AM -0700, Thomas Garnier wrote:
> Default implementation expects 6 pages maximum are needed for low page
> allocations. If KASLR memory randomization is enabled, the worse case
> of e820 layout would require 12 pages (no large pages). It is due to the
> PUD level randomization and the variable e820 memory layout.

Can't this number of required pages be computed based on the
randomization offset or somesuch instead of maxing it out by default on
every machine which enables CONFIG_RANDOMIZE_MEMORY?

> This bug was found while doing extensive testing of KASLR memory
> randomization on different type of hardware.
> 
> Signed-off-by: Thomas Garnier 
> ---
> Based on next-20160805
> ---
>  arch/x86/mm/init.c | 8 
>  1 file changed, 8 insertions(+)
> 
> diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
> index 6209289..3a27e6a 100644
> --- a/arch/x86/mm/init.c
> +++ b/arch/x86/mm/init.c
> @@ -130,6 +130,14 @@ void  __init early_alloc_pgt_buf(void)
>   unsigned long tables = INIT_PGT_BUF_SIZE;
>   phys_addr_t base;
>  
> + /*
> +  * Depending on the machine e860 memory layout and the PUD alignement.

e820   alignment

> +  * We may need twice more pages when KASLR memoy randomization is

  memory

> +  * enabled.
> +  */
> + if (IS_ENABLED(CONFIG_RANDOMIZE_MEMORY))
> + tables *= 2;
> +
>   base = __pa(extend_brk(tables, PAGE_SIZE));
>  
>   pgt_buf_start = base >> PAGE_SHIFT;
> -- 
> 2.8.0.rc3.226.g39d4020
> 

-- 
Regards/Gruss,
Boris.

ECO tip #101: Trim your mails when you reply.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 
(AG Nürnberg)
--


[PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization

2016-08-08 Thread Thomas Garnier
Default implementation expects 6 pages maximum are needed for low page
allocations. If KASLR memory randomization is enabled, the worse case
of e820 layout would require 12 pages (no large pages). It is due to the
PUD level randomization and the variable e820 memory layout.

This bug was found while doing extensive testing of KASLR memory
randomization on different type of hardware.

Signed-off-by: Thomas Garnier 
---
Based on next-20160805
---
 arch/x86/mm/init.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 6209289..3a27e6a 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -130,6 +130,14 @@ void  __init early_alloc_pgt_buf(void)
unsigned long tables = INIT_PGT_BUF_SIZE;
phys_addr_t base;
 
+   /*
+* Depending on the machine e860 memory layout and the PUD alignement.
+* We may need twice more pages when KASLR memoy randomization is
+* enabled.
+*/
+   if (IS_ENABLED(CONFIG_RANDOMIZE_MEMORY))
+   tables *= 2;
+
base = __pa(extend_brk(tables, PAGE_SIZE));
 
pgt_buf_start = base >> PAGE_SHIFT;
-- 
2.8.0.rc3.226.g39d4020



[PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization

2016-08-08 Thread Thomas Garnier
Default implementation expects 6 pages maximum are needed for low page
allocations. If KASLR memory randomization is enabled, the worse case
of e820 layout would require 12 pages (no large pages). It is due to the
PUD level randomization and the variable e820 memory layout.

This bug was found while doing extensive testing of KASLR memory
randomization on different type of hardware.

Signed-off-by: Thomas Garnier 
---
Based on next-20160805
---
 arch/x86/mm/init.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 6209289..3a27e6a 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -130,6 +130,14 @@ void  __init early_alloc_pgt_buf(void)
unsigned long tables = INIT_PGT_BUF_SIZE;
phys_addr_t base;
 
+   /*
+* Depending on the machine e860 memory layout and the PUD alignement.
+* We may need twice more pages when KASLR memoy randomization is
+* enabled.
+*/
+   if (IS_ENABLED(CONFIG_RANDOMIZE_MEMORY))
+   tables *= 2;
+
base = __pa(extend_brk(tables, PAGE_SIZE));
 
pgt_buf_start = base >> PAGE_SHIFT;
-- 
2.8.0.rc3.226.g39d4020