Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1457985 > unrolled thread
| Started by | Thomas Garnier <thgarnie@google.com> |
|---|---|
| First post | 2016-08-08 20:50 +0200 |
| Last post | 2016-08-09 18:10 +0200 |
| Articles | 8 — 4 participants |
Back to article view | Back to linux.kernel
[PATCH v1 1/2] x86/KASLR: Fix physical memory calculation on KASLR memory randomization Thomas Garnier <thgarnie@google.com> - 2016-08-08 20:50 +0200
[PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization Thomas Garnier <thgarnie@google.com> - 2016-08-08 20:50 +0200
Re: [PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization Borislav Petkov <bp@suse.de> - 2016-08-09 06:10 +0200
Re: [PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization "H. Peter Anvin" <hpa@zytor.com> - 2016-08-09 06:20 +0200
Re: [PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization Thomas Garnier <thgarnie@google.com> - 2016-08-09 17:00 +0200
Re: [PATCH v1 1/2] x86/KASLR: Fix physical memory calculation on KASLR memory randomization Joerg Roedel <jroedel@suse.de> - 2016-08-09 18:10 +0200
Re: [PATCH v1 1/2] x86/KASLR: Fix physical memory calculation on KASLR memory randomization Thomas Garnier <thgarnie@google.com> - 2016-08-09 18:40 +0200
Re: [PATCH v1 1/2] x86/KASLR: Fix physical memory calculation on KASLR memory randomization Thomas Garnier <thgarnie@google.com> - 2016-08-09 18:10 +0200
| From | Thomas Garnier <thgarnie@google.com> |
|---|---|
| Date | 2016-08-08 20:50 +0200 |
| Subject | [PATCH v1 1/2] x86/KASLR: Fix physical memory calculation on KASLR memory randomization |
| Message-ID | <s3XMC-52s-9@gated-at.bofh.it> |
Initialize KASLR memory randomization after max_pfn is initialized. Also ensure the size is rounded up. Could have create problems on machines with more than 1Tb of memory on certain random addresses. Signed-off-by: Thomas Garnier <thgarnie@google.com> --- Based on next-20160805 --- arch/x86/kernel/setup.c | 4 ++-- arch/x86/mm/kaslr.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index bcabb88..8dda0ce 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -936,8 +936,6 @@ void __init setup_arch(char **cmdline_p) x86_init.oem.arch_setup(); - kernel_randomize_memory(); - iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1; setup_memory_map(); parse_setup_data(); @@ -1071,6 +1069,8 @@ void __init setup_arch(char **cmdline_p) high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1; #endif + kernel_randomize_memory(); + /* * Find and reserve possible boot-time SMP configuration: */ diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c index 26dccd6..ec8654f 100644 --- a/arch/x86/mm/kaslr.c +++ b/arch/x86/mm/kaslr.c @@ -97,7 +97,7 @@ void __init kernel_randomize_memory(void) * add padding if needed (especially for memory hotplug support). */ BUG_ON(kaslr_regions[0].base != &page_offset_base); - memory_tb = ((max_pfn << PAGE_SHIFT) >> TB_SHIFT) + + memory_tb = DIV_ROUND_UP(max_pfn << PAGE_SHIFT, 1UL << TB_SHIFT) + CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING; /* Adapt phyiscal memory region size based on available memory */ -- 2.8.0.rc3.226.g39d4020
[toc] | [next] | [standalone]
| From | Thomas Garnier <thgarnie@google.com> |
|---|---|
| Date | 2016-08-08 20:50 +0200 |
| Subject | [PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization |
| Message-ID | <s3XMC-52s-17@gated-at.bofh.it> |
| In reply to | #1457985 |
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 <thgarnie@google.com> --- 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
[toc] | [prev] | [next] | [standalone]
| From | Borislav Petkov <bp@suse.de> |
|---|---|
| Date | 2016-08-09 06:10 +0200 |
| Subject | Re: [PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization |
| Message-ID | <s46wx-2tH-3@gated-at.bofh.it> |
| In reply to | #1457988 |
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 <thgarnie@google.com>
> ---
> 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)
--
[toc] | [prev] | [next] | [standalone]
| From | "H. Peter Anvin" <hpa@zytor.com> |
|---|---|
| Date | 2016-08-09 06:20 +0200 |
| Subject | Re: [PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization |
| Message-ID | <s46Gd-2wQ-1@gated-at.bofh.it> |
| In reply to | #1458391 |
On August 8, 2016 9:01:42 PM PDT, Borislav Petkov <bp@suse.de> 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 <thgarnie@google.com> >> --- >> 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.
[toc] | [prev] | [next] | [standalone]
| From | Thomas Garnier <thgarnie@google.com> |
|---|---|
| Date | 2016-08-09 17:00 +0200 |
| Subject | Re: [PATCH v1 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization |
| Message-ID | <s4gFz-ve-5@gated-at.bofh.it> |
| In reply to | #1457988 |
On Mon, Aug 8, 2016 at 10:16 PM, Mika Penttilä <mika.penttila@nextfour.com> 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 <thgarnie@google.com> >> --- >> 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 >
[toc] | [prev] | [next] | [standalone]
| From | Joerg Roedel <jroedel@suse.de> |
|---|---|
| Date | 2016-08-09 18:10 +0200 |
| Subject | Re: [PATCH v1 1/2] x86/KASLR: Fix physical memory calculation on KASLR memory randomization |
| Message-ID | <s4hLj-1pO-13@gated-at.bofh.it> |
| In reply to | #1457985 |
On Tue, Aug 09, 2016 at 09:00:04AM -0700, Thomas Garnier wrote: > On Mon, Aug 8, 2016 at 11:40 AM, Thomas Garnier <thgarnie@google.com> wrote: > > Initialize KASLR memory randomization after max_pfn is initialized. Also > > ensure the size is rounded up. Could have create problems on machines > > with more than 1Tb of memory on certain random addresses. > > > > Signed-off-by: Thomas Garnier <thgarnie@google.com> > > I will send a new version of this PATCH soon. The test bot found > places where virtual addresses were computed before PAGE_OFFSET was > set. I will investigate that. When you do that, please also add 'Fixes:' tags to your patches. Thanks, Joerg
[toc] | [prev] | [next] | [standalone]
| From | Thomas Garnier <thgarnie@google.com> |
|---|---|
| Date | 2016-08-09 18:40 +0200 |
| Subject | Re: [PATCH v1 1/2] x86/KASLR: Fix physical memory calculation on KASLR memory randomization |
| Message-ID | <s4iel-1Aq-33@gated-at.bofh.it> |
| In reply to | #1458882 |
On Tue, Aug 9, 2016 at 9:03 AM, Joerg Roedel <jroedel@suse.de> wrote: > On Tue, Aug 09, 2016 at 09:00:04AM -0700, Thomas Garnier wrote: >> On Mon, Aug 8, 2016 at 11:40 AM, Thomas Garnier <thgarnie@google.com> wrote: >> > Initialize KASLR memory randomization after max_pfn is initialized. Also >> > ensure the size is rounded up. Could have create problems on machines >> > with more than 1Tb of memory on certain random addresses. >> > >> > Signed-off-by: Thomas Garnier <thgarnie@google.com> >> >> I will send a new version of this PATCH soon. The test bot found >> places where virtual addresses were computed before PAGE_OFFSET was >> set. I will investigate that. > > When you do that, please also add 'Fixes:' tags to your patches. > Will do. > Thanks, > > Joerg >
[toc] | [prev] | [next] | [standalone]
| From | Thomas Garnier <thgarnie@google.com> |
|---|---|
| Date | 2016-08-09 18:10 +0200 |
| Subject | Re: [PATCH v1 1/2] x86/KASLR: Fix physical memory calculation on KASLR memory randomization |
| Message-ID | <s4hLj-1pO-15@gated-at.bofh.it> |
| In reply to | #1457985 |
On Mon, Aug 8, 2016 at 11:40 AM, Thomas Garnier <thgarnie@google.com> wrote: > Initialize KASLR memory randomization after max_pfn is initialized. Also > ensure the size is rounded up. Could have create problems on machines > with more than 1Tb of memory on certain random addresses. > > Signed-off-by: Thomas Garnier <thgarnie@google.com> I will send a new version of this PATCH soon. The test bot found places where virtual addresses were computed before PAGE_OFFSET was set. I will investigate that. > --- > Based on next-20160805 > --- > arch/x86/kernel/setup.c | 4 ++-- > arch/x86/mm/kaslr.c | 2 +- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c > index bcabb88..8dda0ce 100644 > --- a/arch/x86/kernel/setup.c > +++ b/arch/x86/kernel/setup.c > @@ -936,8 +936,6 @@ void __init setup_arch(char **cmdline_p) > > x86_init.oem.arch_setup(); > > - kernel_randomize_memory(); > - > iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1; > setup_memory_map(); > parse_setup_data(); > @@ -1071,6 +1069,8 @@ void __init setup_arch(char **cmdline_p) > high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1; > #endif > > + kernel_randomize_memory(); > + > /* > * Find and reserve possible boot-time SMP configuration: > */ > diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c > index 26dccd6..ec8654f 100644 > --- a/arch/x86/mm/kaslr.c > +++ b/arch/x86/mm/kaslr.c > @@ -97,7 +97,7 @@ void __init kernel_randomize_memory(void) > * add padding if needed (especially for memory hotplug support). > */ > BUG_ON(kaslr_regions[0].base != &page_offset_base); > - memory_tb = ((max_pfn << PAGE_SHIFT) >> TB_SHIFT) + > + memory_tb = DIV_ROUND_UP(max_pfn << PAGE_SHIFT, 1UL << TB_SHIFT) + > CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING; > > /* Adapt phyiscal memory region size based on available memory */ > -- > 2.8.0.rc3.226.g39d4020 >
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web